GreasyFork脚本列表优化助手

此脚本会在GreasyFork网站的脚本列表页面每个脚本的下面添加几个快捷操作的按钮。作者:浴火凤凰(QQ:307053741,油猴脚本讨论QQ群:194885662)

当前为 2020-01-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GreasyFork脚本列表优化助手
  3. // @namespace https://github.com/kingphoenix2000/tampermonkey_scripts
  4. // @supportURL https://github.com/kingphoenix2000/tampermonkey_scripts
  5. // @version 0.1.3
  6. // @author 浴火凤凰(QQ:307053741,油猴脚本讨论QQ群:194885662)
  7. // @description 此脚本会在GreasyFork网站的脚本列表页面每个脚本的下面添加几个快捷操作的按钮。作者:浴火凤凰(QQ:307053741,油猴脚本讨论QQ群:194885662)
  8. // @homepage https://blog.csdn.net/kingwolf_javascript/
  9. // @include https://greasyfork.org/*
  10. // @grant GM_xmlhttpRequest
  11. // @connect greasyfork.org
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @note 2019-12-12 为脚本列表的每个脚本增加加入黑名单功能,加入黑名单的脚本会在页面加载完成以后被隐藏掉。可以单击显示全部脚本按钮来显示黑名单的脚本
  15. // @note 2020-01-08 在用户主页用户名的后面增加当前用户开发的脚本安装总数
  16. // ==/UserScript==
  17.  
  18.  
  19. (function () {
  20. 'use strict';
  21.  
  22. function removeADS(arr) {
  23. arr.forEach(function (v) {
  24. let elem = document.querySelector(v);
  25. if (elem) { elem.remove(); }
  26. });
  27. }
  28. function addFilterSystem() {
  29. let div = document.createElement("div");
  30. let h2 = document.createElement("h2");
  31. h2.innerText = "GreasyFork脚本列表优化助手";
  32. div.appendChild(h2);
  33. let input = document.createElement("input");
  34. input.id = "filter_input";
  35. input.type = "text";
  36. input.value = "";
  37. input.placeholder = "请输入过滤关键字";
  38. div.appendChild(input);
  39. let showOnlyBtn = document.createElement("input");
  40. let items = document.querySelectorAll("#browse-script-list > li");
  41. let len = items.length;
  42. showOnlyBtn.type = "button";
  43. showOnlyBtn.value = "过滤脚本";
  44. showOnlyBtn.style.marginLeft = "15px";
  45. showOnlyBtn.onclick = function () {
  46. let text = input.value;
  47. for (let i = 0; i < len; i++) {
  48. if (!items[i].innerText.includes(text)) {
  49. items[i].style.display = "none";//隐藏掉不包含关键字的脚本 并且对隐藏掉的包含关键字的脚本不做处理。
  50. }
  51. }
  52. }
  53. let showAllBtn = document.createElement("input");
  54. showAllBtn.type = "button";
  55. showAllBtn.value = "显示全部脚本";
  56. showAllBtn.style.marginLeft = "15px";
  57. showAllBtn.onclick = function () {
  58. for (let i = 0; i < len; i++) {
  59. items[i].style.display = "list-item";
  60. }
  61. }
  62. div.appendChild(showOnlyBtn);
  63. div.appendChild(showAllBtn);
  64. document.querySelector("#browse-script-list").insertBefore(div, document.querySelector("#browse-script-list").firstChild);
  65. }
  66.  
  67. if (location.href.includes("/scripts")) { addFilterSystem(); }
  68.  
  69. let items = document.querySelectorAll("#browse-script-list > li");
  70. let len = items.length;
  71. for (let i = 0; i < len; i++) {
  72. items[i].addEventListener("click", function (e) {
  73. if (e.ctrlKey === true) {
  74. e.preventDefault();
  75. this.remove();
  76. return false;
  77. }
  78. return true;
  79. }, true);
  80. }
  81.  
  82.  
  83.  
  84. let arr = JSON.parse(GM_getValue("scriptIds_Blacklists", "[]"));
  85. var links = document.querySelectorAll("#browse-script-list > li > article > h2 > a");
  86. for (let index = 0; index < links.length; index++) {
  87. const node_li = links[index].parentNode.parentNode.parentNode;
  88. if (arr.includes(node_li.dataset.scriptId)) {
  89. node_li.style.display = "none";//隐藏掉黑名单里的脚本
  90. }
  91. }
  92. links.forEach(function (item) {
  93. var href = item.href;
  94. GM_xmlhttpRequest({
  95. "method": "GET",
  96. "url": href,
  97. "onload": function (response) {
  98. var text = response.responseText;
  99. var scriptURL = text.match(/\/scripts\/[^"']+\.(user\.js)/)[0];
  100. console.log(scriptURL);
  101. let a = document.createElement('a');
  102. a.href = "https://greasyfork.org" + scriptURL;
  103. a.innerText = "安装脚本";
  104. let a2 = document.createElement('a');
  105. a2.href = "javascript:void(0);";
  106. a2.innerText = "删除脚本";
  107. let node_li = item.parentNode.parentNode.parentNode;
  108. a2.onclick = function () { node_li.remove(); }
  109. a2.style.marginLeft = "15px";
  110. let a3 = document.createElement('a');
  111. a3.href = "javascript:void(0);";
  112. a3.innerText = "加入黑名单";
  113. let arr = JSON.parse(GM_getValue("scriptIds_Blacklists", "[]"));
  114. if (arr.includes(node_li.dataset.scriptId)) { a3.innerText = "移除黑名单"; }
  115. a3.onclick = function () {
  116. let arr = JSON.parse(GM_getValue("scriptIds_Blacklists", "[]"));
  117. if (arr.includes(node_li.dataset.scriptId)) {
  118. arr.splice(arr.indexOf(node_li.dataset.scriptId), 1);
  119. GM_setValue("scriptIds_Blacklists", JSON.stringify(arr));
  120. this.innerText = "加入黑名单";
  121. }
  122. else {
  123. arr.push(node_li.dataset.scriptId);
  124. GM_setValue("scriptIds_Blacklists", JSON.stringify(arr));
  125. node_li.style.display = "none";
  126. this.innerText = "移除黑名单";
  127. }
  128. }
  129. a3.style.marginLeft = "15px";
  130. let a4 = document.createElement('a');
  131. a4.href = "https://greasyfork.org/zh-CN/users/289205-%E6%B5%B4%E7%81%AB%E5%87%A4%E5%87%B0";
  132. a4.innerText = "浴火凤凰的其它脚本";
  133. a4.style.marginLeft = "15px";
  134. item.parentNode.appendChild(a);
  135. item.parentNode.appendChild(a2);
  136. item.parentNode.appendChild(a3);
  137. item.parentNode.appendChild(a4);
  138. },
  139. onerror: function (response) {
  140. console.error("查询信息发生错误。");
  141. },
  142. ontimeout: function (response) {
  143. console.info("查询信息超时。");
  144. }
  145. });
  146. });
  147.  
  148. if (location.href.includes("/users/")) {
  149. let items = document.querySelectorAll("#user-script-list article > dl > dd.script-list-total-installs > span");
  150. let sum = 0;
  151. for (let i = 0; i < items.length; i++) {
  152. let n = parseInt(items[i].innerText, 10);
  153. if (!isNaN(n)) { sum += n; }
  154. }
  155. let text = document.querySelector("body > div.width-constraint > section > h2").innerText;
  156. document.querySelector("body > div.width-constraint > section > h2").innerText = text + `(${sum})`;
  157. }
  158. // Your code here...
  159. })();