Furaffinity-Prototype-Extensions

Library to hold common prototype extensions for your Furaffinity Script

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.greasyfork.org/scripts/525666/1803335/Furaffinity-Prototype-Extensions.js

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

Advertisement:

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

Advertisement:

// ==UserScript==
// @name        Furaffinity-Prototype-Extensions
// @namespace   Violentmonkey Scripts
// @grant       GM_info
// @version     1.0.4
// @author      Midori Dragon
// @description Library to hold common prototype extensions for your Furaffinity Script
// @icon        https://raw.githubusercontent.com/Midori-Dragon/furaffinity-features/refs/heads/main/assets/icons/fa_logo.svg
// @license     MIT
// @homepageURL https://greasyfork.org/scripts/525666-furaffinity-prototype-extensions
// @supportURL  https://greasyfork.org/scripts/525666-furaffinity-prototype-extensions/feedback
// ==/UserScript==
// jshint esversion: 11
(function () {
    'use strict';

    Node.prototype.insertBeforeThis = function (newNode) {
        this.parentNode?.insertBefore(newNode, this);
    };
    Node.prototype.insertAfterThis = function (newNode) {
        this.parentNode?.insertBefore(newNode, this.nextSibling);
    };
    Node.prototype.getIndexOfThis = function () {
        if (this.parentNode == null) {
            return -1;
        }
        const childrenArray = Array.from(this.parentNode.children);
        return childrenArray.indexOf(this);
    };
    Node.prototype.readdToDom = function () {
        const clone = this.cloneNode(false);
        this.parentNode?.replaceChild(clone, this);
        return clone;
    };

    String.prototype.trimEnd = function (toTrim) {
        if (toTrim == null) {
            return '';
        }
        if (toTrim === '' || this === '') {
            return this.toString();
        }
        let result = this.toString();
        while (result.endsWith(toTrim)) {
            result = result.slice(0, -toTrim.length);
        }
        return result;
    };
    String.prototype.trimStart = function (toTrim) {
        if (toTrim == null) {
            return '';
        }
        if (toTrim === '' || this === '') {
            return this.toString();
        }
        let result = this.toString();
        while (result.startsWith(toTrim)) {
            result = result.slice(toTrim.length);
        }
        return result;
    };

})();