UserScript • PB-SyntaxHighlighting for codes in the forum

For everything that's not in any way related to PureBasic. General chat etc...
AZJIO
Addict
Addict
Posts: 1298
Joined: Sun May 14, 2017 1:48 am

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by AZJIO »

Why I have not seen this topic before? I tried to use highlight.js, but part of the code had a crash when the code highlight.

I used my colors:

Code: Select all

// ==PureBasicPreference==

PBSH_Highlight.EnableKeywordBolding = 0;
PBSH_Highlight.TabLength = 4;
PBSH_Highlight.CustomKeywords = '';
PBSH_Highlight.EditorFontName = 'Consolas';
PBSH_Highlight.EditorFontSize = '10';
PBSH_Highlight.EditorFontStyle = '';
PBSH_Highlight.BackgroundColor = '#3f3f3f';
PBSH_Highlight.NormalTextColor = '#C0AD72';
PBSH_Highlight.BasicKeywordColor = '#0099ff';
PBSH_Highlight.CommentColor = '#71AE71';
PBSH_Highlight.ConstantColor = '#D998DE';
PBSH_Highlight.StringColor = '#aaaaaa';
PBSH_Highlight.PureKeywordColor = '#AAA6DB';
PBSH_Highlight.ASMKeywordColor = '#C98BFE';
PBSH_Highlight.PointerColor = '#F3CF70';
PBSH_Highlight.NumberColor = '#EACA9B';
PBSH_Highlight.StructureColor = '#FFA704';
PBSH_Highlight.LabelColor = '#F3CF70';
PBSH_Highlight.ModuleColor = '#00A8BF';
PBSH_Highlight.OperatorColor = '#FF8080';
PBSH_Highlight.SeparatorColor = '#FF8080';
PBSH_Highlight.CustomKeywordColor = '#C0AD72';

// ==/PureBasicPreference==
1. Can you add regular expressions to highlight WINAPI functions?
2. Can you make ordinary numbers and hexadecimal numbers in different colors?

Here are the regular expressions that I did to highlight the code in Akelpad:

Code: Select all

Variables
([\d_a-zA-Z]+\$)
WinAPI functions with checking bracket
\b([\d_a-zA-Z]+_)(?=\s*\()
hexadecimal
(\$[\dA-Fa-f]++)
Internal procedures with checking bracket 
\b([a-zA-Z][\d_a-zA-Z]*(?!_))(?=\s*\()
Pointers 
([*@][\d_a-zA-Z]++)
Constants 
(#[\d_a-zA-Z]++)
Types
(\.[sfdqbliwcapu]\b)
String constants 
(#[\d_a-zA-Z]+?\$)
Element structure
(?<!\.\:)\\[\d_a-zA-Z]+"
Variables with type 
(?<![\n\t])\b([\d_a-zA-Z]+)(\.[sfdqbliwcapu])\b
Variables ending with symbols  ,)=
\b([a-zA-Z][\d_a-zA-Z]*)(?=\s*[,\)=])
Can you make the script more versatile?
1. At the beginning of the script add a variable that means the name of the tag. tagname = "code" (tagname = "pre")
2. make dependency table (regex = color):

Code: Select all

arr=[["(;.*$)", C0AD72],	/* Comment */ 
	["(\\#\\w*\\$?|\'.*?(?:\'|$))", D998DE],	/* Constant */ 
	["(~"(?:\\\\.|[^\\\\])*?(?:"|$)|"[^"]*?(?:"|$))", aaaaaa]];	/* String */ 
I myself would like to add what needs to be highlighted
Last edited by AZJIO on Fri May 21, 2021 11:44 am, edited 1 time in total.
User avatar
STARGÅTE
Addict
Addict
Posts: 2063
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by STARGÅTE »

AZJIO wrote: Tue May 11, 2021 5:51 am1. Can you add regular expressions to highlight WINAPI functions?
2. Can you make ordinary numbers and hexadecimal numbers in different colors?
It is possible to add such differentiation, but it is not a part of the Pure Basic IDE highlighting, so why?
AZJIO wrote: Tue May 11, 2021 5:51 am Can you make the script more versatile?
1. At the beginning of the script add a variable that means the name of the tag. tagname = "code" (tagname = "pre")
2. make dependency table (regex = color):
It was not my concept to create a more "general" syntax highlighting script. It is also not as easy as it looks like, to add just an regex and a corresponding color for format a code block. Many style only work well, when they are defined in the right order.
You can see this dependency when you check the regex for a pointer, it refers to a backreference of a keyword.

I can write such script for you, but I will write a new one, not updating the existing one.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
ChrisR
Addict
Addict
Posts: 1124
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by ChrisR »

I recently found it and I adopted it.
It's really useful for reading codes in the forum, thanks for sharing :)
Fred
Administrator
Administrator
Posts: 16581
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by Fred »

Yes, just installed it and works very well. Nice !
AZJIO
Addict
Addict
Posts: 1298
Joined: Sun May 14, 2017 1:48 am

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by AZJIO »

STARGÅTE wrote: Tue May 11, 2021 5:51 pm It is also not as easy as it looks like, to add just an regex and a corresponding color for format a code block. Many style only work well, when they are defined in the right order.
You can see this dependency when you check the regex for a pointer, it refers to a backreference of a keyword.
I've done code highlighting many times, for example: "Converter CMD to BBcode", HighLight_HSB.js, Notepad++ plugin HighLight, pb.coder (PureBasic + AkelPad)
An engine based on regular expressions is important to me, so that I can connect to any site using its theme.
It is necessary for each regular expression to go through the text of the code from beginning to end.
AZJIO
Addict
Addict
Posts: 1298
Joined: Sun May 14, 2017 1:48 am

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by AZJIO »

Uncommented all styles. StructureColor highlights "stru.Structure" and "stru\field" equally. In AkelPad I made different colors (declaration and use). They are commented out, but not excluded from the regular expression.

Variable type highlighting
Image
User avatar
STARGÅTE
Addict
Addict
Posts: 2063
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by STARGÅTE »

Update 2.0.3:
- Fixed: remove yellow border
- Fixed: remove shadow from server script
- Optional: remove max height.

Code: Select all

// ==UserScript==
// @run-at document-idle
// @namespace     STARGÅTE
// @name          Pure Basic Syntax Highlighting
// @description   Pure Basic Syntax Highlighting (V 2.0.3) (03. June 2021)
// @include       https://purebasic.com/german/*
// @include       https://purebasic.fr/german/*
// @include       https://purebasic.fr/english/*
// @include       https://purebasic.fr/french/*
// @include       https://www.purebasic.com/german/*
// @include       https://www.purebasic.fr/german/*
// @include       https://www.purebasic.fr/english/*
// @include       https://www.purebasic.fr/french/*
// @include       https://forums.purebasic.com/german/*
// @include       https://forums.purebasic.com/english/*
// @include       https://forums.purebasic.fr/german/*
// @include       https://forums.purebasic.fr/english/*
// @include       https://forums.purebasic.fr/french/*
// ==/UserScript==



//--------------------------------------------
// Version 2.0.3 (03. June 2021)
//--------------------------------------------



// Farbdefinition für das Syntax Highlighting
// color definition for the syntax highlighting
//===================================================

var PBSH_Highlight = new Object();

// ==PureBasicPreference==

PBSH_Highlight.EnableKeywordBolding = 1;
PBSH_Highlight.TabLength = 2;
PBSH_Highlight.CustomKeywords = '';
PBSH_Highlight.EditorFontName = 'Consolas';
PBSH_Highlight.EditorFontSize = '10';
PBSH_Highlight.EditorFontStyle = '';
PBSH_Highlight.BackgroundColor = '#101010';
PBSH_Highlight.NormalTextColor = '#A0A0A0';
PBSH_Highlight.BasicKeywordColor = '#5090D0';
PBSH_Highlight.CommentColor = '#C04040';
PBSH_Highlight.ConstantColor = '#FFD000';
PBSH_Highlight.StringColor = '#FFFFFF';
PBSH_Highlight.PureKeywordColor = '#80C040';
PBSH_Highlight.ASMKeywordColor = '#A0A040';
//PBSH_Highlight.PointerColor = '#ADE4B5';
PBSH_Highlight.NumberColor = '#C0C0C0';
//PBSH_Highlight.StructureColor = '#006090';
PBSH_Highlight.LabelColor = '#C080FF';
PBSH_Highlight.ModuleColor = '#208000';
PBSH_Highlight.OperatorColor = '#FFFFFF';
//PBSH_Highlight.SeparatorColor = '#FFFFFF';
PBSH_Highlight.CustomKeywordColor = '#3060E0';

// ==/PureBasicPreference==

//===================================================







// UserScript für die Syntaxhervorhebung
// user script for syntax highlighting
//===================================================

// Regulärer Ausdruck für das SyntaxHighlighting
// regular expressions for the syntax lighting
if (PBSH_Highlight.CustomKeywords == '') PBSH_Highlight.CustomKeywords = 'NoCustomKeywordsDefined';
var PBSH_Syntax = new RegExp(
    /*Comment*/       '(;.*$)|' +
    /*Constant*/      '(\\#\\w*\\$?|\'.*?(?:\'|$))|' +
    /*String*/        '(~"(?:\\\\.|[^\\\\])*?(?:"|$)|"[^"]*?(?:"|$))|' +
    /*CustomKeyword*/ '((?:^[ \\t]+|\\b)(?:'+PBSH_Highlight.CustomKeywords+')\\b)|' +
    /*Keyword*/       '((?:^[ \\t]+|\\b)(?:And|Array|As|Break|CallDebugger|Case|CompilerCase|CompilerDefault|CompilerElse|CompilerElseIf|CompilerEndIf|CompilerEndSelect|CompilerError|CompilerIf|CompilerSelect|CompilerWarning|Continue|Data|DataSection|EndDataSection|Debug|DebugLevel|Declare|DeclareC|DeclareCDLL|DeclareDLL|DeclareModule|EndDeclareModule|Default|Define|Dim|DisableASM|DisableDebugger|DisableExplicit|Else|ElseIf|EnableASM|EnableDebugger|EnableExplicit|End|Enumeration|EnumerationBinary|EndEnumeration|FakeReturn|For|ForEach|ForEver|Global|Gosub|Goto|If|EndIf|Import|EndImport|ImportC|IncludeBinary|IncludeFile|IncludePath|Interface|EndInterface|List|Macro|EndMacro|MacroExpandedCount|Map|Module|EndModule|NewList|NewMap|Next|Not|Or|Procedure|EndProcedure|ProcedureC|ProcedureCDLL|ProcedureDLL|ProcedureReturn|Protected|Prototype|PrototypeC|Read|ReDim|Repeat|Restore|Return|Runtime|Select|EndSelect|Shared|Static|Step|Structure|EndStructure|StructureUnion|EndStructureUnion|Swap|Threaded|To|UndefineMacro|Until|UseModule|UnuseModule|Wend|While|With|EndWith|XIncludeFile|XOr)\\b|\\b[ \\t]+(?:Align|Extends)\\b)|' +
    /*Structure*/     '((?<=\\.)[ \\t]*(?:[^\\Wabcdfilqsuw](?=\\b)|\\w\\w+)|(?<=\\\\)\\w+\\$?[ \\t]*(?![\\w\\( \\t]))|' +
    /*Function*/      '(\\w+\\$?(?=(?:[ \\t]*\\.[ \\t]*\\w+[ \\t]*|[ \\t]*)\\())|' +
    /*ASM*/           '(^[ \\t]*!.*?(?:$|(?=(?<!&gt|&lt|&amp);)))|' +
    /*Pointer*/       '(\\@\\*?[\\w\\$]*|(?:(?<![ \\t\\w$)}\\]])|(?<=\\5))[ \\t]*\\*[\\w\\$]+|\\?\\w*)|' +
    /*Number*/        '((?:\\b\\d+\\.?\\d*(?:e[+\\-]?\\d+)?|\\$[\\dabcdef]+|\\%[01]+))|' +
    /*Module*/        '(\\w+(?=[ \\t]*::))|' +
    /*Label*/         '(^[ \\t]*\\w+\\$?[ \\t]*:(?!:))|' +
    /*Operator*/      '((?:[+*/\\-|!%=~]|::|&gt;|&lt;|&amp;)+)|' +
    /*Seperator*/     '([()\\[\\]\\\\,.:])',
    'gim');

// Hervorheben einer Zeichenkette
// highlighting a string
function PBSH_Highlighting(str, key)
{
    if (PBSH_Highlight[key])
        return '<font color="'+PBSH_Highlight[key]+'">'+str+'</font>';
    else
        return str;
}
function PBSH_Highlighting_Keyword(str, key)
{
    if (PBSH_Highlight[key])
    {
        if (PBSH_Highlight.EnableKeywordBolding)
            return '<font color="'+PBSH_Highlight[key]+'"><b>'+str+'</b></font>';
        else
            return '<font color="'+PBSH_Highlight[key]+'">'+str+'</font>';
    }
    else
        if (PBSH_Highlight.EnableKeywordBolding)
            return '<b>'+str+'</b>';
    else
        return str;
}

// Ersetzen einer Zeichenkette
// replace a string
function PBSH_Replace(str, isComment, isConstant, isString, isCustomKeyword, isKeyword, isStructure, isFunction, isASM, isPointer, isNumber, isModule, isLabel, isOperator, isSeparator)
{
    if (isCustomKeyword)  return PBSH_Highlighting_Keyword(isCustomKeyword, 'CustomKeywordColor');
    else 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(isFunction, 'PureKeywordColor');
    else if (isASM)       return PBSH_Highlighting(isASM, 'ASMKeywordColor');
    else if (isPointer)   return PBSH_Highlighting(isPointer, 'PointerColor');
    else if (isNumber)    return PBSH_Highlighting(isNumber, 'NumberColor');
    else if (isStructure) return PBSH_Highlighting(isStructure, 'StructureColor');
    else if (isModule)    return PBSH_Highlighting(isModule, 'ModuleColor');
    else if (isLabel)     return PBSH_Highlighting(isLabel, 'LabelColor');
    else if (isOperator)  return PBSH_Highlighting(isOperator, 'OperatorColor');
    else if (isSeparator) return PBSH_Highlighting(isSeparator, 'SeparatorColor');
}

// Durchführen der Syntaxhervorhebung
// perform the syntax highlighting
function PureBasicSyntaxHighlighting()
{
    // Anwenden der Syntaxhervorhebung auf alle <code>-Elemente
    // apply the syntax highlighting on all the <code>-elements
    var allMyDivs = document.getElementsByTagName('code');
    for(var i = 0; i < allMyDivs.length; i++)
    {
        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;
        allMyDivs[i].style.tabSize = PBSH_Highlight.TabLength;
        //allMyDivs[i].style.maxHeight = 'none';  // optional to disable the folding of the code block
        allMyDivs[i].style.textShadow = 'none';
        allMyDivs[i].parentNode.style.padding = '0';
        var code = ''+allMyDivs[i].innerHTML+'';
        code = code.replace(/<br>/gi, '\r\n');
        //code = code.replace(/&nbsp;/gi, '\t');
        code = code.replace(/<\/?[^<>]*>/gi, '');
        code = code.replace(PBSH_Syntax, PBSH_Replace);
        //code = code.replace(/\t/gi, '&nbsp;');
        //code = code.replace(/\r\n/gi, '<br>');
        allMyDivs[i].innerHTML = code;
    }
}

PureBasicSyntaxHighlighting();

//===================================================
And as usually the PB script to set the PB-IDE design:

Code: Select all

EnableExplicit

Procedure.s HTMLColor(Color)
	ProcedureReturn "#"+RSet(Hex(Red(Color)),2,"0")+RSet(Hex(Green(Color)),2,"0")+RSet(Hex(Blue(Color)),2,"0")
EndProcedure

Procedure Export(PreferencesFileName.s)
	Protected Keyword.s, String.s, CustomKeywords.s
	If OpenPreferences(PreferencesFileName)
		PreferenceGroup("Global")
		Debug "PBSH_Highlight.EnableKeywordBolding = "+ReadPreferenceString("EnableKeywordBolding", "1")+";"
		Debug "PBSH_Highlight.TabLength = "+ReadPreferenceString("TabLength", "2")+";"
		PreferenceGroup("CustomKeywords")
		If ExaminePreferenceKeys()
			While NextPreferenceKey() 
				If Left(PreferenceKeyName(), 1) = "W"
					If CustomKeywords : CustomKeywords + "|" : EndIf
					CustomKeywords + PreferenceKeyValue()  
				EndIf
			Wend
		EndIf
		Debug "PBSH_Highlight.CustomKeywords = '"+CustomKeywords+"';"
		PreferenceGroup("Editor")
		Restore PreferenceKeys
		Repeat
			Read.s Keyword
			If Keyword
				String = ReplaceString(ReadPreferenceString(Keyword, ""), ",", " ")
				If Right(Keyword, 5) = "Color" : String = HTMLColor(Val(String)) : EndIf
				If ReadPreferenceInteger(Keyword+"_Disabled", 0)
					Debug "//PBSH_Highlight."+Keyword+" = '"+String+"';"
				Else
					Debug "PBSH_Highlight."+Keyword+" = '"+String+"';"
				EndIf
			EndIf  
		Until Keyword = ""
		ProcedureReturn #True
	EndIf
EndProcedure

Define PreferencesFileName.s

If Not Export(GetUserDirectory(#PB_Directory_ProgramData)+"PureBasic\PureBasic.prefs")
	PreferencesFileName = OpenFileRequester("Preference File", GetHomeDirectory(), "PureBasic.prefs", 0)
	Export(PreferencesFileName)
EndIf

DataSection
	PreferenceKeys:
	Data.s "EditorFontName", "EditorFontSize", "EditorFontStyle", "BackgroundColor", "NormalTextColor"
	Data.s "BasicKeywordColor", "CommentColor", "ConstantColor", "StringColor", "PureKeywordColor"
	Data.s "ASMKeywordColor", "PointerColor", "NumberColor", "StructureColor", "LabelColor", "ModuleColor"
	Data.s "OperatorColor", "SeparatorColor", "CustomKeywordColor", ""
EndDataSection
Last edited by STARGÅTE on Sat Jun 05, 2021 1:12 pm, edited 1 time in total.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
ChrisR
Addict
Addict
Posts: 1124
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by ChrisR »

Thanks for the update :)
Remove the shadow from server script removes the blur effect, it's all good also for the yellow border and optional max height.

I have a concern though with the colors, probably related to the overlay of the server script and the userscript !
The colors are good on the French forum but not on the English forum. The server scripts are probably not at the same level.

Also, the syntax is hightlighting with [ code-pb ] [ /code-pb ] tags but not when using default [ code ] [ /code ] tags.
It was working well, before the server script.

Image
User avatar
STARGÅTE
Addict
Addict
Posts: 2063
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by STARGÅTE »

ChrisR wrote: Thu Jun 03, 2021 7:03 pm I have a concern though with the colors, probably related to the overlay of the server script and the userscript !
Strange. Here in my machine (Vivaldi with Tampermonkey) my script is evaluated after the script of the forum, and all colors are overwritten and correct.
Also with both code tags:

Code: Select all

#Constant = "String, #Constants and ; Comments are ignored"

; One Comment, #Constants and "Strings" are ignored

Structure AnyStructure
  Long.l
  *Pointer.AnyStructure
  String$
EndStructure

Procedure AnyProcedure(Parameter1, *Parameter2, Parameter3)

  ! MOV eax, 1
  ProcedureReturn 
EndProcedure

AnyStructureVarible.AnyStructure
AnyStructureVarible\Long = $FF00CC

AnyProcedure(3.14, @AnyProcedure(), 'Abc')

Code: Select all

#Constant = "String, #Constants and ; Comments are ignored"

; One Comment, #Constants and "Strings" are ignored

Structure AnyStructure
  Long.l
  *Pointer.AnyStructure
  String$
EndStructure

Procedure AnyProcedure(Parameter1, *Parameter2, Parameter3)

  ! MOV eax, 1
  ProcedureReturn 
EndProcedure

AnyStructureVarible.AnyStructure
AnyStructureVarible\Long = $FF00CC

AnyProcedure(3.14, @AnyProcedure(), 'Abc')
Image
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
ChrisR
Addict
Addict
Posts: 1124
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by ChrisR »

I use Chrome (mainly because of the integrated Google translate) and ViolentMonkey.
I'll try with Tampermonkey and other browser Vivaldi, Edge.
User avatar
ChrisR
Addict
Addict
Posts: 1124
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by ChrisR »

I just tested it with Tampermonkey
I have a lot of warnings: "eslint: no-multi-spaces - multiples space found before '='."
But it is much better indeed for the colors, conforms with the script :)
And both [ code ] [ code-pb ] are supported.

It was good before the server script with ViolentMonkey but not since it was added.
User avatar
ChrisR
Addict
Addict
Posts: 1124
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by ChrisR »

I also use another useful script, written by AR'S to replace the Home link (already present via the logo) by Active Topics for those who regularly use

English:

Code: Select all

// ==UserScript==
// @namespace     Ar-S
// @name          PB Active Topics
// @description   PB Active Topics
// @version      0.1
// @author       Ar-S
// @include       https://purebasic.fr/english/*
// @include       https://www.purebasic.fr/english/*
// @include       https://forums.purebasic.com/english/*
// @include       https://forums.purebasic.fr/english/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
'use strict';
  
var Lin = document.getElementById("nav-breadcrumbs").getElementsByTagName("a")[0];
Lin.innerText = "Active Topics";
Lin.href = "https://www.purebasic.fr/english/search.php?search_id=active_topics";

})();
French:

Code: Select all

// ==UserScript==
// @namespace     Ar-S
// @name          PB Sujets actifs
// @description   PB Sujets actifs
// @version      0.1
// @author       Ar-S
// @include       https://purebasic.fr/french/*
// @include       https://www.purebasic.fr/french/*
// @include       https://forums.purebasic.fr/french/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
'use strict';
  
var Lin = document.getElementById("nav-breadcrumbs").getElementsByTagName("a")[0];
Lin.innerText = "Sujets actifs";
Lin.href = "https://www.purebasic.fr/french/search.php?search_id=active_topics";

})();
German:

Code: Select all

// ==UserScript==
// @namespace     Ar-S
// @name          PB Aktive Themen
// @description   PB Aktive Themen
// @version      0.1
// @author       Ar-S
// @include       https://purebasic.fr/german/*
// @include       https://www.purebasic.fr/german/*
// @include       https://forums.purebasic.com/german/*
// @include       https://forums.purebasic.fr/german/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
'use strict';
  
var Lin = document.getElementById("nav-breadcrumbs").getElementsByTagName("a")[0];
Lin.innerText = "Aktive Themen";
Lin.href = "https://www.purebasic.fr/german/search.php?search_id=active_topics";

})();
I don't know how to get the 3 forums in 1 script.
User avatar
STARGÅTE
Addict
Addict
Posts: 2063
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by STARGÅTE »

In my case, I just moved the links inside "quick links" right next to the FAQ with this script (which works in all three forums):

Code: Select all

var quickLinksElement = document.getElementById('quick-links');
var dropDownDiv = quickLinksElement.getElementsByTagName('div')[0];
var quickLinksLi = dropDownDiv.getElementsByTagName('li');
for (var i = 0; i<quickLinksLi.length; i++) {
    var linkElements = quickLinksLi[i].getElementsByTagName('a');
    if (linkElements.length > 0 && linkElements[0].getAttribute('href') && (linkElements[0].getAttribute('href').search('active_topics')>=0 || linkElements[0].getAttribute('href').search('unreadposts')>=0)) {
        var clone = quickLinksLi[i].cloneNode(true);
        var navBar = document.getElementById('nav-main');
        navBar.appendChild(clone);
    }
}
Image
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
ChrisR
Addict
Addict
Posts: 1124
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by ChrisR »

Great, thanks for the AIO, 3in1 :)
However, I will probably keep the replacement of the Home button which has no use there and is already present with the logo link.
Finally no, it is very good as you have done next to the FAQ. I just need to stop clicking on Home.
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: UserScript • PB-SyntaxHighlighting for codes in the forum

Post by Sicro »

@ChrisR: In my case, that helps:

Code: Select all

// ==UserScript==
// @run-at document-idle
See: https://violentmonkey.github.io/api/metadata-block/#run-at
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
Post Reply