blocked catbox soundpost fix

Replaces files.catbox.moe links with files.pixstash.moe on soundposts. files.pixstash.moe is a simple passthrough to bypass ISP blocks.

当前为 2023-08-18 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         blocked catbox soundpost fix
// @namespace    fuwamocobaubau
// @description  Replaces files.catbox.moe links with files.pixstash.moe on soundposts. files.pixstash.moe is a simple passthrough to bypass ISP blocks.
// @author       fuwamocobaubau
// @license MIT
// @version      0.1
// @match        *://boards.4chan.org/*
// @match        *://boards.4channel.org/*
// @match        *://desuarchive.org/*
// @match        *://arch.b4k.co/*
// @match        *://archived.moe/*
// @match        *://warosu.org/*
// @match        *://archive.nyafuu.org/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  window.isChanX = document.documentElement && document.documentElement.classList.contains('fourchan-x');

  function rewriteCatbox(target) {
    let posts = target.classList.contains('post')
      ? [ target ]
      : target.querySelectorAll('.post');

    let filename = null;
    let filenameLocations = {
      '.fileText .file-info .fnfull': 'textContent',
      '.fileText .file-info > a': 'textContent',
      '.fileText > a': 'title',
      '.fileText': 'textContent'
    }


    posts.forEach(post => {
      Object.keys(filenameLocations).some(function (selector) {
        const node = post.querySelector(selector);

        node && (filename = node[filenameLocations[selector]]);
        if (filename && filename.includes('files.catbox.moe')) {
          node[filenameLocations[selector]] = filename.replace('files.catbox.moe', 'files.pixstash.moe')
        }
      });

    });
  }

  async function doInit() {
    rewriteCatbox(document.body);

    const observer = new MutationObserver(function (mutations) {
      mutations.forEach(function (mutation) {
        if (mutation.type === 'childList') {
          mutation.addedNodes.forEach(function (node) {
            if (node.nodeType === Node.ELEMENT_NODE) {
              rewriteCatbox(node);
            }
          });
        }
      });
    });

    observer.observe(document.body, {
      childList: true,
      subtree: true
    });
  }

  document.addEventListener('4chanXInitFinished', doInit);

  // The timeout makes sure 4chan X will have added it's classes and be identified.
  setTimeout(function () {
    // If it's already known 4chan X is installed this can be skipped.
    if (!isChanX) {
      if (document.readyState !== 'loading') {
        doInit();
      } else {
        document.addEventListener('DOMContentLoaded', doInit);
      }
    }
  }, 0);
})();