Page 2 of 5
Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Tue Feb 22, 2011 7:15 pm
by ts-soft
skywalk wrote:Hey, I have a dumb question...
Is there a way to select the Code portion of a post without having to manually select everything?
I see buttons for this in other forums, just curious why it is not available on a coder's forum?
Download this:
http://www.realsource.de/index.php/down ... codefolder
Install only the "CodeFold for PureBasic Forum".
Or use this:
Code: Select all
// ==UserScript==
// @name CodeFold for PureBasic Forums
// @description CodeFold
// @include http://purebasic.fr/*
// @include http://www.purebasic.fr/*
// @include http://purebasic.com/*
// @include http://www.purebasic.com/*
// @include http://forums.purebasic.fr/*
// ==/UserScript==
var hoch = "95px";
var select = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAMAAABIK2QJAAAAB3RJTUUH2AYGEg8u3H74gAAAABd0RVh0U29mdHdhcmUAR0xEUE5HIHZlciAzLjRxhaThAAAACHRwTkdHTEQzAAAAAEqAKR8AAAAEZ0FNQQAAsY8L/GEFAAADAFBMVEVFRUWAAAAAgACAgAAAAICAAIAAgIDAwMDA3MCmyvAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/+/CgoKSAgID/AAAA/wD//wAAAP//AP8A//////+NCwMjAAAAAWJLR0T/pQfyxQAAADZJREFUeJyNjEEKADAMwvz/h+fNWdeOHRekSJCCjSTUMUT6MqKQLqdm4zM7PrP2t+fRvx+Ihw1yH39YLwn1QAAAAABJRU5ErkJggg==";
var minus = "data:image/gif;base64,R0lGODlhCgAKAKIAADMzM//M/93d3WZmZv///wAAAAAAAAAAACH5BAEHAAEALAAAAAAKAAoAAAMVGLrc/mrISQe5+ErBOx9AKI5QaS4JADs=";
var plus = "data:image/gif;base64,R0lGODlhCgAKAKIAADMzM//M/93d3WZmZv///wAAAAAAAAAAACH5BAEHAAEALAAAAAAKAAoAAAMgGDo8+mEQ4mAUosaGG5sEBjJYWQ5ACmAq8AyddWVy+yQAOw==";
var expandfunc = '\n';
expandfunc += 'function expand_code(img_id)\n';
expandfunc += '{\n';
expandfunc += ' var node = document.getElementById(img_id);\n';
expandfunc += ' node.src = "'+minus+'" ;\n';
expandfunc += ' node.onclick = function() { collapse_code(img_id); };\n';
expandfunc += ' var node = document.getElementById("c"+img_id);\n';
expandfunc += ' node.style.overflow = "visible";\n';
expandfunc += ' node.style.height = "100%";\n';
expandfunc += '}\n';
var collapsefunc = '\n';
collapsefunc += 'function collapse_code(img_id)\n';
collapsefunc += '{\n';
collapsefunc += ' var node = document.getElementById(img_id);\n';
collapsefunc += ' node.src = "'+plus+'" ;\n';
collapsefunc += ' node.onclick = function() { expand_code(img_id); };\n';
collapsefunc += ' var node = document.getElementById("c"+img_id);\n';
collapsefunc += ' node.style.height = "'+hoch+'";\n';
collapsefunc += ' node.style.overflow = "scroll";\n';
collapsefunc += '}\n';
var selectfunc = '\n';
selectfunc += 'function select_code ( img_id )\n';
selectfunc += '{\n';
selectfunc += ' if ( window.getSelection() && window.getSelection().removeAllRanges() ) {\n';
selectfunc += ' window.getSelection().removeAllRanges();\n';
selectfunc += ' }\n';
selectfunc += ' div_id = img_id - 1000;\n';
selectfunc += ' var node = document.getElementById ( "c" + div_id );\n';
selectfunc += ' if ( document.createRange() ){;\n';
selectfunc += ' range = document.createRange();\n';
selectfunc += ' if ( range.selectNode(node) ){;\n';
selectfunc += ' range.selectNode(node);\n';
selectfunc += ' };\n';
selectfunc += ' };\n';
selectfunc += ' if ( window.getSelection() && window.getSelection().addRange( range ) ){\n';
selectfunc += ' window.getSelection().addRange( range );\n';
selectfunc += ' };\n';
selectfunc += '}\n';
var img_id = 0;
var len = document.getElementsByTagName("div").length;
var script;
for (var i = 0;i<len;i++)
{
if (document.getElementsByTagName("div")[i].className == "codetitle")
{
var node = document.getElementsByTagName("div")[i];
var html = node.innerHTML;
var count = 0;
var code = 0;
node.innerHTML = '<b>Code :</b>';
img_id += 1;
select_id = img_id + 1000;
code = node.nextSibling;
if (code.innerHTML.split("<br>").length - 1 >= 10)
{
node.innerHTML += ' <img id="'+ img_id +'" src="'+plus +'" onclick="expand_code('+img_id +')" />';
code.style.height = hoch;
code.style.overflow = "scroll";
}
code.id = "c" + img_id;
node.innerHTML += ' <img id="'+ select_id +'" src="'+select+'" onclick="select_code('+select_id+')" />';
}
}
script = document.createElement( 'script' );
script.innerHTML = expandfunc;
script.innerHTML += collapsefunc;
script.innerHTML += selectfunc;
document.body.appendChild(script);
Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Wed Feb 23, 2011 5:48 am
by skywalk
STARGÅTE wrote:triple click in the Code-Area (for IE)
Ah, I am using Chrome. Always seems last to the party
@ts-soft, Thanks, I will give your code a try...
Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Wed Feb 23, 2011 6:40 am
by skywalk
Thanks ts-soft!
Wow, what a timesaver. This should be default on the forum.
Question?
I don't know javascript.
How to edit the "rs.pbf.codefold.user.js" script to copy the selection directly to the ClipBoard?
I did a web search and it seems a bit complicated.
Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Wed Feb 23, 2011 3:37 pm
by ts-soft
skywalk wrote:How to edit the "rs.pbf.codefold.user.js" script to copy the selection directly to the ClipBoard?
This is a security risk and not supported

Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Sat Mar 05, 2011 5:56 pm
by Nituvious
This is very cool! Thank you!
In a later version, could it be possible to change the coloring system so we can just paste our color preferences from the IDE into the script?
Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Sat Mar 05, 2011 6:14 pm
by c4s
Nituvious wrote:This is very cool! Thank you!
In a later version, could it be possible to change the coloring system so we can just paste our color preferences from the IDE into the script?
Run the second code and you'll get your color settings of the IDE. Then just copy the result into the script file (edit it with rightclick in the script manager).
Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Tue Feb 26, 2013 10:22 am
by flaith
Hi guys, just an update because of the new keywords
I modified the file in greasemonkey, here is the part to be changed in the file
pure_basic_syntax_highli.user.js :
var PBSH_Syntax = /([^\w";\\][ \t]*(?:Align|And|Array|As|Break|CallDebugger|Case|CompilerCase|CompilerDefault|CompilerElse|CompilerElseIf|CompilerEndIf|CompilerEndSelect|CompilerError|CompilerIf|CompilerEndIf|CompilerSelect|CompilerEndSelect|Continue|Data|DataSection|EndDataSection|Debug|DebugLevel|Declare|DeclareC|DeclareCDLL|DeclareDLL|Default|Define|Dim|DisableASM|DisableDebugger|DisableExplicit|Else|ElseIf|EnableASM|EnableDebugger|EnableExplicit|End|EndDataSection|EndEnumeration|EndIf|EndImport|EndInterface|EndMacro|EndProcedure|EndSelect|EndStructure|EndStructureUnion|EndWith|Enumeration|EndEnumeration|Extends|FakeReturn|For|Next|ForEach|Next|ForEver|Global|Gosub|Goto|If|EndIf|Import|EndImport|ImportC|EndImport|IncludeBinary|IncludeFile|IncludePath|Interface|EndInterface|List|Macro|EndMacro|MacroExpandedCount|Map|NewList|NewMap|Next|Not|Or|Procedure|EndProcedure|ProcedureC|EndProcedure|ProcedureCDLL|EndProcedure|ProcedureDLL|EndProcedure|ProcedureReturn|Protected|Prototype|PrototypeC|Read|ReDim|Repeat|Until|Restore|Return|Select|EndSelect|Shared|Static|Step|Structure|EndStructure|StructureUnion|EndStructureUnion|Swap|Threaded|To|UndefineMacro|Until|Wend|While|Wend|With|EndWith|XIncludeFile|XOr)(?!\w))|(;[^\r\n]*(?=[\r\n]))|(\#\w*\$?|'[^'\r\n]*')|("[^"\r\n]*")|([^\w.][ \t]*\w+\$?(?=(?:[ \t]*\.[ \t]*\w+[ \t]*|[ \t]*)\())|([\n][ \t]*![^\r\n;]*(?=[\n\r;]))|(.\@\*?[\w\$]*|[^\w$)\]][ \t]*\*[\w\$]+|.\?\w*)|(\W(?:\d+\.?[e\d]*|\$[\dabcdef]+|\%[01]+)(?!\w))|(\.[ \t]*(?:[^\Wabcdfilqsuw](?!\w)|\w\w+)|\\[ \t]*\w+\$?|\W\w+(?=[ \t]*\\)|\W\w+(?=[ \t]*\.[ \t]*(?:[^\Wabcdfilqsuw]\W|\w\w+)))|([\n][ \t]*\w+\$?(?=[ \t]*:))|([+*/\-|!%=~]|&|<|>)|([()\[\]\\:,.])/gi ;
Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Tue Feb 26, 2013 3:48 pm
by c4s
@flaith
Thank you!
One question though: When I saved the modified source code GreaseMonkey said something about "all scripts should use @grant". Is this important?
Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Tue Feb 26, 2013 4:05 pm
by Bisonte
c4s wrote:One question though: When I saved the modified source code GreaseMonkey said something about "all scripts should use @grant". Is this important?
I add this
before
to prevent this message.
Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Tue Feb 26, 2013 6:26 pm
by helpy
I use a the prosivler style in the forum.
This means that the script does not work, because the html code is different.
I changed the function PureBasicSyntaxHighlighting of the script:
Code: Select all
function PureBasicSyntaxHighlighting()
{
// Anwenden der Syntaxhervorhebung auf alle Elemente mit der Klasse codecontent
// apply the syntax highlighting on all the elements with class codecontent
var allMy_dl = document.getElementsByTagName('dl');
for(var i = 0; i < allMy_dl.length; i++)
{
if (allMy_dl[i].className == 'codebox')
{
var aCodeBox = allMy_dl[i].getElementsByTagName('code')[0];
if (PBSH_Highlight['EditorFontName'])
aCodeBox.style.font = PBSH_Highlight['EditorFontStyle']+" "+PBSH_Highlight['EditorFontSize']+"pt "+PBSH_Highlight['EditorFontName'];
if (PBSH_Highlight['BackgroundColor'])
aCodeBox.style.backgroundColor = PBSH_Highlight['BackgroundColor'];
if (PBSH_Highlight['NormalTextColor'])
aCodeBox.style.color = PBSH_Highlight['NormalTextColor'];
var code = ' '+aCodeBox.innerHTML+'\r';
code = code.replace(/<br>/gi, '\r\n');
code = code.replace(/ /gi, '\t');
code = code.replace(/<\/?[^<>]*>/gi, '');
code = code.replace(PBSH_Syntax, PBSH_Replace);
code = code.replace(/\t/gi, ' ');
code = code.replace(/\r\n/gi, '<br>');
aCodeBox.innerHTML = code;
}
}
}
Here a sample of my highlighting:
Und hier mein geändertes Script:
PureBasic Syntax Highlighting (Fork of
STARGÅTE's script)
cu,
guido
Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Fri Jun 21, 2013 12:57 pm
by c4s
I updated
flaith's code for PB5.20 by adding "DeclareModule", "EndDeclareModule", "EndModule", "Module" and "Runtime". Furthermore I properly sorted the keywords and removed about 20 duplicates:
var PBSH_Syntax = /([^\w";\\][ \t]*(?:Align|And|Array|As|Break|CallDebugger|Case|CompilerCase|CompilerDefault|CompilerElse|CompilerElseIf|CompilerEndIf|CompilerEndSelect|CompilerError|CompilerIf|CompilerSelect|Continue|Data|DataSection|Debug|DebugLevel|Declare|DeclareC|DeclareCDLL|DeclareDLL|DeclareModule|Default|Define|Dim|DisableASM|DisableDebugger|DisableExplicit|Else|ElseIf|EnableASM|EnableDebugger|EnableExplicit|End|EndDataSection|EndDeclareModule|EndEnumeration|EndIf|EndImport|EndInterface|EndMacro|EndModule|EndProcedure|EndSelect|EndStructure|EndStructureUnion|EndWith|Enumeration|Extends|FakeReturn|For|ForEach|ForEver|Global|Gosub|Goto|If|Import|ImportC|IncludeBinary|IncludeFile|IncludePath|Interface|List|Macro|MacroExpandedCount|Map|Module|NewList|NewMap|Next|Not|Or|Procedure|ProcedureC|ProcedureCDLL|ProcedureDLL|ProcedureReturn|Protected|Prototype|PrototypeC|ReDim|Read|Repeat|Restore|Return|Runtime|Select|Shared|Static|Step|Structure|StructureUnion|Swap|Threaded|To|UndefineMacro|Until|UnuseModule|UseModule|Wend|While|With|XIncludeFile|XOr)(?!\w))|(;[^\r\n]*(?=[\r\n]))|(\#\w*\$?|'[^'\r\n]*')|("[^"\r\n]*")|([^\w.][ \t]*\w+\$?(?=(?:[ \t]*\.[ \t]*\w+[ \t]*|[ \t]*)\())|([\n][ \t]*![^\r\n;]*(?=[\n\r;]))|(.\@\*?[\w\$]*|[^\w$)\]][ \t]*\*[\w\$]+|.\?\w*)|(\W(?:\d+\.?[e\d]*|\$[\dabcdef]+|\%[01]+)(?!\w))|(\.[ \t]*(?:[^\Wabcdfilqsuw](?!\w)|\w\w+)|\\[ \t]*\w+\$?|\W\w+(?=[ \t]*\\)|\W\w+(?=[ \t]*\.[ \t]*(?:[^\Wabcdfilqsuw]\W|\w\w+)))|([\n][ \t]*\w+\$?(?=[ \t]*:))|([+*/\-|!%=~]|&|<|>)|([()\[\]\\:,.])/gi ;
edit: Added "UseModule" and "HideModule"
edit2: Renamed "HideModule" to "UnuseModule"
Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Fri Jun 21, 2013 3:37 pm
by Tenaja
ts-soft wrote:With Firefox, if you have installed Greasemonkey, simple download the file. Firefox will prompt for installation.
Ok, so I installed GreaseMonkey (in Firefox), and installed the script. Nothing. I restarted FF. Still none of the code is highlighted. Am I missing something?
Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Fri Jun 21, 2013 3:48 pm
by ts-soft
Here a complete pack of all required script.
Put this files in your gm_scripts dir of the greasemonkey-plugin (in Appdata/Modzilla/...).
It should show you all PB-Sources in blue-style

, PB5.20 is supported.
Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Sun May 03, 2015 11:01 am
by Kwai chang caine
There are a long time, i use this super JS on my chome for select all the code in one clic
http://www.purebasic.fr/english/viewtop ... 96#p347396
Now i try to install it another time and chrome disable it, and say to me contact the developper.
He must inscribe his code in Chrome Web Store for be sure it's not a malware
Decidedly..the more time passes, the more difficult it is to do what you want in my own explorer

Re: UserScript • PB-SyntaxHighlighting for codes in the foru
Posted: Mon May 18, 2015 12:59 pm
by ts-soft
Kwai chang caine wrote:He must inscribe his code in Chrome Web Store for be sure it's not a malware

Then do this, or use firefox.
If no one do this, i can't do this. I haven't chrome installed.