在 Greasy Fork 一键回报垃圾评论
当前为
// ==UserScript==
// @name GreasyFork: One Click Report Spam
// @name:zh-TW GreasyFork 一鍵回報垃圾評論
// @name:zh-CN GreasyFork 一键回报垃圾评论
// @namespace UserScripts
// @match https://greasyfork.org/*
// @grant none
// @version 1.0
// @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;
const onIframeLoad = async (evt) => {
const iframe = evt.target;
if (!(evt.target instanceof HTMLIFrameElement)) return;
const onNewUrl = async () => {
alert('reported');
await new Promise(requestAnimationFrame);
iframe.remove();
}
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;
if (TEST_MODE) {
iframe.contentWindow.location.href = 'https://greasyfork.org/'
} 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)
}
};
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');
iframe.name = "u423323"
iframe.src = url;
Object.assign(iframe.style, {
display: 'block',
position: 'fixed',
top: '0px',
left: '0px',
width: '300px',
height: '300px',
'contain': 'strict',
});
iframe.addEventListener('load', onIframeLoad, false);
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);
}
})();