by Ragnar » 26 Nov 2022, 10:33
It is also possible to use the syntax highlighter from the docs, which is far more accurate and pretty than the default highlighter used in these forums.
Currently I use the following userscript:
Code: Select all
// ==UserScript==
// @name AutoHotkey Forum Codebox Highlighting
// @namespace https://*.autohotkey.com/board*
// @version 0.1
// @description Use custom syntax highlighter
// @author Ragnar-F
// @match https://*.autohotkey.com/board*
// ==/UserScript==
h2_a = document.querySelector('h2 a');
isV2 = (location.href.match(/f=(82|83|37|92)/) || (h2_a && h2_a.href.match(/f=(82|83|37|92)/))) || false; // forum id is sometimes not always present in the url
unsafeWindow.forceNoScript = true;
var css = '.codebox{border-color:transparent;}*{scrollbar-base-color: #252525;scrollbar-face-color: #4b4b4b;scrollbar-3dlight-color: #252525;scrollbar-highlight-color: #252525;scrollbar-track-color: #252525;scrollbar-arrow-color: #4b4b4b;scrollbar-shadow-color: #252525;}::-webkit-scrollbar{background-color: #252525;}::-webkit-scrollbar-track{background-color: #252525;}::-webkit-scrollbar-thumb{background-color: #4b4b4b;border: 2px solid #252525;}::-webkit-scrollbar-thumb:hover{background-color: #5f5f5f;}::-webkit-scrollbar-corner{background-color: inherit;}::-ms-expand{background-color: #1e1e1e;color: #4b4b4b;border-color: #252525;}code,pre{font-family:Consolas!important;font-size:14px!important;tab-size:4;color:#d5d5d5!important;background-color:#2e2e2e!important;}code span>a,code span>a:hover,code span>a:link,pre span>a,pre span>a:hover,pre span>a:link{color:inherit!important}code>.bif,code>.cmd,pre>.bif,pre>.cmd{color:#569cd6}code>.met,pre>.met{color:#60c5dc}code>.cfs,code>.dec,pre>.cfs,pre>.dec{color:#c586c0}code>.str,pre>.str{color:#ce9178}code .str>.esc,pre .str>.esc{color:#ff6868}pre>.biv,pre>.cls,code>.biv,code>.cls{color:#4ec9b0}code>.dir,pre>.dir{color:#dcdcaa}code>.fun,code>.lab,pre>.fun,pre>.lab{font-weight:normal;color:#dcdcaa}code>.num,pre>.num{color:#b5cea8}code em,code .cmt,pre.origin em,pre .cmt{color:#6a9955!important}';
//var css = 'code,pre { font-family: Consolas !important; font-size: 14px !important; tab-size: 4; color: #000 !important; background-color: #eff0f1 !important;}code span>a,code span>a:hover,code span>a:link,pre span>a,pre span>a:hover,pre span>a:link { color: inherit !important}code>.bif,code>.cmd,pre>.bif,pre>.cmd { color: #0148c2}code>.met,pre>.met { color: #097f9a}code>.cfs,code>.dec,pre>.cfs,pre>.dec { color: #6F008A}code>.str,pre>.str { color: #A31515}code .str>.esc,pre .str>.esc { color: #FF0000}pre>.biv,pre>.cls,code>.biv,code>.cls { color: #006400}code>.dir,pre>.dir { color: green}code>.fun,code>.lab,pre>.fun,pre>.lab { font-weight: bold; color: #290e90}code>.num,pre>.num { color: #1a6c4e}code em,code .cmt,pre.origin em,pre .cmt { color: #708090 !important}';
addGlobalStyle(css);
if (isV2)
{
scriptDir = 'https://www.autohotkey.com/docs/v2/static';
loadScript(scriptDir + '/content.js', function() {
var pres = document.querySelectorAll("code.lang-autohotkey, pre.prettyprint");
// unsafeWindow.features.addCodeBoxButtons(pres);
unsafeWindow.features.addSyntaxColors(pres);
});
}
else
{
scriptDir = 'https://www.autohotkey.com/docs/v1/static';
loadScript(scriptDir + '/content.js', function() {
var pres = document.querySelectorAll("code.lang-autohotkey, pre.prettyprint");
// unsafeWindow.features.addCodeBoxButtons(pres);
unsafeWindow.features.addSyntaxColors(pres);
});
}
function loadScript(url, callback) {
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState){ // IE
script.onreadystatechange = function() {
if (script.readyState == "loaded" ||
script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else { // Others
script.onload = function() {
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
and blocked the default highlighter script with an adblocker (ublock) using the filter:
Code: Select all
||www.autohotkey.com/boards/assets/prism/prism.js$script,domain=www.autohotkey.com
Theoretically, this could also be natively integrated into the forum.
Example: new vs. old
- image.png (5.11 KiB) Viewed 5368 times
- image.png (7.19 KiB) Viewed 5368 times
It is also possible to use the syntax highlighter from the docs, which is far more accurate and pretty than the default highlighter used in these forums.
Currently I use the following userscript:
[Codebox=javascript file=Untitled.js]// ==UserScript==
// @name AutoHotkey Forum Codebox Highlighting
// @namespace https://*.autohotkey.com/board*
// @version 0.1
// @description Use custom syntax highlighter
// @author Ragnar-F
// @match https://*.autohotkey.com/board*
// ==/UserScript==
h2_a = document.querySelector('h2 a');
isV2 = (location.href.match(/f=(82|83|37|92)/) || (h2_a && h2_a.href.match(/f=(82|83|37|92)/))) || false; // forum id is sometimes not always present in the url
unsafeWindow.forceNoScript = true;
var css = '.codebox{border-color:transparent;}*{scrollbar-base-color: #252525;scrollbar-face-color: #4b4b4b;scrollbar-3dlight-color: #252525;scrollbar-highlight-color: #252525;scrollbar-track-color: #252525;scrollbar-arrow-color: #4b4b4b;scrollbar-shadow-color: #252525;}::-webkit-scrollbar{background-color: #252525;}::-webkit-scrollbar-track{background-color: #252525;}::-webkit-scrollbar-thumb{background-color: #4b4b4b;border: 2px solid #252525;}::-webkit-scrollbar-thumb:hover{background-color: #5f5f5f;}::-webkit-scrollbar-corner{background-color: inherit;}::-ms-expand{background-color: #1e1e1e;color: #4b4b4b;border-color: #252525;}code,pre{font-family:Consolas!important;font-size:14px!important;tab-size:4;color:#d5d5d5!important;background-color:#2e2e2e!important;}code span>a,code span>a:hover,code span>a:link,pre span>a,pre span>a:hover,pre span>a:link{color:inherit!important}code>.bif,code>.cmd,pre>.bif,pre>.cmd{color:#569cd6}code>.met,pre>.met{color:#60c5dc}code>.cfs,code>.dec,pre>.cfs,pre>.dec{color:#c586c0}code>.str,pre>.str{color:#ce9178}code .str>.esc,pre .str>.esc{color:#ff6868}pre>.biv,pre>.cls,code>.biv,code>.cls{color:#4ec9b0}code>.dir,pre>.dir{color:#dcdcaa}code>.fun,code>.lab,pre>.fun,pre>.lab{font-weight:normal;color:#dcdcaa}code>.num,pre>.num{color:#b5cea8}code em,code .cmt,pre.origin em,pre .cmt{color:#6a9955!important}';
//var css = 'code,pre { font-family: Consolas !important; font-size: 14px !important; tab-size: 4; color: #000 !important; background-color: #eff0f1 !important;}code span>a,code span>a:hover,code span>a:link,pre span>a,pre span>a:hover,pre span>a:link { color: inherit !important}code>.bif,code>.cmd,pre>.bif,pre>.cmd { color: #0148c2}code>.met,pre>.met { color: #097f9a}code>.cfs,code>.dec,pre>.cfs,pre>.dec { color: #6F008A}code>.str,pre>.str { color: #A31515}code .str>.esc,pre .str>.esc { color: #FF0000}pre>.biv,pre>.cls,code>.biv,code>.cls { color: #006400}code>.dir,pre>.dir { color: green}code>.fun,code>.lab,pre>.fun,pre>.lab { font-weight: bold; color: #290e90}code>.num,pre>.num { color: #1a6c4e}code em,code .cmt,pre.origin em,pre .cmt { color: #708090 !important}';
addGlobalStyle(css);
if (isV2)
{
scriptDir = 'https://www.autohotkey.com/docs/v2/static';
loadScript(scriptDir + '/content.js', function() {
var pres = document.querySelectorAll("code.lang-autohotkey, pre.prettyprint");
// unsafeWindow.features.addCodeBoxButtons(pres);
unsafeWindow.features.addSyntaxColors(pres);
});
}
else
{
scriptDir = 'https://www.autohotkey.com/docs/v1/static';
loadScript(scriptDir + '/content.js', function() {
var pres = document.querySelectorAll("code.lang-autohotkey, pre.prettyprint");
// unsafeWindow.features.addCodeBoxButtons(pres);
unsafeWindow.features.addSyntaxColors(pres);
});
}
function loadScript(url, callback) {
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState){ // IE
script.onreadystatechange = function() {
if (script.readyState == "loaded" ||
script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else { // Others
script.onload = function() {
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}[/Codebox]
and blocked the default highlighter script with an adblocker (ublock) using the filter:
[Codebox=text file=Untitled.txt]||www.autohotkey.com/boards/assets/prism/prism.js$script,domain=www.autohotkey.com[/Codebox]
Theoretically, this could also be natively integrated into the forum.
Example: new vs. old
[attachment=0]image.png[/attachment]
[attachment=1]image.png[/attachment]