[115.com] Local Player

Play Videos Via Local Player

当前为 2019-10-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name [115.com] Local Player
  3. // @version 2.0.0
  4. // @description Play Videos Via Local Player
  5. // @match https://115.com/*
  6. // @author sam
  7. // @run-at document-end
  8. // @grant none
  9. // @namespace 115.com
  10. // ==/UserScript==
  11. $(document).ready(function(){
  12.  
  13. //去除无用侧边栏
  14. if(window.location.href === "https://115.com/home/userhome")
  15. window.location = "https://115.com/?mode=wangpan";
  16. else
  17. {
  18. var item_list,item_obj,item_name;
  19. var ifr = $("iframe[style='position: absolute; top: 0px;']");
  20. $("div#js-main_mode").css("display","none");
  21. $("div.main-core").css("left","0");
  22. ifr.load(
  23. function(){
  24. setCss();
  25. addMarkButton();
  26. item_list = ifr.contents().find("body").find("div#js_data_list");
  27. item_list.mouseenter(
  28. function(){
  29. if($("div.exph-loader").css("display") === "none" && !(item_list.find("div#isload").length)){
  30. item_list.append("<div id='isload'></div>");
  31. itemEvent();
  32. }
  33. }
  34. );
  35. }
  36. );
  37. }
  38.  
  39. //仅在wangpan框架内执行
  40. var page_url = window.location.href.substr(0,25);
  41. if (page_url =='https://115.com/?ct=file&'){
  42. console.log('onload')
  43. //1.本地播放器打开
  44. var requests = [],
  45. CloudVideo = window.CloudVideo = {
  46. showPanel: function (code) {
  47. this.getFileUrl(code, function (url) {
  48. //var xurl = 'ygl://' + encodeURIComponent(url);
  49. var xurl = 'potplayer://' + url; //原生potplayer调用
  50. console.log(xurl);
  51. window.location.href = xurl;
  52. });
  53. },
  54. getFileUrl: function (pickcode, callback) {
  55. requests.push([pickcode, callback])
  56. }
  57. };
  58.  
  59. $('<iframe>').attr('src', 'https://webapi.115.com/bridge_2.0.html?namespace=CloudVideo&api=jQuery').attr("id", 'ciid').css({
  60. width: 0,
  61. height: 0,
  62. border: 0,
  63. padding: 0,
  64. margin: 0,
  65. position: 'absolute',
  66. top: '-99999px'
  67. }).one('load', function () {
  68. var urlCache = {};
  69. CloudVideo.getFileUrl = function (pickcode, callback) {
  70. if (urlCache[pickcode]) {
  71. setTimeout(callback, 0, urlCache[pickcode]);
  72. } else {
  73. /*
  74. window.frames["ciid"].contentWindow.jQuery.get('https://webapi.115.com/files/download?pickcode=' + pickcode, function (data) {
  75. callback(urlCache[pickcode] = data.file_url)
  76. }, 'json');
  77. */
  78. //请求m3u8,调用potplayer打开
  79. var xhr = new XMLHttpRequest();
  80. xhr.open("GET", 'https://115.com/api/video/m3u8/' + pickcode + '.m3u8', true); //未加时间戳
  81. xhr.onreadystatechange = function() {
  82. if (this.readyState == 4 && this.status == 200) {
  83. var text = this.responseText,
  84. text_array=text.split("\n");
  85. text_array.shift();
  86. text_array.pop();
  87. //console.log(text_array);
  88. var BANDWIDTH = [],FILE_URL = [];
  89. for(let index in text_array) {
  90. //console.log(index,text_array[index]);
  91. if(index%2 == 0){
  92. var patt = /BANDWIDTH=(\d*)?/;
  93. var bw = text_array[index].match(patt)[1];
  94. BANDWIDTH.push(Number(bw));
  95. } else{
  96. FILE_URL.push(text_array[index]);
  97. };
  98. };
  99. var bw_max_index = BANDWIDTH.indexOf(Math.max(...BANDWIDTH));
  100. console.log(FILE_URL);
  101. callback(urlCache[pickcode] = FILE_URL[bw_max_index]);
  102. }
  103. };
  104. xhr.send();
  105. };
  106. };
  107. requests.forEach(function (e) {
  108. CloudVideo.getFileUrl(e[0], e[1])
  109. });
  110. requests = null;
  111. }).appendTo('html');
  112.  
  113. //添加播放按钮
  114. $(document).on('mouseenter', 'li[rel="item"][file_type="1"][file_mode="9"]:not([is_loaded_vbutton="1"])', function () {
  115. var par_element = $(this).attr('is_loaded_vbutton', '1'),
  116. pick_code = par_element.attr('pick_code');
  117. var menu = par_element.find('[class="file-opr"]');
  118. $('<a href="javascript:;" menu_btn="more"><i class="icon ifo-share"></i><span>via.PotPlayer</a>').on('click', function () {
  119. CloudVideo.showPanel(pick_code);
  120. console.log(pick_code);
  121. }).appendTo(menu);
  122. });
  123.  
  124. //2.调整添加任务按钮
  125. document.querySelector("#js_top_panel_box > div:nth-child(5)").remove() //移除上传按钮
  126. document.querySelector("#js_top_panel_box > div.right-tvf > a:nth-child(1)").remove() //移除我的分享
  127. //添加链接任务
  128. $('<a href="javascript:;" class="button btn-linear-blue illt-offline" menu="offline_task" is_bind="1"><span>链接任务</span></a>').prependTo(document.querySelector("#js_top_panel_box > div.right-tvf"));
  129.  
  130. };
  131. });