Pintia Code Highlight

自定义 Pintia 代码块样式,提升可读性

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Pintia Code Highlight
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  自定义 Pintia 代码块样式,提升可读性
// @author       Rayni
// @match        https://pintia.cn/*
// @grant        none
// @run-at       document-end
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    // 等待页面加载完成
    const observer = new MutationObserver(() => {
        const preElements = document.querySelectorAll('.rendered-markdown pre');
        preElements.forEach(pre => {
            // 添加自定义样式
            pre.style.display = 'flex';
            pre.style.backgroundColor = '#FFFFFF'; // 深色背景
            pre.style.color = '#000000';           // 浅灰色文本
            pre.style.border = '1px solid #444';
            pre.style.borderRadius = '8px';
            pre.style.padding = '1rem';
            pre.style.fontFamily = '"Fira Code", "Consolas", monospace';
            pre.style.fontSize = '14px';
            pre.style.wordBreak = 'break-all';
            pre.style.overflowX = 'auto';
            pre.style.margin = '0.5rem 0';
            pre.style.textOverflow = 'ellipsis';
            pre.style.whiteSpace = 'pre-wrap';
        });
    });

    // 观察 DOM 变化,以处理动态加载的内容
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    // 初始执行一次
    setTimeout(() => {
        observer.disconnect();
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }, 100);
})();