bili_fix_player

修复B站播放器,黑科技,列表页、搜索页弹窗,破乐视限制,提供高清、低清晰源下载,弹幕下载

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

  1. // ==UserScript==
  2. // @name bili_fix_player
  3. // @namespace bili
  4. // @description 修复B站播放器,黑科技,列表页、搜索页弹窗,破乐视限制,提供高清、低清晰源下载,弹幕下载
  5. // @include /^.*\.bilibili\.(tv|com|cn)\/(video\/|search)?.*$/
  6. // @include /^.*bilibili\.kankanews\.com\/(video\/|search)?.*$/
  7. // @version 3.6
  8. // @grant GM_xmlhttpRequest
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @grant GM_addStyle
  12. // @author 绯色
  13. // ==/UserScript==
  14. /**
  15. 出现无法播放情况先关闭自动修复
  16. 2014-06-30按照田生大神建议,增加与其脚本匹配id,在弹窗标题增加打开播放页面的按钮,补充,发现BUG,在弹窗播放时,点击B站FLASH播放器后,若直接点击关闭弹窗,会造成鼠标滚轮无效的问题,这BUG作者暂时无修复方法
  17. 并且使用了田生大神分支里面的弹窗播放器支持网页全屏功能,感谢
  18. 2014-06-21修复搜索页面因为作者正则匹配错误(B站把域名换成com但在a标签还是tv域名,坑爹)的问题
  19. 2014-06-18修复B站更换域名的BUG,在田生大神的建议下,将所有api域名换成com,弹窗播放器增加收藏按钮
  20. 2014-06-08修复小部分bug(样式冲突、弹窗冲突)
  21. 2014-06-03增强弹窗播放器,[拖动窗口标题可移动播放器,拖动右下角可改变播放器大小,设置后自动保存宽高和位置]
  22. 2014-05-25感谢吧友lzgptdgj提供BUG,在小型播放器下,屏蔽规则会无效的问题,已经修复
  23. 2014-05-14增加首页弹窗播放,基本实现全站可弹窗(首页新番专题列表除外等)
  24. 2014-05-13增加搜索页面的弹窗播放,并且支持多P和显示当前P,增加模糊画质下载按钮
  25. 2014-05-11还是基佬要求,增加弹窗播放器分P效果,增加弹幕下载功能,在吧友大神田生的建议下,正则表达式加强匹配
  26. 2014-05-10收益于自己的B站追番计划(http://v.myacg.ga或者http://weiyun.jd-app.com),代码逻辑重构(不再区分视频源再解析视频),并重写UI
  27. 2014-05-10受诸多基佬要求,增加除首页外其他分类页面的弹窗播放(初衷是为了弹窗乐视源)
  28. 2014-03-28增加下载视频按钮
  29. 2014-01-23替换优酷、爱奇艺、搜狐为B站播放器
  30. 2013-12-14修复B站播放器无法在火狐魔镜弹窗播放
  31. ------------以下信息提供给开发者-----------
  32. //https://static-s.bilibili.tv/play.swf---新版播放器
  33. //http://static.hdslb.com/play.swf---旧版播放器
  34. //https://static-s.bilibili.tv/play_old.swf---考古级别播放器
  35. //使用https连接的播放器可以获得屏蔽列表
  36. -------------------------------------------
  37. */
  38. (function() {
  39. //初始化 init
  40. if (GM_getValue('auto') == undefined) GM_setValue('auto', 1);
  41. if (GM_getValue('player_size') == undefined) GM_setValue('player_size', 1);
  42. //初始化播放器宽高
  43. if (GM_getValue('player_width') == undefined) GM_setValue('player_width', 950);
  44. if (GM_getValue('player_height') == undefined) GM_setValue('player_height', 482);
  45. //初始化播放器外框位置
  46. //if (GM_getValue('div_top') == undefined) GM_setValue('div_top', 100);//设置垂直位置的时候,如果是长页而且是浮动播放器时候记录位置,会导致播放器不知所踪
  47. if (GM_getValue('div_left') == undefined) GM_setValue('div_left', 100);
  48. //初始化jquery支持
  49. var $ = unsafeWindow.$;
  50. /**
  51. -------------------------------用户界面GUI View-------------------------------------
  52. */
  53. //函数,插入可视化操作视图
  54.  
  55. function insert_html(type) {
  56. var auto = GM_getValue('auto') ? '已打开' : '已关闭';
  57. var player_size = GM_getValue('player_size') ? '大型' : '小型';
  58. var div = '<a style="color:red" id="bili-fix-player-installed">脚本(`・ω・´)</a>\
  59. <ul class="i_num" id="bili_fix_script">\
  60. <li><a class="font">遇到播放错误请关闭自动修复后刷新页面</a><a target="_blank" href="http://bilili.ml/361.html">BUG反馈</a></li>\
  61. <li><a>本页视频源:<b style="color:#F489AD">' + type + '</b></a></li>\
  62. <li><a class="font">高清视频下载HD(右键复制以下视频分段下载链接,然后在新标签粘贴打开即可不被403)</a><div class="m_num" id="av_source">\
  63. </div></li>\
  64. <li><a class="font" target="_blank" id="aid_down_av">模糊画质视频下载(单文件)</a></li>\
  65. <li><a id="down_cid_xml" target="_blank">弹幕下载</a></li>\
  66. <li><a>自动修复(修改后请刷新页面):<a id="bili_fix" class="bfpbtn">' + auto + '</a></a></li>\
  67. <li><a class="font">播放器大小(小型在火狐弹窗无BUG):<a id="player_size" class="bfpbtn">' + player_size + '</a></a></li>\
  68. <li><a id="bili_set_status">就绪中→_→</a></li>\
  69. </ul>\
  70. <span class="addnew_5">+10086</span>';
  71. $('div.num:nth-child(4) > ul:nth-child(1) > li:nth-child(1)').html(div);
  72. //监听修复按钮
  73. var bfpbtn = document.querySelector("#bili_fix");
  74. bfpbtn.addEventListener("click", set_auto, false);
  75. //监听播放器大小按钮
  76. var bfpbtn = document.querySelector("#player_size");
  77. bfpbtn.addEventListener("click", set_player, false);
  78. }
  79.  
  80. //函数,插入下载按钮
  81.  
  82. function insert_download_button(url, count) {
  83. $('#av_source').append('<a href="' + url + '" target="blank">分段【' + count + '】</a>');
  84. }
  85.  
  86. //设置参数
  87. //修复按钮事件
  88.  
  89. function set_auto() {
  90. GM_getValue('auto') ? GM_setValue('auto', 0) : GM_setValue('auto', 1);
  91. var s = GM_getValue('auto') ? '已打开' : '已关闭';
  92. document.getElementById('bili_fix').innerHTML = s;
  93. $("#bili_fix").toggleClass("active");
  94. $('#bili_set_status').html('<a class="bfpbtn notice font">已更改,刷新生效_(:3」∠)_</a>');
  95. }
  96. //播放器大小按钮事件
  97.  
  98. function set_player() {
  99. GM_getValue('player_size') ? GM_setValue('player_size', 0) : GM_setValue('player_size', 1);
  100. var s = GM_getValue('player_size') ? '大型' : '小型';
  101. document.getElementById('player_size').innerHTML = s;
  102. $("#player_size").toggleClass("active");
  103. $('#bili_set_status').html('<a class="bfpbtn active font">已更改,刷新生效_(:3」∠)_</a>');
  104. }
  105. /**
  106. -------------------------------函数 Model-------------------------------------
  107. */
  108. //函数,替换播放器
  109.  
  110. function Replace_player(aid, cid) {
  111. if (GM_getValue('auto') == '1') {
  112. if (GM_getValue('player_size') == '1') {
  113. document.getElementById('bofqi').innerHTML = '<iframe class="player" src="https://secure.bilibili.com/secure,cid=' + cid + '&amp;aid=' + aid + '" scrolling="no" border="0" framespacing="0" onload="window.securePlayerFrameLoaded=true" frameborder="no" height="482" width="950"></iframe> ';
  114. } else {
  115. document.getElementById('bofqi').outerHTML = '<embed id="bofqi_embed" class="player" allowfullscreeninteractive="true" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" allowscriptaccess="always" rel="noreferrer" flashvars="cid=' + cid + '&amp;aid=' + aid + '" src="https://static-s.bilibili.com/play.swf" type="application/x-shockwave-flash" allowfullscreen="true" quality="high" wmode="window" height="482" width="950">';
  116. }
  117. }
  118. }
  119. //api获取cid
  120.  
  121. function api_get_cid(aid, page) {
  122. var url = 'http://api.bilibili.com/view?type=json&appkey=0a99fa1d87fdd38c&batch=1&id=' + aid;
  123. GM_xmlhttpRequest({
  124. method: 'GET',
  125. url: url,
  126. synchronous: false,
  127. onload: function(responseDetails) {
  128. if (responseDetails.status == 200) {
  129. var Content = eval('(' + responseDetails.responseText + ')');
  130. var list = Content.list;
  131. var p = page - 1;
  132. if (list != undefined) {
  133. var lp = (list[p] == undefined) ? list[0] : list[p]; //针对某些aid只有一个cid但是有分P的情况
  134. //console.log(lp);
  135. var cid = lp.cid;
  136. var type = lp.type;
  137. insert_html(type); //UI
  138. var cid_xml_url = 'http://comment.bilibili.com/' + cid + '.xml';
  139. $('#down_cid_xml').attr('href', cid_xml_url); //弹幕下载
  140. Replace_player(aid, cid); //替换播放器
  141. cid_get_videodown_hd(cid); //获取高清下载链接
  142. aid_down_av(aid, page); //av画质下载(单文件)
  143. } else {
  144. window_player_init(); //执行弹窗函数
  145. }
  146. }
  147. }
  148. });
  149. }
  150.  
  151. //弹框播放器支持页面全屏 来自田生
  152. function fix_player_fullwin() {
  153. unsafeWindow.player_fullwin = function(is_full) {
  154. $('#window-player').css({
  155. 'position': is_full ? 'fixed' : 'static'
  156. });
  157. $('.z, .header, .z_top, .footer').css({
  158. 'display': is_full ? 'none' : 'block'
  159. });
  160. }
  161. };
  162. //在新番页面,通过弹窗,获取aid,cid然后进行播放
  163. function aid_build_player(aid) {
  164. var url = 'http://api.bilibili.com/view?type=json&appkey=0a99fa1d87fdd38c&batch=1&id=' + aid;
  165. GM_xmlhttpRequest({
  166. method: 'GET',
  167. url: url,
  168. synchronous: false,
  169. onload: function(responseDetails) {
  170. if (responseDetails.status == 200) {
  171. var Content = eval('(' + responseDetails.responseText + ')');
  172. var list = Content.list;
  173. //默认播放第一个分P-------------------
  174. var p = 0;
  175. var lp = (list[p] == undefined) ? list[0] : list[p];
  176. //console.log(lp);
  177. var cid = lp.cid;
  178. $('#player_content').html(window_player(aid, cid));
  179. //分P列表和播放器------------------------------
  180. for (var i in list) {
  181. //console.log(list[i]);
  182. var cid = list[i].cid;
  183. var p = parseInt(i) + 1;
  184. $('#window_play_list').append('<li class="single_play_list" data-field="aid=' + aid + '&cid=' + cid + '"><a href="javascript:void(0);" style="color:#00A6D8;" >' + p + 'P</a></li>');
  185. }
  186. if (!unsafeWindow.player_fullwin) setTimeout(fix_player_fullwin, 0);
  187. //弹窗的分P播放
  188. $('.single_play_list').click(
  189. function() {
  190. $('#window_play_info').html('正在播放第<span style="color:#F0CF1D">' + $(this).find('a').html() + '</span>');
  191. var info = $(this).attr('data-field');
  192. var pattern = /aid=(\d+)&cid=(\d+)/ig;
  193. var val = pattern.exec(info);
  194. var aid = val === null ? '' : val[1];
  195. var cid = val === null ? '' : val[2];
  196. // console.log(aid,cid);
  197. setTimeout(function() {
  198. $('#player_content').html(window_player(aid, cid));
  199. });
  200. });
  201. }
  202. }
  203. });
  204. }
  205. //弹窗播放器
  206.  
  207. function window_player(aid, cid) {
  208. var width = GM_getValue('player_width');
  209. var height = GM_getValue('player_height');
  210. return '<embed id="window-player" class="player" allowfullscreeninteractive="true" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" allowscriptaccess="always" rel="noreferrer" flashvars="cid=' + cid + '&amp;aid=' + aid + '" src="https://static-s.bilibili.com/play.swf" type="application/x-shockwave-flash" allowfullscreen="true" quality="high" wmode="window" height="' + height + '" width="' + width + '">';
  211. }
  212. //cid获取高清视频链接
  213.  
  214. function cid_get_videodown_hd(cid) {
  215. var url = 'http://interface.bilibili.com/playurl?appkey=0a99fa1d87fdd38c&platform=android&quality=2&cid=' + cid;
  216. GM_xmlhttpRequest({
  217. method: 'GET',
  218. url: url,
  219. synchronous: false,
  220. onload: function(responseDetails) {
  221. if (responseDetails.status == 200) {
  222. var pattern = /<\/(?:(?:chunk)?size|length)>[\s\n]*?<url><\!\[CDATA\[(.*?)\]\]><\/url>/ig;
  223. var c = 1;
  224. while (content = pattern.exec(responseDetails.responseText)) {
  225. var url = content ? (content[1]) : 'http://interface.bilibili.cn/playurl?appkey=0a99fa1d87fdd38c&platform=android&quality=2&cid=' + cid;
  226. insert_download_button(url, c);
  227. c++;
  228. }
  229. }
  230. }
  231. });
  232. }
  233. //低画质视频下载(单文件)
  234.  
  235. function aid_down_av(aid, page) {
  236. var url = 'http://www.bilibili.com/m/html5?aid=' + aid + '&page=' + page;
  237. GM_xmlhttpRequest({
  238. method: 'GET',
  239. url: url,
  240. synchronous: false,
  241. onload: function(responseDetails) {
  242. if (responseDetails.status == 200) {
  243. var Content = eval('(' + responseDetails.responseText + ')');
  244. var downlink = Content.src;
  245. $('#aid_down_av').attr('href', downlink);
  246. }
  247. }
  248. });
  249. }
  250.  
  251. /**
  252. -------------------------------控制 Control-------------------------------------
  253. */
  254.  
  255. function window_player_init() {
  256. //弹窗------------------------------
  257. //新番列表弹窗UI
  258. $('.vd_list .title').each(
  259. function() {
  260. var href = $(this).attr('href');
  261. var pattern = /\/video\/av(\d+)\//ig;
  262. var content = pattern.exec(href);
  263. var aid = content ? (content[1]) : '';
  264. $(this).prepend('<a class="single_player" href="javascript:void(0);" style="color:red;" data-field="' + aid + '">弹▶</a>');
  265. });
  266. //搜索列表弹窗UI
  267. $('.result li .r a').each(
  268. function() {
  269. var href = $(this).attr('href');
  270. var pattern = /\/video\/av(\d+)\//ig;
  271. var content = pattern.exec(href);
  272. var aid = content ? (content[1]) : '';
  273. if (aid != '') {
  274. $(this).find('.t').prepend('<a class="single_player" href="javascript:void(0);" style="color:red;" data-field="' + aid + '">弹▶</a>');
  275. }
  276. });
  277. //带缩略图弹窗UI、和侧栏新投稿弹窗UI、首页的推荐栏弹窗、侧栏列表弹窗UI
  278. $('.video li a,.z-r.new li a,#suggest li a,.rlist li a').each(
  279. function() {
  280. var href = $(this).attr('href');
  281. var pattern = /\/video\/av(\d+)\//ig;
  282. var content = pattern.exec(href);
  283. var aid = content ? (content[1]) : '';
  284. $(this).find('.t').prepend('<a class="single_player" href="javascript:void(0);" style="color:red;" data-field="' + aid + '">弹▶</a>');
  285. });
  286. //弹窗默认的第一P,建立弹窗播放器并建立分P列表===click事件应该在each事件之后执行
  287. $('.single_player').click(
  288. function() {
  289. //$('.dialogcontainter').remove();//防止同时播放两个视频
  290. $('#player-list').remove(); //移除播放列表
  291. var a = '<p id="window_play_title">脚本(`・ω・´)正在加载中</p><div id="player_content">脚本(`・ω・´)播放器正在努力加载中....</div>';
  292. var list_html = '<div id="player-list"><div class="sort"><i>分P列表</i></div><ul id="window_play_list"></ul></div>';
  293.  
  294. var title = $(this).parent('.t').html() === null ? $(this).parent('.title').html() : $(this).parent('.t').html();
  295. var aid = $(this).attr('data-field');
  296. var title_html = '<a class="mark_my_video" href="javascript:void(0);" style="color:#006766;" data-field="' + aid + '">收藏★</a>&nbsp;&nbsp;&nbsp;<a href="http://www.bilibili.com/video/av' + aid + '/" style="color:#D54851" target="_blank">打开播放页</a>&nbsp;&nbsp;&nbsp;<span style="color:#8C8983">' + title.replace('弹▶', '') + '</span>&nbsp;&nbsp;&nbsp;▶<span id="window_play_info"></span>';
  297. setTimeout(function() {
  298. creat(title_html, a); //创建可视化窗口
  299. $('.dialogcontainter').after(list_html);
  300. $('#window_play_info').html('正在播放第<span style="color:#F0CF1D">1P</span>');
  301. $('#window_play_title').html('<p><a id="div_positon_button" class="button-small button-flat-action" style="background: none repeat scroll 0% 0% #E54C7E;">固定播放器</a><a id="list_control_button" class="button-small button-flat-action" style="background: none repeat scroll 0% 0% #0CB3EE;">收缩分P列表[在左边]</a>[拖动标题可移动播放器,拖动右下角可改变播放器大小,设置后自动保存宽高和位置]</p>');
  302. //切换分P按钮
  303. $('#list_control_button').click(function() {
  304. var flag = $("#player-list").css("display");
  305. if (flag == "none") {
  306. $("#player-list").show();
  307. $('#list_control_button').html('收缩分P列表');
  308. $('#list_control_button').css('background', 'none repeat scroll 0% 0% #0CB3EE');
  309. } else {
  310. $("#player-list").hide();
  311. $('#list_control_button').html('显示分P列表');
  312. $('#list_control_button').css('background', 'none repeat scroll 0% 0% #FF2C14');
  313. }
  314. });
  315. //固定播放器按钮
  316. $('#div_positon_button').click(function() {
  317. var p = $('.dialogcontainter').css('position');
  318. if (p == "fixed") {
  319. $('.dialogcontainter').css('position', 'absolute');
  320. $('#player-list').css('position', 'absolute');
  321. $('#div_positon_button').html('浮动播放器');
  322. $('#div_positon_button').css('background', 'none repeat scroll 0% 0% #FECD3E');
  323. } else {
  324. $('.dialogcontainter').css('position', 'fixed');
  325. $('#player-list').css('position', 'fixed');
  326. $('#div_positon_button').html('固定播放器');
  327. $('#div_positon_button').css('background', 'none repeat scroll 0% 0% #E54C7E');
  328. }
  329. });
  330. //弹窗播放器收藏功能
  331. $('.mark_my_video').click(function() {
  332. var aid = $(this).attr('data-field');
  333. $.ajax({
  334. type: 'POST',
  335. url: 'http://www.bilibili.com/m/stow',
  336. data: 'dopost=save&aid=' + aid + '&stow_target=stow&ajax=1',
  337. success: function(r) {
  338. //$('#edit_status_bar').html(r);
  339. alert('收藏成功');
  340. },
  341. error: function(r) {
  342. alert('出错,请重试!');
  343. },
  344. dataType: 'text'
  345. });
  346. });
  347. }, 0);
  348. setTimeout(function() {
  349. aid_build_player(aid);
  350. }, 0);
  351. });
  352. }
  353. //END弹窗------------------------------
  354.  
  355.  
  356.  
  357. //替换播放器----------------------------
  358. //取出aid和分P
  359. var url = document.location.href;
  360. var aid_reg = /\/av(\d+)\/(?:index_(\d+)\.html)?/ig;
  361. var aid_array = aid_reg.exec(url);
  362.  
  363. var aid = aid_array === null ? '' : aid_array[1]; //aid
  364. var page = aid_array === null ? '1' : typeof(aid_array[2]) == 'undefined' ? '1' : aid_array[2]; //分p
  365.  
  366. //播放器的html
  367. var content; //本脚本使用了很多content变量,其中cid_get_videodown函数的while循环content变量全局,如果此处未定义content,火狐会报权限问题
  368. api_get_cid(aid, page); //按照aid和分p获取cid并且替换播放器
  369.  
  370. //css插入
  371. var css = '.bfpbtn{font-size: 12px;height: 25.6px;line-height: 25.6px;padding: 0px 2px;transition-property: #000, color;\
  372. transition-duration: 0.3s;\
  373. box-shadow: none;\
  374. color: #FFF;\
  375. text-shadow: none;\
  376. border: medium none;\
  377. background: none repeat scroll 0% 0% #00A1CB!important;}\
  378. .bfpbtn.active{\
  379. background: none repeat scroll 0% 0% #F489AD!important;}\
  380. .bfpbtn.notice{\
  381. background-color:#A300C0!important;}\
  382. .font{\
  383. font-size:11px!important;}\
  384. #window_play_list li{\
  385. float: left;\
  386. position: relative;\
  387. width: 5em;\
  388. border: 1px solid #B0C4DE;\
  389. font: 80% Verdana, Geneva, Arial, Helvetica, sans-serif;\
  390. }\
  391. .ui.corner.label {\
  392. height: 0px;\
  393. border-width: 0px 3em 3em 0px;\
  394. border-style: solid;\
  395. border-top: 0px solid transparent;\
  396. border-bottom: 3em solid transparent;\
  397. border-left: 0px solid transparent;\
  398. border-right-color: rgb(217, 92, 92)!important;;\
  399. transition: border-color 0.2s ease 0s;\
  400. position: absolute;\
  401. content: "";\
  402. right: 0px;\
  403. top: 0px;\
  404. z-index: -1;\
  405. width: 0px;\
  406. }\
  407. .ui.corner.label i{\
  408. display: inline-block;\
  409. margin:3px 0.25em 0px 17px;\
  410. width: 1.23em;\
  411. height: 1em;\
  412. font-weight: 800!important;\
  413. }\
  414. .dialogcontainter{height:400px; width:400px; border:1px solid #14495f; position:fixed; font-size:13px;} \
  415. .dialogtitle{height:26px; width:auto; background-color:#C6C6C6;} \
  416. .dialogtitleinfo{float:left;height:20px; margin-top:2px; margin-left:10px;line-height:20px; vertical-align:middle; color:#FFFFFF; font-weight:bold; } \
  417. .dialogtitleico{float:right; height:20px; width:21px; margin-top:2px; margin-right:5px;text-align:center; line-height:20px; vertical-align:middle; background-image:url("http://nightlyfantasy.github.io/Bili_Fix_Player/bg.gif");background-position:-21px 0px} \
  418. .dialogbody{ padding:10px; width:auto; background-color: #FFFFFF;\
  419. background-image:url("http://nightlyfantasy.github.io/Bili_Fix_Player/bg.png");} \
  420. .dialogbottom{ \
  421. bottom:1px; right:1px;cursor:nw-resize; \
  422. position:absolute; \
  423. background-image:url("http://nightlyfantasy.github.io/Bili_Fix_Player/bg.gif"); \
  424. background-position:-42px -10px; \
  425. width:10px; \
  426. height:10px; \
  427. font-size:0;}\
  428. .button-small {\
  429. font-size: 12px;\
  430. height: 25.6px;\
  431. line-height: 25.6px;\
  432. padding: 0px 5px;\
  433. }\
  434. .button-flat-action {\
  435. transition-duration: 0.3s;\
  436. box-shadow: none;\
  437. background: none repeat scroll 0% 0% #7DB500;\
  438. color: #FFF!important;\
  439. text-shadow: none;\
  440. border: medium none;\
  441. border-radius: 3px;\
  442. }\
  443. #player-list{\
  444. position:fixed;\
  445. z-index:1000;\
  446. left:10px;\
  447. top:50px;\
  448. width:400px!important;\
  449. background-image:url("http://nightlyfantasy.github.io/Bili_Fix_Player/bg.png");\
  450. min-height:200px!Important;\
  451. }\
  452. #player_content {\
  453. position:absolute;\
  454. top:60px;\
  455. left:10px;\
  456. right:10px;\
  457. bottom:10px;\
  458. }\
  459. #window-player {\
  460. bottom: 0;\
  461. height: 100%;\
  462. left: 0;\
  463. right: 0;\
  464. top: 0;\
  465. width: 100%;}\
  466. a.single_player{\
  467. display:none;\
  468. }\
  469. a:hover .single_player{\
  470. display:inline;\
  471. }';
  472. GM_addStyle(css);
  473.  
  474.  
  475. //高大上的拖动DIV和改变DIV大小功能,来自互联网脚本之家www.jb51.net
  476. var z = 1,
  477. i = 1,
  478. left = 10;
  479. var isIE = (document.all) ? true : false;
  480. var Extend = function(destination, source) {
  481. for (var property in source) {
  482. destination[property] = source[property];
  483. }
  484. }
  485.  
  486. var Bind = function(object, fun, args) {
  487. return function() {
  488. return fun.apply(object, args || []);
  489. }
  490. }
  491.  
  492. var BindAsEventListener = function(object, fun) {
  493. var args = Array.prototype.slice.call(arguments).slice(2);
  494. return function(event) {
  495. return fun.apply(object, [event || window.event].concat(args));
  496. }
  497. }
  498.  
  499. var CurrentStyle = function(element) {
  500. return element.currentStyle || document.defaultView.getComputedStyle(element, null);
  501. }
  502.  
  503. function create(elm, parent, fn) {
  504. var element = document.createElement(elm);
  505. fn && fn(element);
  506. parent && parent.appendChild(element);
  507. return element
  508. };
  509.  
  510. function addListener(element, e, fn) {
  511. element.addEventListener ? element.addEventListener(e, fn, false) : element.attachEvent("on" + e, fn)
  512. };
  513.  
  514. function removeListener(element, e, fn) {
  515. element.removeEventListener ? element.removeEventListener(e, fn, false) : element.detachEvent("on" + e, fn)
  516. };
  517.  
  518. var Class = function(properties) {
  519. var _class = function() {
  520. return (arguments[0] !== null && this.initialize && typeof(this.initialize) == 'function') ? this.initialize.apply(this, arguments) : this;
  521. };
  522. _class.prototype = properties;
  523. return _class;
  524. };
  525.  
  526. var Dialog = new Class({
  527. options: {
  528. Width: 400,
  529. Height: 400,
  530. Left: 100,
  531. Top: 10,
  532. Titleheight: 26,
  533. Minwidth: 200,
  534. Minheight: 200,
  535. CancelIco: true,
  536. ResizeIco: true,
  537. Info: "标题",
  538. Content: "无内容",
  539. Zindex: 2
  540. },
  541. initialize: function(options) {
  542. this._dragobj = null;
  543. this._resize = null;
  544. this._cancel = null;
  545. this._body = null;
  546. this._x = 0;
  547. this._y = 0;
  548. this._fM = BindAsEventListener(this, this.Move);
  549. this._fS = Bind(this, this.Stop);
  550. this._isdrag = null;
  551. this._Css = null;
  552. ////////////////////////////////////////////////////////////////////////////////
  553. this.Width = this.options.Width;
  554. this.Height = this.options.Height;
  555. this.Left = this.options.Left;
  556. this.Top = this.options.Top;
  557. this.CancelIco = this.options.CancelIco;
  558. this.Info = this.options.Info;
  559. this.Content = this.options.Content;
  560. this.Minwidth = this.options.Minwidth;
  561. this.Minheight = this.options.Minheight;
  562. this.Titleheight = this.options.Titleheight;
  563. this.Zindex = this.options.Zindex;
  564. Extend(this, options);
  565. Dialog.Zindex = this.Zindex
  566. //////////////////////////////////////////////////////////////////////////////// 构造dialog
  567. var obj = ['dialogcontainter', 'dialogtitle', 'dialogtitleinfo', 'dialogtitleico', 'dialogbody', 'dialogbottom'];
  568. for (var i = 0; i < obj.length; i++) {
  569. obj[i] = create('div', null, function(elm) {
  570. elm.className = obj[i];
  571. });
  572. }
  573. obj[2].innerHTML = this.Info;
  574. obj[4].innerHTML = this.Content;
  575. obj[1].appendChild(obj[2]);
  576. obj[1].appendChild(obj[3]);
  577. obj[0].appendChild(obj[1]);
  578. obj[0].appendChild(obj[4]);
  579. obj[0].appendChild(obj[5]);
  580. document.body.appendChild(obj[0]);
  581. this._dragobj = obj[0];
  582. this._resize = obj[5];
  583. this._cancel = obj[3];
  584. this._body = obj[4];
  585. ////////////////////////////////////////////////////////////////////////////////o,x1,x2
  586. ////设置Dialog的长 宽 ,left ,top
  587. with(this._dragobj.style) {
  588. height = this.Height + "px";
  589. top = this.Top + "px";
  590. width = this.Width + "px";
  591. left = this.Left + "px";
  592. zIndex = this.Zindex;
  593. }
  594. this._body.style.height = this.Height - this.Titleheight - parseInt(CurrentStyle(this._body).paddingLeft) * 2 + 'px';
  595. /////////////////////////////////////////////////////////////////////////////// 添加事件
  596. addListener(this._dragobj, 'mousedown', BindAsEventListener(this, this.Start, true));
  597. addListener(this._cancel, 'mouseover', Bind(this, this.Changebg, [this._cancel, '0px 0px', '-21px 0px']));
  598. addListener(this._cancel, 'mouseout', Bind(this, this.Changebg, [this._cancel, '0px 0px', '-21px 0px']));
  599. addListener(this._cancel, 'mousedown', BindAsEventListener(this, this.Disappear));
  600. addListener(this._body, 'mousedown', BindAsEventListener(this, this.Cancelbubble));
  601. addListener(this._resize, 'mousedown', BindAsEventListener(this, this.Start, false));
  602. },
  603. Disappear: function(e) {
  604. this.Cancelbubble(e);
  605. document.body.removeChild(this._dragobj);
  606. $('#player-list').remove();
  607. },
  608. Cancelbubble: function(e) {
  609. this._dragobj.style.zIndex = ++Dialog.Zindex;
  610. document.all ? (e.cancelBubble = true) : (e.stopPropagation())
  611. },
  612. Changebg: function(o, x1, x2) {
  613. o.style.backgroundPosition = (o.style.backgroundPosition == x1) ? x2 : x1;
  614. },
  615. Start: function(e, isdrag) {
  616. if (!isdrag) {
  617. this.Cancelbubble(e);
  618. }
  619. this._Css = isdrag ? {
  620. x: "left",
  621. y: "top"
  622. } : {
  623. x: "width",
  624. y: "height"
  625. }
  626. this._dragobj.style.zIndex = ++Dialog.Zindex;
  627. this._isdrag = isdrag;
  628. this._x = isdrag ? (e.clientX - this._dragobj.offsetLeft || 0) : (this._dragobj.offsetLeft || 0);
  629. this._y = isdrag ? (e.clientY - this._dragobj.offsetTop || 0) : (this._dragobj.offsetTop || 0);
  630. if (isIE) {
  631. addListener(this._dragobj, "losecapture", this._fS);
  632. this._dragobj.setCapture();
  633. } else {
  634. e.preventDefault();
  635. addListener(window, "blur", this._fS);
  636. }
  637. addListener(document, 'mousemove', this._fM)
  638. addListener(document, 'mouseup', this._fS)
  639. },
  640. Move: function(e) {
  641. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  642. var i_x = e.clientX - this._x,
  643. i_y = e.clientY - this._y;
  644. this._dragobj.style[this._Css.x] = (this._isdrag ? Math.max(i_x, 0) : Math.max(i_x, this.Minwidth)) + 'px';
  645. this._dragobj.style[this._Css.y] = (this._isdrag ? Math.max(i_y, 0) : Math.max(i_y, this.Minheight)) + 'px'
  646. if (!this._isdrag)
  647. this._body.style.height = Math.max(i_y - this.Titleheight, this.Minheight - this.Titleheight) - 2 * parseInt(CurrentStyle(this._body).paddingLeft) + 'px';
  648. },
  649. Stop: function() {
  650. removeListener(document, 'mousemove', this._fM);
  651. removeListener(document, 'mouseup', this._fS);
  652. //console.log($('.dialogcontainter').width(), $('.dialogcontainter').height());
  653. //实时改变播放器大小,保存播放器大小
  654. $('#window-player').width($('.dialogcontainter').width() - 20);
  655. GM_setValue('player_width', ($('.dialogcontainter').width() - 20));
  656. $('#window-player').height($('.dialogcontainter').height() - 70);
  657. GM_setValue('player_height', ($('.dialogcontainter').height() - 70));
  658. //保存位置
  659. //GM_setValue('div_top', ($('.dialogcontainter').offset().top));//设置垂直位置的时候,如果是长页而且是浮动播放器时候记录位置,会导致播放器不知所踪
  660. GM_setValue('div_left', ($('.dialogcontainter').offset().left));
  661. if (isIE) {
  662. removeListener(this._dragobj, "losecapture", this._fS);
  663. this._dragobj.releaseCapture();
  664. } else {
  665. removeListener(window, "blur", this._fS);
  666. };
  667. }
  668. })
  669.  
  670. function creat(title, content) {
  671. $('.dialogcontainter').remove();
  672. new Dialog({
  673. Info: title = title,
  674. Left: GM_getValue('div_left'),
  675. Top: 50,
  676. Width: (GM_getValue('player_width') + 20),
  677. Height: (GM_getValue('player_height') + 70),
  678. Content: content,
  679. Zindex: (2000)
  680. });
  681. i++;
  682. left += 10;
  683. }
  684. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址