115 Online Player

Play videos from 115 online

目前为 2014-09-07 提交的版本。查看 最新版本

// ==UserScript==
// @name        115 Online Player
// @version     1.0.1
// @description Play videos from 115 online
// @match       http://*.115.com/*
// @match       http://*.115.com/*
// @author      8qwe24657913 | 864907600cc
// @run-at      document-end
// @grant       none
// @namespace   http://ext.ccloli.com
// ==/UserScript==

// 播放的视频系未转码的原始视频,播放视频需浏览器支持该格式,当浏览器无法播放此视频时会弹出视频下载地址,您可以将地址贴入本地播放器来在线观看,或贴入下载地址下载播放

var requests = [],
	CloudVideo = window.CloudVideo = {
		showPanel: function (code, height) {
			var dialog_frame = $('<div class="dialog-frame" style="height:' + height + 'px;text-align:center;font-size:100px;">Loading......</div>');
			new Core.DialogBase({
				title: "视频播放",
				content: dialog_frame,
				width: 640
			}).Open();
			this.getFileUrl(code, function (url) {
				$('<video class="online-video-player" autoplay="autoplay" controls="controls" width="640" height="' + height + '"></video>').attr('src', url).appendTo(dialog_frame.html('')).on('error',function(){prompt('播放失败!可能是不支持的格式或下载断流!\n请尝试复制下载地址并调用本地播放器播放', this.src)});
			});
		},
		getFileUrl: function (pickcode, callback) {
			requests.push([pickcode, callback])
		}
	};
$('<iframe>').attr('src', 'http://web.api.115.com/bridge_2.0.html?namespace=CloudVideo&api=jQuery').css({
	width: 0,
	height: 0,
	border: 0,
	padding: 0,
	margin: 0,
	position: 'absolute',
	top: '-99999px'
}).one('load', function () {
	//delete window.CloudVideo;
	var urlCache = {};
	CloudVideo.getFileUrl = function (pickcode, callback) {
		if (urlCache[pickcode]) {
			setTimeout(callback, 0, urlCache[pickcode]);
		} else {
			this.jQuery.get('http://web.api.115.com/files/download?pickcode=' + pickcode, function (data) {
				callback(urlCache[pickcode] = data.file_url)
			}, 'json');
		}
	};
	requests.forEach(function (e) {
		CloudVideo.getFileUrl(e[0], e[1])
	});
	requests = null;
}).appendTo('body');
$('<style>').text('.show-video-button{font-size:14px;width:40px;height:24px;line-height:24px;text-align:center;background:rgba(255,255,255,0.75);top:20px;left:0px;right:0px;bottom:auto;margin:auto;position:absolute;z-index:999;display:none;border:1px #EEEEEE solid}li[rel="item"][file_type="1"][file_mode="9"]:hover .show-video-button{display:block}').appendTo($('iframe[rel="wangpan"]').contents().on('mouseenter', 'li[rel="item"][file_type="1"][file_mode="9"]:not([is_loaded_vbutton="1"])', function () {
	var par_element = $(this).attr('is_loaded_vbutton', '1'),
		pick_code = par_element.attr('pick_code'),
		video_height = function () {
			var image = par_element.find('.img-pos img');
			return 640 / image.width() * image.height() || 480;
		}();
	$('<div class="show-video-button">播放</div>').on('click', function () {
		CloudVideo.showPanel(pick_code, video_height);
	}).appendTo(par_element);
}).get(0).head);