52 Enhance

Minimalistic enhancements for 52pojie.

目前為 2023-06-20 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         52 Enhance
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  Minimalistic enhancements for 52pojie.
// @author       PRO
// @match        https://www.52pojie.cn/*
// @icon         http://52pojie.cn/favicon.ico
// @grant        none
// @license      gpl-3.0
// ==/UserScript==

(function() {
    'use strict';
    // Dynamic opacity
    let config = {
        opacity: {
            "default": 0.2,
            "hover": 0.8,
            "none": 0.8,
            "transition": "opacity 0.2s ease-in-out"
        }
    };
    let css = document.createElement("style");
    css.textContent = `
    #jz52top {
        opacity: ${config.opacity.default};
        transition: ${config.opacity.transition};
    }
    #jz52top:hover {
        opacity: ${config.opacity.hover};
    }
    @media (any-hover: none) {
        #jz52top {
            opacity: ${config.opacity.none};
        }
        #jz52top:hover {
            opacity: ${config.opacity.none};
        }
    }
    `;
    document.head.appendChild(css);
    // Hide code
    function toggleCode() {
        let code = this.parentNode.parentNode.lastChild;
        if (code.style.display == "none") {
            code.style.display = "";
            this.textContent = " 隐藏代码";
        } else {
            code.style.display = "none";
            this.textContent = " 显示代码";
        }
    }
    document.querySelectorAll("em.viewsource").forEach(ele => {
        let hide_code = document.createElement("em");
        hide_code.setAttribute("style", ele.getAttribute("style"));
        hide_code.setAttribute("num", ele.getAttribute("num"));
        hide_code.textContent = " 隐藏代码";
        hide_code.addEventListener("click", toggleCode);
        ele.parentNode.appendChild(hide_code);
    });
    // Double click navbar to get to top
    document.getElementById("nv").addEventListener("dblclick", e => {
        window.scrollTo({ top: 0, behavior: "smooth" });
    });
})();