GreasyFork 一键回报垃圾评论

在 Greasy Fork 一键回报垃圾评论

当前为 2023-09-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GreasyFork: One Click Report Spam
  3. // @name:zh-TW GreasyFork 一鍵回報垃圾評論
  4. // @name:zh-CN GreasyFork 一键回报垃圾评论
  5. // @namespace UserScripts
  6. // @match https://greasyfork.org/*
  7. // @grant none
  8. // @version 1.0
  9. // @author CY Fung
  10. // @license MIT
  11. // @description To report spam comments in Greasy Fork with one click
  12. // @description:zh-TW 在 Greasy Fork 一鍵回報垃圾評論
  13. // @description:zh-CN 在 Greasy Fork 一键回报垃圾评论
  14. // ==/UserScript==
  15.  
  16. (() => {
  17.  
  18. const TEST_MODE = 0;
  19.  
  20. const onIframeLoad = async (evt) => {
  21. const iframe = evt.target;
  22. if (!(evt.target instanceof HTMLIFrameElement)) return;
  23.  
  24.  
  25. const onNewUrl = async () => {
  26.  
  27. alert('reported');
  28. await new Promise(requestAnimationFrame);
  29. iframe.remove();
  30.  
  31. }
  32.  
  33. const reportReasonRadio = iframe.contentDocument.querySelector('input[name="report[reason]"]');
  34. if (reportReasonRadio) {
  35. reportReasonRadio.scrollIntoView();
  36. await new Promise(requestAnimationFrame);
  37. reportReasonRadio.click();
  38. const form = reportReasonRadio.closest('form');
  39. let currentUrl = iframe.contentWindow.location.pathname;
  40. if (TEST_MODE) {
  41.  
  42. iframe.contentWindow.location.href = 'https://greasyfork.org/'
  43. } else {
  44. form.submit();
  45. }
  46. let cid = setInterval(() => {
  47. if (!cid) return;
  48. let nextUrl = iframe.contentWindow.location.pathname;
  49. if (nextUrl !== currentUrl) {
  50. clearInterval(cid)
  51. cid = 0;
  52. setTimeout(onNewUrl, 300);
  53. }
  54. }, 100)
  55.  
  56. }
  57.  
  58. };
  59. const clickHandler = (evt) => {
  60. evt.preventDefault();
  61. if (!(evt.target instanceof HTMLElement)) return;
  62. let url = evt.target.getAttribute('ohref');
  63. if (!url) return;
  64. let userid = /id=(\d+)\b/.exec(url);
  65. if (userid) userid = userid[1];
  66. let r = window.confirm(`Confirm to report user#${userid || "------"} ?`);
  67. if (!r) return;
  68. const iframe = document.createElement('iframe');
  69. iframe.name = "u423323"
  70. iframe.src = url;
  71. Object.assign(iframe.style, {
  72. display: 'block',
  73. position: 'fixed',
  74. top: '0px',
  75. left: '0px',
  76. width: '300px',
  77. height: '300px',
  78. 'contain': 'strict',
  79. });
  80. iframe.addEventListener('load', onIframeLoad, false);
  81. document.body.appendChild(iframe)
  82. }
  83.  
  84.  
  85. for (const anchor of document.querySelectorAll('a[href*="/reports/new?item_class=comment&item_id="],a[href*="/reports/new?item_class=discussion&item_id="]')) {
  86.  
  87. let anchorNode = anchor;
  88. if (anchor.parentNode.firstElementChild === anchor.parentNode.lastElementChild) {
  89. anchorNode = anchorNode.parentNode;
  90. }
  91. let newAnchorNode = anchorNode.cloneNode(true);
  92. let newAnchor = newAnchorNode.querySelector('a[href]') || newAnchorNode;
  93. newAnchor.setAttribute('ohref', newAnchor.getAttribute('href'));
  94. newAnchor.setAttribute('href', '#');
  95. newAnchor.addEventListener('click', clickHandler, false)
  96. newAnchor.textContent = 'Report Spam';
  97. anchorNode.parentNode.insertBefore(newAnchorNode, anchorNode.nextSibling);
  98.  
  99.  
  100. }
  101. })();