Greasy Fork镜像 Enhance

Enhance your experience at Greasyfork.

Verze ze dne 26. 05. 2023. Zobrazit nejnovější verzi.

// ==UserScript==
// @name         Greasy Fork镜像 Enhance
// @name:zh-CN   Greasy Fork镜像 增强
// @namespace    http://tampermonkey.net/
// @version      0.1.4
// @description  Enhance your experience at Greasyfork.
// @description:zh-CN 增进 Greasyfork 浏览体验。
// @author       PRO
// @match        https://greasyfork.dpdns.org/*
// @icon         https://greasyfork.dpdns.org/vite/assets/blacklogo16-bc64b9f7.png
// @license      gpl-3.0
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    function sanitify(s) {
        // Remove emojis (such a headache)
        s = s.replaceAll(/([\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2580-\u27BF]|\uD83E[\uDD10-\uDEFF]|\uFE0F| )/g, "");
        // Trim spaces and newlines
        s = s.trim();
        // Replace spaces
        s = s.replaceAll(" ", "-");
        s = s.replaceAll("%20", "-");
        // No more multiple "-"
        s = s.replaceAll(/-+/g, "-");
        return s;
    }
    function process(node) { // Add anchor and assign id to given node
        if (node.childElementCount > 1) return; // Ignore complex nodes
        node.id = sanitify(node.textContent); // Assign id
        // Add anchors
        let node_ = document.createElement('a');
        node_.className = 'anchor';
        node_.href = '#' + node.id;
        node.appendChild(node_);
    }
    // Css for anchors
    let css = document.createElement("style");
    css.textContent = `
    html {
        scroll-behavior: smooth;
    }
    a.anchor::before {
        content: "#";
    }
    a.anchor {
        opacity: 0;
        text-decoration: none;
        padding: 0px 0.5em;
        -moz-transition: all 0.25s ease-in-out;
        -o-transition: all 0.25s ease-in-out;
        -webkit-transition: all 0.25s ease-in-out;
        transition: all 0.25s ease-in-out;
    }
    h1:hover>a.anchor,
    h2:hover>a.anchor,
    h3:hover>a.anchor,
    h4:hover>a.anchor,
    h5:hover>a.anchor,
    h6:hover>a.anchor {
        opacity: 1;
        -moz-transition: all 0.25s ease-in-out;
        -o-transition: all 0.25s ease-in-out;
        -webkit-transition: all 0.25s ease-in-out;
        transition: all 0.25s ease-in-out;
    }
    @media (any-hover: none) {
        a.anchor {
            opacity: 1;
        }
    }`;
    document.querySelector("head").appendChild(css); // Inject css
    document.querySelectorAll("body > div.width-constraint h1, h2, h3, h4, h5, h6").forEach(process); // Main
    // Navigate to hash
    let hash = window.location.hash.slice(1);
    if (hash) {
        let ele = document.getElementById(decodeURIComponent(hash));
        if (ele) {
            ele.scrollIntoView();
        }
    }
})();
长期地址
遇到问题?请前往 GitHub 提 Issues,或加Q群1031348184

赞助商

Fishcpy

广告

Rainyun

注册一下就行

Rainyun

一年攒够 12 元