Furaffinity-Custom-Pages

Helper Script to create Custom pages on Furaffinitiy

当前为 2023-10-05 提交的版本,查看 最新版本

此脚本不应直接安装,它是供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/476762/1260198/Furaffinity-Custom-Pages.js

  1. // ==UserScript==
  2. // @name Furaffinity-Custom-Pages
  3. // @namespace Violentmonkey Scripts
  4. // @grant none
  5. // @version 1.0.2
  6. // @author Midori Dragon
  7. // @description Helper Script to create Custom pages on Furaffinitiy
  8. // @icon https://www.furaffinity.net/themes/beta/img/banners/fa_logo.png?v2
  9. // @homepageURL https://greasyfork.org/de/scripts/476762-furaffinity-custom-pages
  10. // @supportURL https://greasyfork.org/de/scripts/476762-furaffinity-custom-pages/feedback
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. // jshint esversion: 8
  15.  
  16. (() => {
  17. const customPagesAll = [];
  18.  
  19. class CustomPage extends EventTarget {
  20. constructor(parameterName, pageUrl) {
  21. super();
  22. this.parameterName = parameterName;
  23. this.url = pageUrl;
  24. customPagesAll.push(this);
  25. }
  26.  
  27. static checkCustomPagesOpened() {
  28. for (const customPage of customPagesAll) {
  29. customPage.checkPageOpened();
  30. }
  31. }
  32.  
  33. pageOpened(parameterValue, openedPage) {
  34. const customData = new CustomData();
  35. customData.parameterValue = parameterValue;
  36. customData.document = openedPage;
  37. const event = new CustomEvent("pageOpened", { detail: customData });
  38. this.dispatchEvent(event);
  39. }
  40.  
  41. isPageOpened() {
  42. const url = window.location.toString();
  43. if (this.pageUrl && !url.includes(this.pageUrl)) return false;
  44. const parameter = extractParameterFromURL(url, this.parameterName);
  45. if (parameter && parameter.key == this.parameterName) return true;
  46. return false;
  47. }
  48.  
  49. getPageParameterValue() {
  50. const url = window.location.toString();
  51. const parameter = extractParameterFromURL(url, this.parameterName);
  52. if (parameter) return parameter.value;
  53. }
  54.  
  55. checkPageOpened() {
  56. if (this.isPageOpened()) this.pageOpened(this.getPageParameterValue(), document);
  57. }
  58. }
  59.  
  60. class CustomData {
  61. constructor() {
  62. this.parameterValue;
  63. this.document;
  64. }
  65.  
  66. removeDocumentSiteContent() {
  67. const siteContent = this.document.getElementById("site-content");
  68. if (siteContent) siteContent.remove();
  69. return siteContent;
  70. }
  71. }
  72.  
  73. function extractParameterFromURL(url, parameterName) {
  74. if (!url || !parameterName) return null;
  75. const parts = url.split("?");
  76. if (parts.length > 1) {
  77. const params = parts[1].split("&");
  78. for (const param of params) {
  79. const [key, value] = param.split("=");
  80. if (key === parameterName) return { key, value: decodeURIComponent(value) };
  81. }
  82. }
  83. return null;
  84. }
  85.  
  86. window.FACustomPage = CustomPage;
  87. })();