// ==UserScript==
// @name Pure Basic Syntax Highlighting
// @namespace http://www.bhelpuri.net/Trixie
// @description Pure Basic Syntax Highlighting (V 1.6b) (16. Feb 2011) (Update 21. Jun 2013)
// @include http://purebasic.com/german/*
// @include http://purebasic.fr/german/*
// @include http://purebasic.fr/english/*
// @include http://purebasic.fr/french/*
// @include http://www.purebasic.com/german/*
// @include http://www.purebasic.fr/german/*
// @include http://www.purebasic.fr/english/*
// @include http://www.purebasic.fr/french/*
// @include http://forums.purebasic.com/german/*
// @include http://forums.purebasic.com/english/*
// @include http://forums.purebasic.fr/german/*
// @include http://forums.purebasic.fr/english/*
// @include http://forums.purebasic.fr/french/*
// ==/UserScript==
//--------------------------------------------
// Version 1.6b (16. Feb 2011) (Update 21. Jun 2013)
//--------------------------------------------
// Farbdefinition für das Syntax Highlighting
// color definition for the syntax highlighting
//===================================================
var PBSH_Highlight = new Object();
// ==PureBasicPreference==
PBSH_Highlight['EnableKeywordBolding'] = 1;
PBSH_Highlight['EditorFontName'] = 'Courier';
PBSH_Highlight['EditorFontSize'] = '10';
PBSH_Highlight['EditorFontStyle'] = '';
PBSH_Highlight['BackgroundColor'] = '#FFFFFF';
PBSH_Highlight['NormalTextColor'] = '#202020';
PBSH_Highlight['BasicKeywordColor'] = '#000000';
PBSH_Highlight['CommentColor'] = '#808080';
PBSH_Highlight['ConstantColor'] = '#802050';
PBSH_Highlight['StringColor'] = '#205080';
PBSH_Highlight['PureKeywordColor'] = '#508020';
//PBSH_Highlight['ASMKeywordColor'] = '#000000';
//PBSH_Highlight['PointerColor'] = '#000000';
//PBSH_Highlight['NumberColor'] = '#000000';
//PBSH_Highlight['StructureColor'] = '#000000';
//PBSH_Highlight['LabelColor'] = '#000000';
//PBSH_Highlight['OperatorColor'] = '#000000';
//PBSH_Highlight['SeparatorColor'] = '#000000';
// ==/PureBasicPreference==
//===================================================
// UserScript für die Syntaxhervorhebung
// user script for syntax highlighting
//===================================================
// Regulärer Ausdrück für das SyntaxHighlighting
// regular expressions for the syntax lighting
// |( Keyword )|( Comment )|( Constant )|( String )|( Function )|( ASM )|( Pointer )|( Number )|( Structure )|( Label )|( Operator )|( Separator )|
var PBSH_Syntax = /([^\w";\\][ \t]*(?:And|Array|As|Break|CallDebugger|Case|CompilerCase|CompilerDefault|CompilerElse|CompilerEndIf|CompilerEndSelect|CompilerError|CompilerIf|CompilerEndIf|CompilerSelect|CompilerEndSelect|Continue|Data|DataSection|EndDataSection|Debug|DebugLevel|Declare|DeclareCDLL|DeclareDLL|DeclareModule|EndDeclareModule|Default|Define|Dim|DisableASM|DisableDebugger|DisableExplicit|Else|ElseIf|EnableASM|EnableDebugger|EnableExplicit|End|Enumeration|EndEnumeration|Extends|FakeReturn|For|Next|ForEach|Next|ForEver|Global|Gosub|Goto|If|EndIf|Import|EndImport|ImportC|IncludeBinary|IncludeFile|IncludePath|Interface|EndInterface|List|Macro|EndMacro|Map|Module|EndModule|NewList|NewMap|Next|Not|Or|Procedure|EndProcedure|ProcedureC|ProcedureCDLL|ProcedureDLL|ProcedureReturn|Protected|Prototype|PrototypeC|Read|ReDim|Repeat|Until|Restore|Return|Runtime|Select|EndSelect|Shared|Static|Step|Structure|EndStructure|StructureUnion|EndStructureUnion|Swap|Threaded|To|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 ;
// Hervorheben einer Zeichenkette
// highlighting a string
function PBSH_Highlighting(str, key)
{
if (PBSH_Highlight[key])
return ''+str+'';
else
return str;
}
function PBSH_Highlighting_Shift(str, key)
{
if (PBSH_Highlight[key])
{
var chr = str.slice(0,1);
if (PBSH_Highlight['OperatorColor'])
chr = chr.replace(PBSH_Syntax, PBSH_Replace);
else if (PBSH_Highlight['SeparatorColor'])
chr = chr.replace(PBSH_Syntax, PBSH_Replace);
return chr+''+str.slice(1,str.length)+'';
}
else
return str;
}
function PBSH_Highlighting_Keyword(str, key)
{
if (PBSH_Highlight[key])
{
var space = str.lastIndexOf(' ');
if (space==-1) space = 0;
var chr = str.slice(0,space+1);
if (PBSH_Highlight['SeparatorColor'])
chr = chr.replace(PBSH_Syntax, PBSH_Replace);
if (PBSH_Highlight['EnableKeywordBolding'])
return chr+''+str.slice(space+1,str.length)+'';
else
return chr+''+str.slice(space+1,str.length)+'';
}
else
if (PBSH_Highlight['EnableKeywordBolding'])
return ''+str+'';
else
return str;
}
// Ersetzen einer Zeichenkette
// replace a string
function PBSH_Replace(str, isKeyword, isComment, isConstant, isString, isFunction, isASM, isPointer, isNumber, isStructure, isLabel, isOperator, isSeparator)
{
if (isKeyword) return PBSH_Highlighting_Keyword(isKeyword, 'BasicKeywordColor');
else if (isComment) return PBSH_Highlighting(isComment, 'CommentColor');
else if (isConstant) return PBSH_Highlighting(isConstant, 'ConstantColor');
else if (isString) return PBSH_Highlighting(isString, 'StringColor');
else if (isFunction) return PBSH_Highlighting_Shift(isFunction, 'PureKeywordColor');
else if (isASM) return PBSH_Highlighting_Shift(isASM, 'ASMKeywordColor');
else if (isPointer) return PBSH_Highlighting_Shift(isPointer, 'PointerColor');
else if (isNumber) return PBSH_Highlighting_Shift(isNumber, 'NumberColor');
else if (isStructure) return PBSH_Highlighting_Shift(isStructure, 'StructureColor');
else if (isLabel) return PBSH_Highlighting_Shift(isLabel, 'LabelColor');
else if (isOperator) return PBSH_Highlighting(isOperator, 'OperatorColor');
else if (isSeparator) return PBSH_Highlighting(isSeparator, 'SeparatorColor');
}
// Durchführes der Syntaxhervorhebung
// carry out the syntax highlighting
function PureBasicSyntaxHighlighting()
{
// Anwenden der Syntaxhervorhebung auf alle Elemente mit der Klasse codecontent
// apply the syntax highlighting on all the elements with class codecontent
var allMyDivs = document.getElementsByTagName('div');
for(var i = 0; i < allMyDivs.length; i++)
{
if (allMyDivs[i].className == 'codecontent')
{
if (PBSH_Highlight['EditorFontName'])
allMyDivs[i].style.font = PBSH_Highlight['EditorFontStyle']+" "+PBSH_Highlight['EditorFontSize']+"pt "+PBSH_Highlight['EditorFontName'];
if (PBSH_Highlight['BackgroundColor'])
allMyDivs[i].style.backgroundColor = PBSH_Highlight['BackgroundColor'];
if (PBSH_Highlight['NormalTextColor'])
allMyDivs[i].style.color = PBSH_Highlight['NormalTextColor'];
var code = ' '+allMyDivs[i].innerHTML+'\r';
code = code.replace(/
/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, '
');
allMyDivs[i].innerHTML = code;
}
}
}
PureBasicSyntaxHighlighting();
//===================================================