Skip to content

Instantly share code, notes, and snippets.

@bmwalters
Last active August 30, 2016 23:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmwalters/6d4cc5499378711de0f46028e565cc8d to your computer and use it in GitHub Desktop.
Save bmwalters/6d4cc5499378711de0f46028e565cc8d to your computer and use it in GitHub Desktop.
Get the power of the GLua Wiki Tokenizer in your Facepunch [lua] tags!
// ==UserScript==
// @name Facepunch GLua Wiki Tokenizer
// @namespace zerf
// @description Get the power of the GLua Wiki Tokenizer in your Facepunch [lua] tags!
// @version 1.5
// @include https://facepunch.com/showthread.php*
// @downloadURL https://gist.github.com/bmwalters/6d4cc5499378711de0f46028e565cc8d/raw/master/Facepunch_GLua_Wiki_Tokenizer.user.js
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js
// @run-at document-start
// @grant GM_xmlhttpRequest
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);
var css = `<style>
pre {
margin:2em;
border:none;
font-size:12px;
background-color:#444;
border-radius:3px;
padding:8px;
overflow:auto;
color:#aaa;
}
pre .keyword {
color:#afa;
}
pre .operator,pre .identifier {
color:#ddd;
}
pre .function {
color:#adf;
}
pre .string {
color:#ffa;
}
pre .number {
color:#fff;
}
pre .constant {
color:#fd5;
}
pre .escape {
color:#f96;
}
pre .comment {
color:#3a3;
}
pre .error {
background-color:red;
color:yellow;
}
pre a {
font-weight:bold;
color:#adf;
text-decoration:none !important;
}
pre a:hover {
color:#adf;
text-decoration-color:#adf;
text-decoration:underline !important;
}
code {
display:block;
font-size:12px;
background-color:#444;
border-radius:3px;
padding:8px;
overflow:auto;
color:#ddd;
white-space:pre;
}
</style>`;
var forumDetectionRe = /<link rel="alternate" type="application\/rss\+xml" title=".+?" href="https:\/\/facepunch\.com\/external\.php\?type=RSS2&amp;forumids=(\d\d?\d?)">/;
window.addEventListener("beforescriptexecute", function(e) {
if (e.target.src.indexOf("rainbow-custom.min.js") !== -1) {
var forumId = forumDetectionRe.exec(document.documentElement.innerHTML)[1];
if (forumId && (forumId == 65 || forumId == 15 || forumId == 66)) {
// prevent loading
e.preventDefault();
e.stopPropagation();
}
}
});
var grabGmodJS = function() {
$("<script async>").attr("src", "https://wiki.garrysmod.com/garrysmod/rainbow.min.js").appendTo("head");
GM_xmlhttpRequest({
url: "https://wiki.garrysmod.com/skins/garrysmod/garrysmod.js",
method: "GET",
headers: {
referer: "https://wiki.garrysmod.com",
origin: "https://wiki.garrysmod.com"
},
onload: function(res) {
var code = res.responseText;
var goodStuff = code.substring(code.indexOf("var FUNCTIONS="), code.length);
$("<script>").text(goodStuff).appendTo("head");
}
});
}
document.addEventListener("DOMContentLoaded", function() {
if ($("#breadcrumb").text().trim().indexOf("Garry's Mod") == -1) { return; } // skip forums that aren't GMod
$("body").attr("id", "bodyContent");
$("pre").each(function() {
var $this = $(this);
var code = $this.text();
var $new = $("<pre><code data-language='lua'></code></pre>");
$new.find("code").html(code);
$this.replaceWith($new);
});
grabGmodJS();
$(css).appendTo("head");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment