蜜柑计划(Mikan Project)复制全部磁链

复制某部番的某个字幕组的全部磁链

  1. // ==UserScript==
  2. // @name 蜜柑计划(Mikan Project)复制全部磁链
  3. // @namespace
  4. // @version 0.1.13
  5. // @description 复制某部番的某个字幕组的全部磁链
  6. // @author cookedfish
  7. // @match http*://mikanime.tv/Home/Bangumi/*
  8. // @match http*://mikanani.me/Home/Bangumi/*
  9. // @grant GM_setClipboard
  10. // @license MIT
  11. // ==/UserScript==
  12. function print_messageBar(max){//消息框
  13. var messageBar = document.createElement('div');
  14. messageBar.textContent = max;
  15. messageBar.style.position = 'fixed';
  16. messageBar.style.bottom = '0';
  17. messageBar.style.left = '0';
  18. messageBar.style.width = '100%';
  19. messageBar.style.backgroundColor = 'green';
  20. messageBar.style.color = 'white';
  21. messageBar.style.textAlign = 'center';
  22. messageBar.style.padding = '10px 0';
  23. document.body.appendChild(messageBar);
  24. setTimeout(function() {
  25. messageBar.parentNode.removeChild(messageBar);
  26. }, 1000);
  27. }
  28. function search(text,Value){//单词模式
  29. var startIndex = 0;
  30. while (startIndex < text.length) {//匹配关键字词
  31. var index = text.indexOf(Value, startIndex);
  32. if (index !== -1) {
  33. console.log('%c' + 'true','color: green',text,Value);
  34. return true;
  35. } else {
  36. break;
  37. }
  38. }
  39. console.log('%c' + 'false', 'color: red', text, Value);
  40. return false;
  41. }
  42. function multiple_match(texts, Value) {//多词模式
  43. var searchTerms = Value.split(' ');
  44. for (var i = 0; i < searchTerms.length; i++) {
  45. console.log(searchTerms[i]);
  46. if (!search(texts, searchTerms[i])) {return false;}
  47. }
  48. return true;
  49. }
  50. function get_xunlei(){//复制按钮
  51. var num = parseInt($(this).closest('div').attr('id'));
  52. console.log(num);
  53. var urls = [];
  54. var abc = undefined;
  55. var checkbox = [];
  56. var box = false;
  57. var mode = $(this).nextAll("a:first").next('a').text();
  58. console.log(mode);
  59. $('.table').find('input').each(function () {
  60. if($(this).attr('id') !== "myCheckbox") return true;
  61. if (parseInt($(this).closest('table').prev('div').attr('id')) !== num && $(this).closest('table').prev('div').attr('id') !== abc) return true;
  62. checkbox.push($(this).attr('effect'));
  63. });
  64. console.log(checkbox);
  65. for(var i = 0;i < checkbox.length;i++){
  66. if(checkbox[i] === 'checked'){//预检查勾选框是否有勾选
  67. box=true;
  68. break;
  69. console.log(i);
  70. }
  71. box=false;
  72. }
  73. console.log(box);
  74. if(box===false){
  75. $('.table').find('a').each(function () {//按条件排除
  76. if($(this).attr('class') !== "js-magnet magnet-link") return true;
  77. if (parseInt($(this).closest('table').prev('div').attr('id')) !== num && $(this).closest('table').prev('div').attr('id') !== abc) return true;
  78. if($(this).closest('table').prev('div').find('input').val()&&mode === ' 模式切换:单词模式'&&search($(this).prev('a').text(),$(this).closest('table').prev('div').find('input').val())===false) return true;
  79. if($(this).closest('table').prev('div').find('input').val()&&mode === ' 模式切换:多词模式'&&multiple_match($(this).prev('a').text(),$(this).closest('table').prev('div').find('input').val())===false) return true;
  80. if($(this).closest('table').prev('div').find('input').val()&&mode === ' 模式切换:打开模式'&&multiple_match($(this).prev('a').text(),$(this).closest('table').prev('div').find('input').val())===false) return true;
  81. urls.push($(this).attr('data-clipboard-text'));
  82. $(this).prev('a').prev('input').click();
  83. });
  84. }
  85. else{
  86. $('.table').find('a').each(function () {
  87. if($(this).attr('class') !== "js-magnet magnet-link") return true;
  88. if (parseInt($(this).closest('table').prev('div').attr('id')) !== num && $(this).closest('table').prev('div').attr('id') !== abc) return true;
  89. if($(this).prev('a').prev('input').attr('effect') === 'uncheck') return true;
  90. urls.push($(this).attr('data-clipboard-text'));
  91. });
  92. };
  93. if(mode === ' 模式切换:打开模式'){
  94. for(i = 0;i < urls.length;i++)
  95. {
  96. var pages = window.open(urls[i], '_blank');
  97. pages.close();
  98. if(i % 10 === 9) alert(i-8 + '-' + (i+1) + '条,共' + urls.length + '条');
  99. }
  100. }
  101. print_messageBar('复制了'+urls.length+'个链接');
  102. GM_setClipboard(urls.join('\n'));//更改剪贴板
  103. };
  104. function click(){//自动展开
  105. document.querySelectorAll('a.js-expand-episode').forEach(function(element) {
  106. element.click();
  107. });
  108. }
  109. function Mode(){//模式切换
  110. var currentMode = $(this).text().trim();
  111. switch (currentMode) {
  112. case '模式切换:多词模式':
  113. $(this).text(' 模式切换:打开模式');
  114. break;
  115. case '模式切换:单词模式':
  116. $(this).text(' 模式切换:多词模式');
  117. break;
  118. case '模式切换:打开模式':
  119. $(this).text(' 模式切换:单词模式');
  120. break;
  121. default:
  122. break;
  123. };
  124. }
  125. function del(){//清空勾选框
  126. var num = parseInt($(this).closest('div').attr('id'));
  127. $('.table').find('input').each(function () {
  128. if($(this).attr('id') !== 'myCheckbox') return true;
  129. if (parseInt($(this).closest('table').prev('div').attr('id')) !== num && $(this).closest('table').prev('div').attr('id') !== 'undefined') return true;
  130. if($(this).attr('effect') === 'checked') $(this).click();
  131. console.log($(this).attr('effect'));
  132. });
  133. }
  134. function change(){//改变勾选框
  135. if($(this).attr('effect') === 'uncheck') $(this).attr('effect', 'checked');
  136. else $(this).attr('effect', 'uncheck');
  137. }
  138. function title(){//字幕组名
  139. var title=$(this).attr('data-anchor');
  140. title = title.replace(/#/g, '');
  141. console.log(title);
  142. var urls = [];
  143. var abc = undefined;
  144. $('.table').find('a').each(function () {//按条件排除
  145. if($(this).attr('class') !== "js-magnet magnet-link") return true;
  146. if ($(this).closest('table').prev('div').attr('id') !== title && $(this).closest('table').prev('div').attr('id') !== abc) return true;
  147. urls.push($(this).attr('data-clipboard-text'));
  148. });
  149. print_messageBar('复制了'+urls.length+'个链接');
  150. GM_setClipboard(urls.join('\n'));//更改剪贴板
  151. }
  152. (function (){
  153. $(document).on('click', 'a[ref="thunder"]', get_xunlei);//绑定事件
  154. $(document).on('click', 'a[ref="mode"]', Mode);
  155. $(document).on('click', 'a[data-anchor^="#"]',title);
  156. $(document).on('click', 'a[ref="del"]', del);
  157. $(document).on('click', 'input[ref="checkbox"]', change);
  158. $('.subgroup-text i').closest('a').each(function() {
  159. var $button = $('<a class="js-magnet magnet-link" ref="mode" style="background-color:white" > 模式切换:多词模式</a>');
  160. var $del = $('<a class="js-magnet magnet-link" ref="del" > [清空勾选框]</a>');
  161. var $input = $('<input type="text" id="magnet-input" placeholder="输入关键字词(区分大小写)">');
  162. var $thunder_magnet = $('<a class="js-magnet magnet-link" ref="thunder" style="background-color:white" > [复制/打开] </a>');
  163. $(this).after($thunder_magnet, $input ,$del, $button);//添加按钮
  164. });
  165. $('a.magnet-link-wrap').each(function() {//先执行一遍
  166. if ($(this).prev().is('input')) {//避免重复添加勾选框
  167. return;
  168. }
  169. var $check = $('<input type="checkbox" id="myCheckbox" ref="checkbox" effect="uncheck">');
  170. $(this).before($check);
  171. });
  172. const origOpen = XMLHttpRequest.prototype.open;
  173. XMLHttpRequest.prototype.open = function() {
  174. this.addEventListener("loadend", function() {
  175. $('a.magnet-link-wrap').each(function() {
  176. if ($(this).prev().is('input')) {//避免重复添加勾选框
  177. return;
  178. }
  179. var $check = $('<input type="checkbox" id="myCheckbox" ref="checkbox" effect="uncheck">');
  180. $(this).before($check);
  181. });
  182. });
  183. origOpen.apply(this, arguments);
  184. };
  185. $('div.header').text('字幕组列表(点击复制)');
  186. click();
  187. })();