dlaa.me shiki highlight

highlight old posts, needs manually overriding csp to preview

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         dlaa.me shiki highlight
// @namespace    http://unlucky.ninja/
// @version      2025-10-04
// @description  highlight old posts, needs manually overriding csp to preview
// @author       UnluckyNinja
// @match        https://dlaa.me/blog/post/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=dlaa.me
// @license      Unlicense
// @grant        none
// ==/UserScript==

(async function() {
    'use strict';

    // ignore newer posts
    if (!document.querySelector('pre:not(:has(code[class]))')) {
        return
    }

    const { codeToHtml } = await import('https://esm.sh/[email protected]')

    document.querySelectorAll('pre:not(:has(code[class]))').forEach(async ele=>{
        const html = await codeToHtml(ele.textContent, {
            lang: 'csharp',
            theme: 'catppuccin-macchiato'
        })
        ele.innerHTML = html
        ele.firstChild.firstChild.style.backgroundColor = 'inherit' // avoid original style interfering
        ele.replaceWith(ele.firstChild)
    })

})();