Greasy Fork is available in English.
在 Greasy Fork 一键回报垃圾评论
当前为
// ==UserScript==
// @name GreasyFork: One Click Report Spam
// @name:zh-TW GreasyFork 一鍵回報垃圾評論
// @name:zh-CN GreasyFork 一键回报垃圾评论
// @namespace UserScripts
// @match http://greasyfork.icu/*
// @grant none
// @version 1.3
// @author CY Fung
// @license MIT
// @description To report spam comments in Greasy Fork with one click
// @description:zh-TW 在 Greasy Fork 一鍵回報垃圾評論
// @description:zh-CN 在 Greasy Fork 一键回报垃圾评论
// ==/UserScript==
(() => {
const TEST_MODE = 0;
let skipMode = false;
const onIframeLoad = async (evt) => {
const iframe = evt.target;
if (!(iframe instanceof HTMLIFrameElement)) return;
if (skipMode) return;
const onNewUrl = async () => {
skipMode = true;
alert('reported');
await new Promise(requestAnimationFrame);
iframe.remove();
skipMode = false;
}
const onAbort = async () => {
skipMode = true;
await new Promise(requestAnimationFrame);
iframe.remove();
skipMode = false;
}
iframe.removeEventListener('load', onIframeLoad, false);
if (!iframe.contentDocument) {
alert('Iframe Access Error. Action aborted.');
onAbort();
return;
}
const reportReasonRadio = iframe.contentDocument.querySelector('input[name="report[reason]"]');
if (reportReasonRadio) {
reportReasonRadio.scrollIntoView();
await new Promise(requestAnimationFrame);
reportReasonRadio.click();
const form = reportReasonRadio.closest('form');
let currentUrl = iframe.contentWindow.location.pathname;
skipMode = true;
if (TEST_MODE) {
iframe.contentWindow.location.href = 'http://greasyfork.icu/'
} else {
form.submit();
}
let cid = setInterval(() => {
if (!cid) return;
let nextUrl = iframe.contentWindow.location.pathname;
if (nextUrl !== currentUrl) {
clearInterval(cid)
cid = 0;
setTimeout(onNewUrl, 300);
}
}, 100)
} else if (iframe.contentDocument.querySelector('#open-report-:not(:empty)')) {
alert("The spam report is already submitted for moderator's review. Action aborted.");
onAbort();
} else {
alert('Cannot find the report[reason] radio button. Action aborted.');
onAbort();
}
};
const clickHandler = (evt) => {
evt.preventDefault();
if (!(evt.target instanceof HTMLElement)) return;
let url = evt.target.getAttribute('ohref');
if (!url) return;
let userid = /id=(\d+)\b/.exec(url);
if (userid) userid = userid[1];
let r = window.confirm(`Confirm to report user#${userid || "------"} ?`);
if (!r) return;
const iframe = document.createElement('iframe');
skipMode = false;
iframe.addEventListener('load', onIframeLoad, false);
iframe.name = "u423323";
iframe.src = url;
Object.assign(iframe.style, {
display: 'block',
position: 'fixed',
top: '0px',
left: '0px',
width: '300px',
height: '300px',
'contain': 'strict',
});
document.body.appendChild(iframe);
}
for (const anchor of document.querySelectorAll('a[href*="/reports/new?item_class=comment&item_id="],a[href*="/reports/new?item_class=discussion&item_id="]')) {
let anchorNode = anchor;
if (anchor.parentNode.firstElementChild === anchor.parentNode.lastElementChild) {
anchorNode = anchorNode.parentNode;
}
let newAnchorNode = anchorNode.cloneNode(true);
let newAnchor = newAnchorNode.querySelector('a[href]') || newAnchorNode;
newAnchor.setAttribute('ohref', newAnchor.getAttribute('href'));
newAnchor.setAttribute('href', '#');
newAnchor.addEventListener('click', clickHandler, false)
newAnchor.textContent = 'Report Spam';
anchorNode.parentNode.insertBefore(newAnchorNode, anchorNode.nextSibling);
}
})();