Skip to content

Instantly share code, notes, and snippets.

@rsKliPPy
Last active March 2, 2018 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsKliPPy/31c9ad9426794a34f08270e602c12834 to your computer and use it in GitHub Desktop.
Save rsKliPPy/31c9ad9426794a34f08270e602c12834 to your computer and use it in GitHub Desktop.
ViolentMonkey script that highlights [code] blocks on AlliedModders Forums
// ==UserScript==
// @name AlliedModders Code Highlight
// @description Adds syntax highlight for [code] blocks on AlliedModders Forums
// @namespace github.com/rsKliPPy
// @match https://forums.alliedmods.net/*
// @version 1.0.2
// @downloadURL https://gist.github.com/rsKliPPy/31c9ad9426794a34f08270e602c12834/raw/am-code-highlight.user.js
// @homepageURL https://github.com/rsKliPPy
// @run-at document-end
//
// @resource hljsScript https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js
// @resource hljsStyleSheet https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/vs.min.css
//
// @grant GM_addStyle
// @grant GM_getResourceText
// ==/UserScript==
'use strict';
GM_addStyle(GM_getResourceText('hljsStyleSheet'));
const scriptElement = document.createElement('script');
scriptElement.type = 'text/javascript';
scriptElement.appendChild(document.createTextNode(GM_getResourceText('hljsScript')))
document.body.appendChild(scriptElement);
hljs.configure({
tabReplace: ' ', // 1 tab = 4 spaces
languages: [ 'markdown', 'json', 'xml', 'python', 'cpp' ]
});
window.addEventListener('load', () => {
for(const element of document.querySelectorAll('pre.alt2')) {
hljs.highlightBlock(element);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment