Sleazy Fork is available in English.

橘二八的快乐生活

橘二八的定制脚本-B站点赞,下载某网站视频

  1. // ==UserScript==
  2. // @name 橘二八的快乐生活
  3. // @namespace YoungYang
  4. // @version 0.2
  5. // @description 橘二八的定制脚本-B站点赞,下载某网站视频
  6. // @author You
  7. // @match *://*.bilibili.com/*
  8. // @match *://*.pornhub.com/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. let currentURL = window.location.href;
  18.  
  19. // initBilibili
  20. let initBilibili = function(){
  21.  
  22. // 判断是不是视频页面
  23. let regex = new RegExp("(www\.)?bilibili.com/video/[a-zA-Z0-9]+/");
  24. if( !regex.test(currentURL) ){
  25. return;
  26. }
  27. // 添加绑定事件
  28. let _wr = function(type) {
  29. let orig = history[type];
  30. return function() {
  31. let rv = orig.apply(this, arguments);
  32. let e = new Event(type);
  33. e.arguments = arguments;
  34. window.dispatchEvent(e);
  35. return rv;
  36. };
  37. };
  38. history.pushState = _wr('pushState');
  39. history.replaceState = _wr('replaceState');
  40.  
  41. // 防抖
  42. let timeout = null;
  43. let debounce = function(func, wait = 2000, immediate = false) {
  44. if (timeout !== null) clearTimeout(timeout);
  45. if (immediate) {
  46. var callNow = !timeout;
  47. timeout = setTimeout(function() {
  48. timeout = null;
  49. }, wait);
  50. if (callNow) typeof func === 'function' && func();
  51. } else {
  52. timeout = setTimeout(function() {
  53. typeof func === 'function' && func();
  54. }, wait);
  55. }
  56. }
  57.  
  58. // 点赞
  59. let clickLike = function(){
  60. let curLike = document.querySelector(".video-like.video-toolbar-left-item");
  61. if (curLike) {
  62. if ( curLike.classList.contains('on') ) {
  63. console.log('已经点赞');
  64. } else {
  65. console.log('没有点赞,正在点赞');
  66. curLike.click();
  67. }
  68. }
  69. }
  70.  
  71. // 检测是否登录
  72. let UserInterval = setInterval(function(){
  73. let userImg = document.querySelector(".bili-header .header-entry-mini .v-img");
  74. if (userImg) {
  75. debounce(clickLike);
  76. window.addEventListener('replaceState', function(e) {
  77. debounce(clickLike);
  78. });
  79. window.addEventListener('pushState', function(e) {
  80. debounce(clickLike);
  81. });
  82. clearInterval(UserInterval);
  83. }
  84. },1000);
  85.  
  86. };
  87.  
  88.  
  89. // initPornhub
  90. let initPornhub = function(){
  91.  
  92. // 判断是不是视频页面
  93. let regex = new RegExp('pornhub\\.com/view_video\\.php\\?viewkey=');
  94. if( !regex.test(currentURL) ){
  95. return;
  96. }
  97.  
  98. // 页面所需的CSS
  99. let initStyles = function () {
  100. let style = document.createElement("style");
  101. style.appendChild(document.createTextNode(`
  102. div#__draw__Pane {
  103. position: relative;
  104. z-index: 9999;
  105. }
  106. div#__draw__Pane .__button{
  107. position: fixed;
  108. left: 50px;
  109. top: 50%;
  110. transform: translate3d(-50%, -50%, 0);
  111. background: #fff;
  112. display: flex;
  113. justify-content: center;
  114. align-items: center;
  115. font-size: 20px;
  116. color: #000;
  117. width: 50px;
  118. height: 50px;
  119. border-radius: 50%;
  120. }
  121. div#__draw__Pane .__pane{
  122. display: none;
  123. position: fixed;
  124. left: 50%;
  125. top: 50%;
  126. background: #fff;
  127. padding: 20px;
  128. color: #000;
  129. font-size: 20px;
  130. transform: translate3d(-50%, -50%, 0);
  131. }
  132. div#__draw__Pane .__pane.on{
  133. display: block;
  134. }
  135. `));
  136. document.head.appendChild(style);
  137. }
  138.  
  139. // 绘制表格 draw Pane
  140. let drawPane = function(infos, id){
  141. let dom = document.getElementById(id);
  142. if (!dom) {
  143. dom = document.createElement("div");
  144. dom.id = id;
  145. dom.innerHTML = `
  146. <div class="__button">D</div>
  147. <div class="__pane">
  148. <table>
  149. <tr>
  150. <th>质量</th>
  151. <th>下载地址</th>
  152. </tr>
  153. ${infos
  154. .map(
  155. (item) => `
  156. <tr>
  157. <td>${item.quality}</td>
  158. <td><a href="${item.videoUrl}" onclick="javascript:return false">右键另存为</a></td>
  159. </tr>
  160. `
  161. )
  162. .join("")}
  163. </table>
  164. </div>
  165. `;
  166.  
  167. document.body.appendChild(dom);
  168.  
  169. let __button = document.querySelector(`#${id} .__button`);
  170. let __pane = document.querySelector(`#${id} .__pane`);
  171.  
  172. __button.addEventListener('click', function() {
  173. if ( __pane.classList.contains('on') ) {
  174. __pane.classList.remove("on");
  175. } else {
  176. __pane.classList.add("on");
  177. }
  178. });
  179. };
  180. }
  181.  
  182. // 获取所有视频信息
  183. let videosInfo = eval(
  184. Object.keys(window).filter((item) => item.indexOf("flashvars_") == 0)[0]
  185. ).mediaDefinitions;
  186.  
  187. // 获取所有视频信息
  188. let mp4Url = videosInfo.filter((item) => item.format == "mp4")[0].videoUrl;
  189. fetch(mp4Url)
  190. .then((data) => data.json())
  191. .then((data) => {
  192. console.table(
  193. data.map((item) => ({ 质量: item.quality, 地址: item.videoUrl }))
  194. );
  195. initStyles();
  196. drawPane(data, "__draw__Pane");
  197. })
  198. // .catch((error) => {
  199. // alert("视频详情获取失败");
  200. // console.error(error);
  201. // });
  202. }
  203.  
  204.  
  205.  
  206.  
  207. // 初始化
  208. let currentHostName = window.location.hostname;
  209. let regexUrl = {
  210. "bilibili": /bilibili.com/,
  211. "pornhub": /pornhub.com/,
  212. }
  213.  
  214.  
  215. if( regexUrl.bilibili.test(currentHostName) ){
  216. initBilibili();
  217. }
  218.  
  219. if( regexUrl.pornhub.test(currentHostName) ){
  220. initPornhub();
  221. }
  222.  
  223. })();