GreasyFork 一鍵回報垃圾評論

在 Greasy Fork镜像 一鍵回報垃圾評論

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

// ==UserScript==
// @name        GreasyFork: One Click Report Spam
// @name:zh-TW  GreasyFork 一鍵回報垃圾評論
// @name:zh-CN  GreasyFork 一键回报垃圾评论
// @namespace   UserScripts
// @match       https://gf.qytechs.cn/*
// @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://gf.qytechs.cn/'
      } 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);


  }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址