GreasyFork脚本列表优化助手

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

目前為 2019-12-09 提交的版本,檢視 最新版本

  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.1
  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. // ==/UserScript==
  13.  
  14.  
  15. (function () {
  16. 'use strict';
  17.  
  18. function removeADS(arr) {
  19. arr.forEach(function (v) {
  20. let elem = document.querySelector(v);
  21. if (elem) { elem.remove(); }
  22. });
  23. }
  24. function addFilterSystem() {
  25. let div = document.createElement("div");
  26. let h2 = document.createElement("h2");
  27. h2.innerText = "GreasyFork脚本列表优化助手";
  28. div.appendChild(h2);
  29. let input = document.createElement("input");
  30. input.id = "filter_input";
  31. input.type = "text";
  32. input.value = "";
  33. input.placeholder = "请输入过滤关键字";
  34. div.appendChild(input);
  35. let showOnlyBtn = document.createElement("input");
  36. let items = document.querySelectorAll("#browse-script-list > li");
  37. let len = items.length;
  38. showOnlyBtn.type = "button";
  39. showOnlyBtn.value = "过滤脚本";
  40. showOnlyBtn.style.marginLeft = "15px";
  41. showOnlyBtn.onclick = function () {
  42. let text = input.value;
  43. for (let i = 0; i < len; i++) {
  44. items[i].style.display = "none";
  45. if (items[i].innerText.includes(text)) {
  46. items[i].style.display = "list-item";
  47. }
  48. }
  49. }
  50. let showAllBtn = document.createElement("input");
  51. showAllBtn.type = "button";
  52. showAllBtn.value = "显示全部脚本";
  53. showAllBtn.style.marginLeft = "15px";
  54. showAllBtn.onclick = function () {
  55. for (let i = 0; i < len; i++) {
  56. items[i].style.display = "list-item";
  57. }
  58. }
  59. div.appendChild(showOnlyBtn);
  60. div.appendChild(showAllBtn);
  61. document.querySelector("#browse-script-list").insertBefore(div, document.querySelector("#browse-script-list").firstChild);
  62. }
  63.  
  64. addFilterSystem();
  65.  
  66. let items = document.querySelectorAll("#browse-script-list > li");
  67. let len = items.length;
  68. for (let i = 0; i < len; i++) {
  69. items[i].addEventListener("click", function (e) {
  70. if (e.ctrlKey === true) {
  71. e.preventDefault();
  72. this.remove();
  73. return false;
  74. }
  75. return true;
  76. }, true);
  77. }
  78.  
  79.  
  80. var links = document.querySelectorAll("#browse-script-list > li > article > h2 > a");
  81. links = Array.from(links);
  82. links.forEach(function (item) {
  83. var href = item.href;
  84. GM_xmlhttpRequest({
  85. "method": "GET",
  86. "url": href,
  87. "onload": function (response) {
  88. var text = response.responseText;
  89. var scriptURL = text.match(/\/scripts\/[^"']+\.(user\.js)/)[0];
  90. console.log(scriptURL);
  91. let a = document.createElement('a');
  92. a.href = "https://greasyfork.org" + scriptURL;
  93. a.innerText = "安装脚本";
  94. let a2 = document.createElement('a');
  95. a2.href = "javascript:void(0);";
  96. a2.innerText = "删除脚本";
  97. a2.onclick = function () { item.parentNode.parentNode.parentNode.remove(); }
  98. a2.style.marginLeft = "15px";
  99. let a3 = document.createElement('a');
  100. a3.href = "https://greasyfork.org/zh-CN/users/289205-%E6%B5%B4%E7%81%AB%E5%87%A4%E5%87%B0";
  101. a3.innerText = "浴火凤凰的其它脚本";
  102. a3.style.marginLeft = "15px";
  103. item.parentNode.appendChild(a);
  104. item.parentNode.appendChild(a2);
  105. item.parentNode.appendChild(a3);
  106. },
  107. onerror: function (response) {
  108. console.error("查询信息发生错误。");
  109. },
  110. ontimeout: function (response) {
  111. console.info("查询信息超时。");
  112. }
  113. });
  114. });
  115. // Your code here...
  116. })();