Oracle Java Documentation Syntax Highlighter

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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);
});