BilibiliToUWP

Open BilibiliUWP from Web

  1. // ==UserScript==
  2. // @namespace BlueFire
  3. // @version 1.06
  4. // @grant unsafeWindow
  5. // @include http://www.bilibili.com/video/*
  6. // @include http://www.bilibili.com/mobile/video/*
  7. // @include http://bangumi.bilibili.com/*
  8. // @include http://live.bilibili.com/*
  9. // @include http://music.163.com/*
  10. // @include http://*.ithome.com/*
  11. // @include http://*.lapin365.com/*
  12. // @run-at document-start
  13. // @name BilibiliToUWP
  14. // @name:zh-CN Bilibili调起UWP客户端
  15. // @description Open BilibiliUWP from Web
  16. // @description:zh-CN 从Bilibili网页调起UWP客户端
  17. // ==/UserScript==
  18.  
  19. unsafeWindow.Object.freeze = null;
  20. var IsOpenURIWhenPageLoadedEnable = false;
  21. document.addEventListener('DOMContentLoaded',OnPageLoaded , true);
  22. //document.onload = OnPageLoaded;
  23. function OnPageLoaded (event) {
  24. try {
  25. window.oneerror=function(){return true;};
  26. var url = window.location.href;
  27. var loc;
  28. var URI="";
  29. var element,element2,para,childpara,node;
  30. if(url.indexOf("bilibili.") != -1 && (url.indexOf("index") != -1 || url.indexOf("html") == -1))
  31. {
  32. if(url.indexOf("bangumi") != -1)
  33. {
  34. window.addEventListener('load',OnWindowLoaded,true);
  35. }
  36. else if(url.indexOf("video") != -1)
  37. {
  38. loc = url.match("av[0-9]*")[0].match("[0-9].*");
  39. URI = "bilibili://video/" + loc;
  40. element = document.getElementsByClassName("tminfo")[0];
  41. para = document.createElement("a");
  42. para.innerText = "用客户端打开";
  43. para.setAttribute("class","charge-appeal-init");
  44. para.href = URI;
  45. element.appendChild(para);
  46.  
  47. element2 = document.getElementsByClassName("qr-bottom")[0];
  48. element2.childNodes[1].removeAttribute("target");
  49. element2.childNodes[1].href=URI;
  50. }
  51. else if(url.indexOf("live") != -1)
  52. {
  53. loc = url.match("[0-9].*")[0];
  54. URI = "bilibili://live/" + loc;
  55. element = document.getElementsByClassName("room-title-row")[0];
  56. element2 = document.getElementsByClassName("report-link dp-none")[0];
  57. para = document.createElement("a");
  58. para.innerText = "用客户端打开";
  59. para.setAttribute("class","share-link");
  60. para.href=URI;
  61. try
  62. {
  63. element.appendChild(element2);
  64. element2.appendChild(para);
  65. }catch(error){}
  66. }
  67.  
  68. }
  69. if(url.indexOf("music.163.") != -1)
  70. {
  71. var IsEnable = false;
  72. if(url.indexOf("playlist") != -1) //判断歌单
  73. {
  74. if(url.indexOf("playlist?id=") != -1)
  75. {
  76. IsEnable = true;
  77. loc = url.match("id=[0-9]*")[0].match("[1-9].*")[0];
  78. }
  79. if(url.indexOf("/playlist/") != -1)
  80. {
  81. IsEnable = true;
  82. loc = url.match("/playlist/[1-9]*")[0].match("[1-9].*")[0];
  83. }
  84. URI = "orpheus://playlist/" + loc;
  85. }
  86. if(url.indexOf("song") != -1) //判断歌曲
  87. {
  88. IsEnable = true;
  89. if(url.indexOf("song?id=") != -1)
  90. {
  91. loc = url.match("id=[0-9]*")[0].match("[1-9].*")[0];
  92. }
  93. if(url.indexOf("/song/") != -1)
  94. {
  95. loc = url.match("/song/[1-9]*")[0].match("[1-9].*")[0];
  96. }
  97. URI = "orpheus://song/" + loc;
  98. }
  99. if(url.indexOf("album") != -1) //判断专辑
  100. {
  101. IsEnable = true;
  102. if(url.indexOf("album?id=") != -1)
  103. {
  104. loc = url.match("id=[0-9]*")[0].match("[1-9].*")[0];
  105. }
  106. if(url.indexOf("/album/") != -1)
  107. {
  108. loc = url.match("/album/[1-9]*")[0].match("[1-9].*")[0];
  109. }
  110. URI = "orpheus://album/" + loc;
  111. }
  112. if(url.indexOf("program?id=") != -1) //判断电台节目
  113. {
  114. IsEnable = true;
  115. if(url.indexOf("program?id=") != -1)
  116. {
  117. loc = url.match("id=[0-9]*")[0].match("[1-9].*")[0];
  118. }
  119. if(url.indexOf("/program/") != -1)
  120. {
  121. loc = url.match("/program/[1-9]*")[0].match("[1-9].*")[0];
  122. }
  123. URI = "orpheus://program/" + loc;
  124. }
  125. if(url.indexOf("artist?id=") != -1) //判断歌手
  126. {
  127. IsEnable = true;
  128. if(url.indexOf("artist?id=") != -1)
  129. {
  130. loc = url.match("id=[0-9]*")[0].match("[1-9].*")[0];
  131. }
  132. if(url.indexOf("/artist/") != -1)
  133. {
  134. loc = url.match("/artist/[1-9]*")[0].match("[1-9].*")[0];
  135. }
  136. URI = "orpheus://artist/" + loc;
  137. }
  138. if(url.indexOf("djradio?id=") != -1) //判断电台主播
  139. {
  140. IsEnable = true;
  141. if(url.indexOf("djradio?id=") != -1)
  142. {
  143. loc = url.match("id=[0-9]*")[0].match("[1-9].*")[0];
  144. }
  145. if(url.indexOf("/djradio/") != -1)
  146. {
  147. loc = url.match("/djradio/[1-9]*")[0].match("[1-9].*")[0];
  148. }
  149. URI = "orpheus://djradio/" + loc;
  150. }
  151. if(IsEnable)
  152. {
  153. document.documentElement.focus();
  154. para = document.createElement("a");
  155. childpara = document.createElement("i");
  156. node=document.createTextNode("用客户端打开");
  157. childpara.appendChild(node);
  158. para.setAttribute("class","u-btni u-btni-dl");
  159. para.href=URI;
  160. para.style.marginTop="7px";
  161. para.appendChild(childpara);
  162. element=document.getElementById("content-operation");
  163. element2 = document.getElementsByClassName("btns f-cb j-flag")[0];
  164. try {element.appendChild(para);}catch(error){}
  165. try {element2.appendChild(para);}catch(error){}
  166. }
  167.  
  168. }
  169. if(url.indexOf("ithome.com") != -1)
  170. {
  171. if(url.indexOf("quan") == -1)
  172. {
  173. loc = url.match("/[0-9]+")[0].match("[0-9]+")[0];
  174. URI = "ithome://ithome.com/?newsid=" + loc;
  175. }
  176. else
  177. {
  178. loc = url.match("[0-9]{3}/[0-9]{3}")[0].replace("/","");
  179. URI = "ithome://ithome.com/?postid=" + loc;
  180. }
  181. para = document.createElement("li");
  182. childpara = document.createElement("a");
  183. childpara.setAttribute("class","nav-item nav-item-7");
  184. childpara.href = URI;
  185. node = document.createTextNode("使用客户端打开");
  186. childpara.appendChild(node);
  187. para.appendChild(childpara);
  188. element = document.getElementsByClassName("nav_list")[0];
  189. try {element.appendChild(para);} catch (error) {}
  190. }
  191. if(URI !== "" && URI !== null && URI !== undefined && IsOpenURIWhenPageLoadedEnable)
  192. {
  193. alert(URI);
  194. window.location.href = URI;
  195. }
  196.  
  197. }
  198. catch (error)
  199. {
  200. //alert(error);
  201. }
  202. }
  203.  
  204. function OnWindowLoaded(event)
  205. {
  206. try
  207. {
  208. window.oneerror=function(){return true;};
  209. var url = window.location.href;
  210. var loc;
  211. var URI="";
  212. if(url.indexOf("bilibili.") != -1 && (url.indexOf("index") != -1 || url.indexOf("html") == -1))
  213. {
  214. if(url.indexOf("bangumi") != -1)
  215. {
  216. var ele= document.getElementsByClassName("v-av-link")[0];
  217. loc = ele.href.match("[0-9]+")[0];
  218. URI = "bilibili://video/" + loc;
  219. ele.setAttribute("target","");
  220. ele.href = URI;
  221. ele.innerText = "使用客户端打开 AV" + loc;
  222. }
  223. }
  224. }
  225. catch(error){}
  226. }

QingJ © 2025

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