[115.com] Local Player

Play Videos Via Local Player

目前为 2019-12-21 提交的版本。查看 最新版本

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