Syntax Highlighting - UserStyles.world

Syntax Highlighting for the Source Code

当前为 2023-06-25 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Syntax Highlighting - UserStyles.world
// @namespace    https://github.com/pabli24
// @version      0.1
// @description  Syntax Highlighting for the Source Code
// @author       Pabli
// @license      MIT
// @match        https://userstyles.world/style/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=userstyles.world
// @require      https://greasyfork.org/scripts/469422-highlight-js-css-less-scss-stylus/code/Highlightjs%20CSS%20Less%20SCSS%20Stylus.js?version=1210677
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

//tomorrow-night-bright
GM_addStyle(`pre{background-color:#242424}pre code.hljs{display:block}code.hljs{padding:3px 5px}.hljs-comment,.hljs-quote{color:#969896}.hljs-deletion,.hljs-name,.hljs-regexp,.hljs-selector-class,.hljs-selector-id,.hljs-tag,.hljs-template-variable,.hljs-variable{color:#d54e53}.hljs-built_in,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-type{color:#e78c45}.hljs-attribute{color:#e7c547}.hljs-addition,.hljs-bullet,.hljs-string,.hljs-symbol{color:#b9ca4a}.hljs-section,.hljs-title{color:#7aa6da}.hljs-keyword,.hljs-selector-tag{color:#c397d8}.hljs{color:#eaeaea}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}`);

let code = document.querySelector("#code code");
let codeMark = document.querySelector("#code mark");
let userCss = document.getElementById("install").href;

highlight();

if (codeMark) {
	codeMark.innerHTML += `<a id="fullcode" style="margin: 0 5px;cursor: pointer;font-weight: bold"> Load full code</a>`
	document.getElementById("fullcode").onclick = () => fullUserCss();
}

function highlight() {
	if (/@preprocessor\s+stylus/.test(code.innerText)) {
		code.classList.add("language-stylus");
	} else if (/@preprocessor\s+less/.test(code.innerText)) {
		code.classList.add("language-less");
	} else {
		code.classList.add("language-css");
	}
	hljs.highlightAll();
}

async function fullUserCss() {
	const response = await fetch(userCss);
	const css = await response.text();
	code.innerHTML = css;
	codeMark.remove();
	highlight();
}

})();