Oracle Java Documentation Syntax Highlighter

4/25/2022, 11:46:18 PM

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Oracle Java Documentation Syntax Highlighter
// @namespace   Violentmonkey Scripts
// @match       *://docs.oracle.com/javase/tutorial/*
// @grant       GM_addStyle
// @grant       GM_getResourceText
// @require     https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/prism.min.js
// @require     https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/components/prism-java.min.js
// @resource    prismCSS https://cdn.jsdelivr.net/npm/[email protected]/themes/prism.min.css
// @version     1.0
// @author      tcharts-boop
// @license     MIT
// @description 4/25/2022, 11:46:18 PM
// ==/UserScript==

/* Source Code */

const css = GM_getResourceText("prismCSS");
GM_addStyle(css);

let codeBlockClassElements = document.querySelectorAll('.codeblock');

codeBlockClassElements.forEach(e => {

    if (e.tagName !== 'PRE') {
        e = e.querySelector('pre');
    }

    codeText = e.textContent;
    e.textContent = '';

    codeElement = document.createElement('code');
    codeElement.textContent = codeText;
    codeElement.classList.add('language-java');

    e.appendChild(codeElement);
});