Furaffinity-Custom-Pages

Helper Script to create Custom pages on Furaffinitiy

目前為 2023-10-05 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/476762/1260198/Furaffinity-Custom-Pages.js

// ==UserScript==
// @name        Furaffinity-Custom-Pages
// @namespace   Violentmonkey Scripts
// @grant       none
// @version     1.0.2
// @author      Midori Dragon
// @description Helper Script to create Custom pages on Furaffinitiy
// @icon        https://www.furaffinity.net/themes/beta/img/banners/fa_logo.png?v2
// @homepageURL https://gf.qytechs.cn/de/scripts/476762-furaffinity-custom-pages
// @supportURL  https://gf.qytechs.cn/de/scripts/476762-furaffinity-custom-pages/feedback
// @license     MIT
// ==/UserScript==

// jshint esversion: 8

(() => {
  const customPagesAll = [];

  class CustomPage extends EventTarget {
    constructor(parameterName, pageUrl) {
      super();
      this.parameterName = parameterName;
      this.url = pageUrl;
      customPagesAll.push(this);
    }

    static checkCustomPagesOpened() {
      for (const customPage of customPagesAll) {
        customPage.checkPageOpened();
      }
    }

    pageOpened(parameterValue, openedPage) {
      const customData = new CustomData();
      customData.parameterValue = parameterValue;
      customData.document = openedPage;
      const event = new CustomEvent("pageOpened", { detail: customData });
      this.dispatchEvent(event);
    }

    isPageOpened() {
      const url = window.location.toString();
      if (this.pageUrl && !url.includes(this.pageUrl)) return false;
      const parameter = extractParameterFromURL(url, this.parameterName);
      if (parameter && parameter.key == this.parameterName) return true;
      return false;
    }

    getPageParameterValue() {
      const url = window.location.toString();
      const parameter = extractParameterFromURL(url, this.parameterName);
      if (parameter) return parameter.value;
    }

    checkPageOpened() {
      if (this.isPageOpened()) this.pageOpened(this.getPageParameterValue(), document);
    }
  }

  class CustomData {
    constructor() {
      this.parameterValue;
      this.document;
    }

    removeDocumentSiteContent() {
      const siteContent = this.document.getElementById("site-content");
      if (siteContent) siteContent.remove();
      return siteContent;
    }
  }

  function extractParameterFromURL(url, parameterName) {
    if (!url || !parameterName) return null;
    const parts = url.split("?");
    if (parts.length > 1) {
      const params = parts[1].split("&");
      for (const param of params) {
        const [key, value] = param.split("=");
        if (key === parameterName) return { key, value: decodeURIComponent(value) };
      }
    }
    return null;
  }

  window.FACustomPage = CustomPage;
})();

QingJ © 2025

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