• Hallo liebe Userinnen und User,

    nach bereits längeren Planungen und Vorbereitungen sind wir nun von vBulletin auf Xenforo umgestiegen. Die Umstellung musste leider aufgrund der Serverprobleme der letzten Tage notgedrungen vorverlegt werden. Das neue Forum ist soweit voll funktionsfähig, allerdings sind noch nicht alle der gewohnten Funktionen vorhanden. Nach Möglichkeit werden wir sie in den nächsten Wochen nachrüsten. Dafür sollte es nun einige der Probleme lösen, die wir in den letzten Tagen, Wochen und Monaten hatten. Auch der Server ist nun potenter als bei unserem alten Hoster, wodurch wir nun langfristig den Tank mit Bytes vollgetankt haben.

    Anfangs mag die neue Boardsoftware etwas ungewohnt sein, aber man findet sich recht schnell ein. Wir wissen, dass ihr alle Gewohnheitstiere seid, aber gebt dem neuen Board eine Chance.
    Sollte etwas der neuen oder auch gewohnten Funktionen unklar sein, könnt ihr den "Wo issn da der Button zu"-Thread im Feedback nutzen. Bugs meldet ihr bitte im Bugtracker, es wird sicher welche geben die uns noch nicht aufgefallen sind. Ich werde das dann versuchen, halbwegs im Startbeitrag übersichtlich zu halten, was an Arbeit noch aussteht.

    Neu ist, dass die Boardsoftware deutlich besser für Mobiltelefone und diverse Endgeräte geeignet ist und nun auch im mobilen Style alle Funktionen verfügbar sind. Am Desktop findet ihr oben rechts sowohl den Umschalter zwischen hellem und dunklem Style. Am Handy ist der Hell-/Dunkelschalter am Ende der Seite. Damit sollte zukünftig jeder sein Board so konfigurieren können, wie es ihm am liebsten ist.


    Die restlichen Funktionen sollten eigentlich soweit wie gewohnt funktionieren. Einfach mal ein wenig damit spielen oder bei Unklarheiten im Thread nachfragen. Viel Spaß im ngb 2.0.

[Script] NGB Subload - Themenüberblick von Foren

theSplit

1998
Veteran Barkeeper

Registriert
3 Aug. 2014
Beiträge
28.577
Hallo,

ich habe ein Greasemonkey-Skript (sollte allerdings auch mit Tempermonkey funktionieren) - welches einen Überblick über ein Forum gibt, noch bevor ihr dieses öffnen müsst.
Dabei werden dann unter dem Forumnamen die letzten X (Standardmäßig bis zu 8) Themen mit Informationen angezeigt, die allerdings niemals älter als 90 Tage sind. Seid ihr in einem Forum mit Unterforen, werden dann auch anschließend diese gelistet.

Info: Nach Rücksprache ist das Skript hier okay, aber es verursacht natürlich etwas mehr Load, weil die Foren einmalig geladen werden müssen, wenn sich nichts aktualisiert, kommen sie aus dem Cache (Firefox).

Das ganze funktioniert über Ajax Requests die in Chrome wie auch Firefox unterstützt werden.

Hier einmal ein paar Screenshots des Skripts im Einsatz:

- -

Das Skript hat noch keine Einstellungsoptionen, also es lässt sich noch nicht wirklich steuern. Wir zeigen immer bis zu 8 letzte Themen an.


Updates:
v1.0 : Diese Version
v1.1 : https://ngb.to/threads/29485-Script-NGB-Subload-Themenüberblick-von-Foren?p=793197#post793197
v1.2: https://ngb.to/threads/29485-Script-NGB-Subload-Themenüberblick-von-Foren?p=793751#post793751

v1.2.2:
v1.2.3:
v.1.2.4: https://ngb.to/threads/29485-Script-NGB-Subload-Themenüberblick-von-Foren?p=793896#post793896

v.1.2.5 (Bugfix! + latest): https://ngb.to/threads/29485-Script-NGB-Subload-Themenüberblick-von-Foren?p=794383#post794383

Und hier das Userscript (alt, v1.0):

[src=javascript]// ==UserScript==
// @name NGB Subloader
// @namespace ngb_subload
// @description NGB Subloader
// @include https://ngb.to/
// @include https://ngb.to/forum*
// @version 1
// @grant none
// ==/UserScript==

function loaderChangeStatus(loader) {
loader = loader.target;
if (loader.readyState == 4 && loader.status == 200) {
data = loader.responseText.replace(/\n|\t|\b/g, '');

var threadTitles = data.match(/<a href="[\s\w\b\=\"\\\-\_].*" class="lastpostdate/g);
//console.log(threadTitles);

var threadAuthors = data.match(/<a[\s\w\b].* popupctrl"[\s\w\bäöüÄÖÜ=\"].*<\/a>/g);
//console.log(threadAuthors);

var threadTimes = data.match(/<dd>[\s\w\bäöüÄÖÜ=\"\-\:\.].*<\/span>/g);
var offset = 0;
var htmlData = '<div style="clear: both; display: inline-block; width: 100%; padding: 10px 6px;">';
for (var i = 0; i < threadTimes.length; i++) {
if (threadTimes.match(/\"time\"/) === null) {
threadTimes.splice(i, 1);
i--;
}
}

//console.log(threadTimes);

if (threadTitles.length !== 0) {
var threadUrl = '';
var threadAuthor = '';
var threadAuthorId = 0;
var threadTime = '';
var now = new Date();

for (var x = 0; x < 8; x++) { // Anzahl der Artikel die wir maximal anzeigen lassen wollen, hier 8.
if (offset + x >= threadTitles.length) {
break;
}

threadUrl = threadTitles[x + offset].match(/href="threads[\s\wäöüÄÖÜ\-\\\/\_].*"/) [0];
threadUrl = threadUrl.substring(6, threadUrl.length - 8);
threadAuthor = threadAuthors[x + offset].match(/<strong\>[\s\wäöüÄÖÜ\-\\\\/_].*<\/strong>/) [0];
threadAuthor = threadAuthor.substr(8,threadAuthor.length-17);
threadAuthorId = threadAuthors[x + offset].match(/members\/[0-9].*-/g)[0];
threadAuthorId.substr(7, threadAuthorId.length);
threadTime = threadTimes[x + offset].replace(/<dd>|<span class="time">|<\/span>/g, '');

if (threadTime.indexOf("Heute,") === -1 && threadTime.indexOf("Gestern,") === -1) {
var timeDate = threadTime.match(/[0-9].?/g);
var dateObj = new Date();
dateObj.setDate(parseInt(timeDate[0]));
dateObj.setMonth(parseInt(timeDate[1]));
dateObj.setFullYear(parseInt("20"+timeDate[2]), 10);
dateObj.setHours(parseInt(timeDate[3], 10));
dateObj.setMinutes(parseInt(timeDate[4], 10));
dateObj.setSeconds(0);
dateObj.setMilliseconds(0);

if (dateObj.getTime() < now - (3600000*24*90)) {
offset++;
x--;
continue;
}
}

htmlData += '<a href="https://ngb.to/' + threadUrl + '">' + threadUrl.substring(threadUrl.indexOf('-', 7), threadUrl.indexOf('?', 7)).replace(/quot/g, '').replace(/\-/g, ' ') + '</a>';
htmlData += ' [<a href="https://ngb.to/members/'+threadAuthorId+threadAuthor+'">' + threadAuthor + '</a>, ' + threadTime + ']<br/><br/>';

/*
console.log("----------------------------------------------------------------");
console.log(threadUrl);
console.log(threadAuthor);
console.log(threadTime);
*/
}
loader.parent.innerHTML += htmlData + '</div>';
}
}

return;
}

function ajaxLoader(url, index) {
var loader = new XMLHttpRequest();
loader.addEventListener('readystatechange', loaderChangeStatus);
loader.parent = boardLinks[index].parentNode.parentNode;
loader.open('GET', 'https://ngb.to/' + url.replace("http:\/\/", "https:\/\/"));
loader.send();
return;
}

var boardLinks = document.querySelectorAll('h2.forumtitle');
for (var i = 0; i < boardLinks.length; ++i) {
var hrefLink = boardLinks.innerHTML.match(/href="[\s\w\böäüÖÄÜ\-\_\/\\].*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, i, true);
}
[/src]

Folgende Ideen stehen noch im Raum für das Skript:
- Foren zum laden aktivieren/deaktiveren (Cookie)
- Button um alle dynamischen Inhalte auf Knopfdruck ein bzw. auszubleden (vielleicht verankert im Usermenü (auch in Cookie)
- Button um die Anzeige für ein Forum zu ein- bzw. auszuklappen (auch in Cookie)
 
Zuletzt bearbeitet:

theSplit

1998
Veteran Barkeeper

Registriert
3 Aug. 2014
Beiträge
28.577
  • Thread Starter Thread Starter
  • #2
v1.1:
- die Ansicht wurde nochmal überarbeitet
- jetzt werden wirklich nur noch die Threads angezeigt, die 30 Tage oder jünger sind - alles andere fliegt raus, vorher wurden auch ältere Themen als X Tage angezeigt da der Monat bei 0 in Javascript anfängt
- die Titel der Themen werden nun korrekt ausgelesen

Screenshot:


[src=javascript]
// ==UserScript==
// @name NGB Subloader
// @namespace ngb_subload
// @description NGB Subloader
// @include https://ngb.to/
// @include https://ngb.to/forum*
// @version 1.1
// @grant none
// ==/UserScript==

function loaderChangeStatus(loader) {
loader = loader.target;
if (loader.readyState == 4 && loader.status == 200) {
data = loader.responseText.replace(/\n|\t|\b/g, '');

var threadLinks = data.match(/class="titl.*<\/a>/g);
//console.log(threadLinks);

var threadAuthors = data.match(/<a[\s\w\b].* popupctr.*<\/a>/g);
//console.log(threadAuthors);

var threadTimes = data.match(/<dd>.*<\/span>/g);
for (var i = 0; i < threadTimes.length; i++) {
if (threadTimes.match(/"time"/) === null) {
threadTimes.splice(i, 1);
i--;
}
}

//console.log(threadTimes);

var htmlData = '<div style="clear: both; display: inline-block; width: 100%; padding: 10px 0px;">';


if (threadLinks.length !== 0) {
try {
var threadTitle = "";
var threadUrl = '';
var threadAuthor = '';
var threadAuthorId = 0;
var threadTime = '';
var now = new Date();
var hasContent = false;

var offset = 0;
var offsetUser = Math.abs(threadAuthors.length - threadLinks.length);

for (var x = 0; x < 8; x++) {
if (offset + x + offsetUser == threadAuthors.length || offset + x == threadLinks.length || offset + x == threadTimes.length) {
break;
}

threadTitle = threadLinks[x + offset].match(/">.*<\/a>/g)[0];
threadTitle = threadTitle.substring(2, threadTitle.length-4);
//console.log(threadTitle);
threadUrl = threadLinks[x + offset].match(/href="threads.*"/g)[0];
threadUrl = threadUrl.substr(6, threadUrl.length - 8);
//console.log(threadUrl);
threadAuthor = threadAuthors[x + offset + offsetUser].match(/<strong\>[\s\w\däöüÄÖÜ\-\\\\/_\(\)\[\]].*<\/strong>/g)[0];
threadAuthor = threadAuthor.substring(8,threadAuthor.length-9);
//console.log(threadAuthor);
threadAuthorId = threadAuthors[x + offset].match(/members\/[0-9]*\-/g)[0];
threadAuthorId.substr(7, threadAuthorId.length);
//console.log(threadAuthorId);
threadTime = threadTimes[x + offset].replace(/<dd>|<span class="time">|<\/span>/g, '');
//console.log(threadTime);

if (threadTime.indexOf("Heute,") === -1 && threadTime.indexOf("Gestern,") === -1) {
var timeDate = threadTime.match(/[0-9].?/g);
var dateObj = new Date();
dateObj.setDate(parseInt(timeDate[0]));
dateObj.setMonth(parseInt(timeDate[1])-1);
dateObj.setFullYear(parseInt("20"+timeDate[2]));
dateObj.setHours(parseInt(timeDate[3]));
dateObj.setMinutes(parseInt(timeDate[4]));
dateObj.setSeconds(0);
dateObj.setMilliseconds(0);
if (dateObj.getTime() < now - ((3600 * 1000) * 24 * 30)) { // 30 - Anzahl der Tage die Themen alt sein duerfen
offset++;
x--;
continue;
}
}

htmlData += '<a style="clear: left; float: left;"href="https://ngb.to/' + threadUrl + '">' + threadTitle + '</a>';
htmlData += '<p style="display: block; text-align: right; margin-left: 10%;">[ <a href="https://ngb.to/members/'+threadAuthorId+threadAuthor+'">' + threadAuthor + '</a>, ' + threadTime + ' Uhr ]</p>';
hasContent = true;

/*
console.log("----------------------------------------------------------------");
console.log(threadUrl);
console.log(threadAuthor);
console.log(threadTime);
*/
}

if (hasContent) {
loader.parent.innerHTML += htmlData + '</div>';
}
} catch (error) {
console.log("[ERROR] Error in script: "+ error + ", loader: " + loader.responseURL);
}

}
} else if (loader.readyState == 4) {
console.log("[ERROR] Loader status: " + loader.responseURL + " : (" + loader.status + ") "+ loader.statusText);
}

return;
}

function ajaxLoader(url, index) {
var loader = new XMLHttpRequest();
loader.addEventListener('readystatechange', loaderChangeStatus);
loader.parent = boardLinks[index].parentNode.parentNode;
loader.open('GET', 'https://ngb.to/' + url.replace("http:\/\/", "https:\/\/"));
loader.send();
return;
}

var boardLinks = document.querySelectorAll('h2.forumtitle');
for (var i = 0; i < boardLinks.length; ++i) {
var hrefLink = boardLinks.innerHTML.match(/href="[\s\w\böäüÖÄÜ\-\_\/\\].*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, i, true);
}
[/src]
 
Zuletzt bearbeitet:

Lokalrunde

Schneehasen-Administrator
Teammitglied

Registriert
13 Juli 2013
Beiträge
74.789
Ort
im Tiefschnee
Prinzipiell finde ich es nicht schlecht, aber zumindest unter Tampermonkey in Chrome scheint es nicht ganz fehlerfrei zu funktionieren. So hat sich beispielsweise bei den internen Foren (die Du nicht sehen kannst, was das bugfixen natürlich komplizierter macht, das ist mir klar) ein Fehler eingeschlichen, wonach der letzte Beitrag angeblich von Kugelfisch stammen soll, was ja bekanntlich nicht der Fall sein kann. Außerdem werden in bestimmten Foren (beispielsweise Teilen der Börse) gar keine Threads angezeigt.
 

theSplit

1998
Veteran Barkeeper

Registriert
3 Aug. 2014
Beiträge
28.577
  • Thread Starter Thread Starter
  • #4
Danke für dein Feedback!

Ich habe eben nochmal ein paar augenscheinliche Fehler behoben und auch "Error" handling eingebaut, bzw. das Fehler überhaupt dargestellt werden.

Wenn du die Entwicklerkonsole aufmachst, sollte dir nun auch ein Fehler angezeigt werden, wenn er in der Hauptroutine stattfindet. Das würde mir schon einmal helfen den Fehler zu suchen, für interne Foren kann ich allerdings weniger etwas machen, hoffen wir das meine letzten Fehlerbehebungen das beheben. :)
 

Lokalrunde

Schneehasen-Administrator
Teammitglied

Registriert
13 Juli 2013
Beiträge
74.789
Ort
im Tiefschnee
Wenn Du mir jetzt noch sagst, welche Fehler Du da genau benötigst, kann ich Dir weiterhelfen :D
Ich bin in der Beziehung eher unwissend, weißt Du ja ;)


Edit: Hier mal ein Beispiel für einen Fehler:



Bei Hardware wird nix angezeigt, obwohl es aktuelle Threads gibt.
 

theSplit

1998
Veteran Barkeeper

Registriert
3 Aug. 2014
Beiträge
28.577
  • Thread Starter Thread Starter
  • #6
Ich habe mal die Fehlerquellen etwas mehr hervorgehoben, heißt, wenn etwas einen Fehler schmeißt, steht da "[ERROR] Fehlermeldung", mehr oder minder auch mit URL und Grund.

Das Skript aktualisiere ich gleich, dann sollte es passen.

Das du im Hardware den Thread von "takota" nicht sehen kannst, hat aber auch damit zu tun, das das Thema im Unterforum "Hardware-Kaufberatung" liegt, die Hardware Anzeige sollte nun passen. Da gab es noch ein Problem mit.

In "Kaufberatung", schmeißt der Ajax Request einen 301 - Permanent umgezogen für das "Hardware" Forum, dass muss wohl an der Verlinkung liegen wie die Inhalte "doppelt" vorhanden sind.

Ich aktualisiere eben mal das Skript im Thread des "v1.1" :) Edit: Done!

Edit2:

Habe gerade noch eine Bearbeitung gemacht, das Benutzernamen nicht korrekt angezeigt worden sind, durch Unterforen, das sollte jetzt auch behoben sein. So wurde ein falscher Benutzername im Hardware zum Beispiel angezeigt.
 
Zuletzt bearbeitet:

Lokalrunde

Schneehasen-Administrator
Teammitglied

Registriert
13 Juli 2013
Beiträge
74.789
Ort
im Tiefschnee
Funktioniert zwar nun schon etwas besser, es bleiben aber nach wie vor Foren ohne Threads in der Übersicht.

[ERROR] Error in script: TypeError: Cannot read property 'replace' of undefined, loader: https://ngb.to/forums/11-Hardware
[ERROR] Error in script: TypeError: Cannot read property 'replace' of undefined, loader: https://ngb.to/forums/25-Grafik
[ERROR] Error in script: TypeError: Cannot read property 'replace' of undefined, loader: https://ngb.to/forums/90-Schnäppchen
[ERROR] Error in script: TypeError: Cannot read property 'replace' of undefined, loader: https://ngb.to/forums/18-Zwischenmenschliches
[ERROR] Error in script: TypeError: Cannot read property 'replace' of undefined, loader: https://ngb.to/forums/64-Werbung
Das sollten alle sein, hoffe, das hilft weiter.
 

theSplit

1998
Veteran Barkeeper

Registriert
3 Aug. 2014
Beiträge
28.577
  • Thread Starter Thread Starter
  • #8
Versuch mal bitte Zeile 49 wie folgt abzuändern:

[src=javascript]if (offset + x + offsetUser == threadAuthors.length || offset + x == threadLinks.length || offset + x == threadTimes.length) {[/src]

Neu in der Zeile ist das:
|| offset + x == threadTimes.length


Das überprüft ob die Zeiten (threadTimes) außerhalb bereits abgearbeitet sind bzw. nicht mehr bearbeitet werden können falls ja, bricht die Ausführung ab und stellt dann nur dass da, was wir bisher haben.

Ich weiß nicht ob du da mehr siehst als ich als Normaluser, aber nur da werden Daten mit einem "replace" (ein String) verändert.

PS: Kannst du das auch mal in Firefox testen, falls möglich/nötig?

Eigentlich sollten die Zeiten aber definiert sein, außer dein Markup (HTML) sieht anders aus. ;)
 
Zuletzt bearbeitet:

Lokalrunde

Schneehasen-Administrator
Teammitglied

Registriert
13 Juli 2013
Beiträge
74.789
Ort
im Tiefschnee
Grafik (und übrigens auch "Konsolen und Emulatoren", obwohl es dafür keine Fehlermeldung gab) bleibt nach wie vor leer, mittlerweile aber ohne Fehlermeldung in der Konsole.

Für Firefox bin ich der falsche Ansprechpartner, den nutze ich nur noch sporadisch und habe auch nur Werbeblocker & NoScript installiert.
 

Lokalrunde

Schneehasen-Administrator
Teammitglied

Registriert
13 Juli 2013
Beiträge
74.789
Ort
im Tiefschnee
Die angezeigten Namen stimmen übrigens nicht, wie ich gerade sehe:



Das passt nicht. Frodoo taucht auf, ohne wirklich aktiv gewesen zu sein und der Rest ist dadurch "verrutscht".
 

theSplit

1998
Veteran Barkeeper

Registriert
3 Aug. 2014
Beiträge
28.577
  • Thread Starter Thread Starter
  • #11
Ja, das war wirklich ein Problem, ich glaube das habe ich nun im Griff, kopiere dir am besten das gesamte Skript noch einmal aus dem v1.1 "Post", habe es aktualisiert vor kurzer Zeit.
Bei mir stimmt es zum Beispiel aktuell.

Siehe Screenshot:

 

theSplit

1998
Veteran Barkeeper

Registriert
3 Aug. 2014
Beiträge
28.577
  • Thread Starter Thread Starter
  • #12
Grafik (und übrigens auch "Konsolen und Emulatoren", obwohl es dafür keine Fehlermeldung gab) bleibt nach wie vor leer, mittlerweile aber ohne Fehlermeldung in der Konsole.

Für Firefox bin ich der falsche Ansprechpartner, den nutze ich nur noch sporadisch und habe auch nur Werbeblocker & NoScript installiert.


Grafik und Konsolen bleiben leer, weil immer nur das "erste" Forum vorgeladen wird, alle darunter liegenden bleiben ausgeschlossen.

Das heißt: In Grafik hat niemand gepostet, aber in den Wettbewerben, dann wird aber für Grafik nichts direkt angezeigt, erst wenn man in das Forum wechselt werden die "Unterforen" vorgeladen.

Du siehst also nur die Beiträge aus den "Oberforen", und alles was darunter ist, siehtst du eventuell erst dann, wenn du in das Oberforum hinein wechselst.
 

Lokalrunde

Schneehasen-Administrator
Teammitglied

Registriert
13 Juli 2013
Beiträge
74.789
Ort
im Tiefschnee
Ah, ok. Da ich bei den Konsolen normalerweise nie gucke, dachte ich am letzten Beitrag den 04.06.17 gesehen zu haben, war aber schon 2016. Dann passt es ja ;)
Den Rest teste ich jetzt nicht mehr, das probiere ich später. Ist mir jetzt schon zu spät, um das nochmal ausgiebig zu testen ;)
 

theSplit

1998
Veteran Barkeeper

Registriert
3 Aug. 2014
Beiträge
28.577
  • Thread Starter Thread Starter
  • #15
.... du Grammernazi, der Unterschied ist mir aber bekannt. :p
Wohl zu schnell getippt ;)

Habs korrigiert :p

Seid ihr alle damit einverstanden? - Ich hoffe doch ;)
 

theSplit

1998
Veteran Barkeeper

Registriert
3 Aug. 2014
Beiträge
28.577
  • Thread Starter Thread Starter
  • #17
Update: v1.2

- es gibt einen Ein und Ausschalter für NGB Subload "NBG Sl [an] / NGB Sl [aus] (im Usermenü, Update2: für unangemeldete im Boardmenü) (Update: jetzt auch über einen Cookie gesteuert)
- Subload kann jetzt über Cookies steuern, welche Foren geladen werden sollen und welche nicht - per Default werden keine Foren geladen mehr vorgeladen
- die Foren können interaktiv entladen und geladen werden, mit Buttons können die Foren bestimmt werden die automatisch geladen werden sollen und dann beim nächsten Besuch wieder geladen werden
- wird ein Forum mit Unterforum besucht, erstellt Subload Cookies für diese, diese können dann mit einem Click auf "Add to Subload" geladen werden
- ein Klick auf einen Themenlink öffnet automatisch einen neuen Tab, anstelle des aktuellen so kann von dort aus navigiert werden wo man sich gerade befindet und das Thema im neuen Tab gelesen werden
- Links zu den Themen sind nun auch die letzten Posts, nicht mehr der erste Post im Thema
- Auslesen der Threadprefix funktioniert (letzter Screenshot)

Erst ein paar Screenshots:


Mit Threadprefixen:


Und hier der neue Code (ich update gleich den Startpost mit dem Link zu den Versionen:

[src=javascript]
// ==UserScript==
// @name NGB Subloader
// @namespace ngb_subload
// @description NGB Subloader
// @include https://ngb.to/
// @include https://ngb.to/#*
// @include https://ngb.to/forum*
// @version 1.2
// @grant none
// ==/UserScript==

var loaded = 0;
var hasLoaded = false;
var boardLinks;

function toggleVisibility(event) {
var ngbSubloadDivs = document.getElementsByClassName("ngbSubloadDiv");
var ngbSubloadToggles = document.getElementsByClassName("subLoadtoggleForum");

var show = "inline-block";
if (event.target.dataset.status == "on") {
show = "none";
event.target.dataset.status = "off";
event.target.innerHTML = "NGB-Sl [an]";
document.cookie = "subload_switch=off";
} else {
event.target.dataset.status = "on";
event.target.innerHTML = "NGB-Sl [aus]";
document.cookie = "subload_switch=on";
}

for (var i = 0; i < ngbSubloadDivs.length; ++i) {
ngbSubloadDivs.style.display = show;
ngbSubloadToggles.style.display = show;
}

if (!hasLoaded) {
for (var i = 0; i < boardLinks.length; ++i) {
var hrefLink = boardLinks.innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, i);
}
}

return false;
}

function toggleSubLoad(event) {
var forumId = event.target.dataset.name;
if (document.cookie.indexOf("subload_"+ forumId +"=true") != -1) {
document.cookie = "subload_"+forumId+"=false";
} else {
document.cookie = "subload_"+forumId+"=true";
}

var oldData = document.querySelector("div.ngbSubloadDiv."+forumId);
oldData.parentNode.removeChild(oldData);
loaded--;

boardLinks = document.querySelectorAll('h2.forumtitle');
var index = parseInt(event.target.dataset.index);
var hrefLink = boardLinks[index].innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, index);
}

function checkLoad() {
if (loaded >= boardLinks.length-2) {
var userMenu = document.querySelector("ul.isuser");
if (userMenu !== null) {
if (document.getElementById("ngb_subload_switch") === null) {
userMenu.innerHTML += '<li><a id="ngb_subload_switch" data-status="on" style="margin-left: 10px; margin-right: 15px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl [aus]</a></li>';
document.getElementById("ngb_subload_switch").addEventListener("click", toggleVisibility, true);
}
} else {
var subMenu = document.querySelector("ul.floatcontainer > ul.floatcontainer");
if (document.getElementById("ngb_subload_switch") === null) {
subMenu.innerHTML += '<li><a id="ngb_subload_switch" class="popupmenu" data-status="on" style="margin-left: 30px; margin-right: 15px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl [an]</a></li>';
document.getElementById("ngb_subload_switch").addEventListener("click", toggleVisibility, true);
}
}

var toggleButtons = document.getElementsByClassName("subLoadtoggleForum");
for (var i = 0; i < toggleButtons.length; ++i) {
toggleButtons.addEventListener("click", toggleSubLoad, true);
}

hasLoaded = true;
}
}

function loaderChangeStatus(loader) {
loader = loader.target;
if (loader.readyState == 4 && loader.status == 200) {
data = loader.responseText.replace(/\n|\t|\b/g, '');
try {
var threadLinks = data.match(/class="titl.*<\/a>/g);
var threadLastPosts = data.match(/<a .*lastpostdate.*<\/a>/g);
var threadPrefixes = data.replace(/\n|\t|\b|\r/g, '').match(/id="thread_prefix.*\<\/span>/g);
var threadAuthors = data.match(/<a[\s\w\b].* popupctr.*<\/a>/g);
var threadTimes = data.match(/<dd>.*<\/span>/g);
} catch (error) {
console.log("[ERROR] Error in script: "+ error + ", loader: " + loader.responseURL);
loaded++;
return;
}

for (var i = 0; i < threadTimes.length; i++) {
if (threadTimes.match(/"time"/) === null) {
threadTimes.splice(i, 1);
i--;
}
}

var forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.id
if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

var htmlData = '<div class="ngbSubloadDiv ' + forumId +'" style="clear: both; display: inline-block; width: 100%; margin: 10px 0px 10px 20px;">';

if (document.cookie.indexOf("subload_"+ forumId +"=true") == -1) {
loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+ loader.index +'" style="clear:both; float: right; margin-top: 15px;">Add to subload</button></div>';
loaded++;

checkLoad();
return;
}

if (threadLinks.length !== 0) {
try {
var threadTitle = "";
var threadUrl = '';
var threadAuthor = '';
var threadAuthorId = 0;
var threadTime = '';
var threadId = "";
var lastThreadPrefix = 0;

var now = new Date();
var offset = 0;
var offsetUser = Math.abs(threadAuthors.length - threadLinks.length);

for (var x = 0; x < 8; x++) {
if (offset + x + offsetUser == threadAuthors.length || offset + x == threadLinks.length || offset + x == threadTimes.length) {
break;
}

threadTitle = threadLinks[x + offset].match(/">.*<\/a>/g)[0];
threadTitle = threadTitle.substring(2, threadTitle.length-4);
threadUrl = threadLastPosts[x + offset].match(/href="threads[\s\wäöüÄÖÜ\\\/\#\?\+\-\_\=\(\)\[\]]*/g)[0];
threadUrl = threadUrl.substr(6, threadUrl.length - 1);
threadAuthor = threadAuthors[x + offset + offsetUser].match(/<strong\>[\s\w\däöüÄÖÜ\-\\\\/_\(\)\[\]].*<\/strong>/g)[0];
threadAuthor = threadAuthor.substring(8,threadAuthor.length-9);
threadAuthorId = threadAuthors[x + offset].match(/members\/[0-9]*\-/g)[0];
threadAuthorId.substring(7, threadAuthorId.length);
threadTime = threadTimes[x + offset].replace(/<dd>|<span class="time">|<\/span>/g, '');
threadId = threadLinks[x + offset].match(/href="threads\/[0-9]*/g)[0];
threadId = threadId.substring(14, threadId.length);

if (threadTime.indexOf("Heute,") === -1 && threadTime.indexOf("Gestern,") === -1) {
var timeDate = threadTime.match(/[0-9].?/g);
var dateObj = new Date();
dateObj.setDate(parseInt(timeDate[0]));
dateObj.setMonth(parseInt(timeDate[1])-1);
dateObj.setFullYear(parseInt("20"+timeDate[2]));
dateObj.setHours(parseInt(timeDate[3]));
dateObj.setMinutes(parseInt(timeDate[4]));
dateObj.setSeconds(0);
dateObj.setMilliseconds(0);
if (dateObj.getTime() < now - ((3600 * 1000) * 24 * 30)) { // 30 - Anzahl der Tage die Themen alt sein duerfen
offset++;
x--;
continue;
}
}

var prefix = "";
if (threadPrefixes !== null) {
for (var i = lastThreadPrefix; i < threadPrefixes.length; ++i) {
if (threadPrefixes.indexOf(threadId) != -1) {
lastThreadPrefix = i;
prefix = threadPrefixes.match(/>[\s\w\b\-\_\(\)\[\]äöüÄÖÜ\:\,\;\#\+\*\&\/]*<\/span>/g)[0].trimRight();
prefix = prefix.substring(1, prefix.length-7);
}
}
}

if (prefix != "") {
htmlData += '<span style="clear: both; float:left;"><i>' + prefix + '</i> <a href="https://ngb.to/' + threadUrl + '" target="_blank">' + threadTitle + '</a></span>';
} else {
htmlData += '<a style="clear: left; float: left;" href="https://ngb.to/' + threadUrl + '" target="_blank">' + threadTitle + '</a>';
}

htmlData += '<p style="display: block; text-align: right; margin-left: 10%;">[ <a href="https://ngb.to/members/'+threadAuthorId+threadAuthor+'">' + threadAuthor + '</a>, ' + threadTime + ' Uhr ]</p>';
}

loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+loader.index+'" style="clear:both; float: right; margin-top: 15px;">Remove of subload</button></div>';
loaded++;
checkLoad();

} catch (error) {
console.log("[ERROR] Error in script: "+ error + ", loader: " + loader.responseURL);
}
}

} else if (loader.readyState == 4) {
console.log("[ERROR] Loader status: " + loader.responseURL + " : (" + loader.status + ") "+ loader.statusText);
loaded++;
checkLoad();
}

return;
}

function ajaxLoader(url, index) {
var loader = new XMLHttpRequest();
loader.addEventListener('readystatechange', loaderChangeStatus);
loader.parent = boardLinks[index].parentNode.parentNode;
loader.index = index;

var forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.id;
if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

if (document.cookie.indexOf("subload_"+ forumId +"=true") == -1) {
var htmlData = '<div class="ngbSubloadDiv ' + forumId +'" style="clear: both; display: inline-block; width: 100%; margin: 10px 0px 10px 20px;">';
loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+loader.index+'" style="clear:both; float: right; margin-top: 15px;">Add to subload</button></div>';
loaded++;
checkLoad();
return;
}

loader.open('GET', 'https://ngb.to/' + url.replace("http:\/\/", "https:\/\/"), true);
loader.send();
return;
}

//-----------------------------------------------------------------------------------------------

boardLinks = document.querySelectorAll('h2.forumtitle');
for (var i = 0; i < boardLinks.length; ++i) {
var forumId = boardLinks.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;

if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = boardLinks.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

if (document.cookie.indexOf("subload_"+ forumId +"=true") == -1 && document.cookie.indexOf("subload_"+ forumId +"=false") == -1) {
document.cookie = "subload_"+ forumId +"=false";
}
}

// Check for existing subload cookie
if (document.cookie.indexOf("subload_switch=on") == -1 && document.cookie.indexOf("subload_switch=off") == -1) {
document.cookie = "subload_switch=on";
}

if (document.cookie.indexOf("subload_switch=on") != -1) {
for (var i = 0; i < boardLinks.length; ++i) {
var hrefLink = boardLinks.innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, i);
}
} else {
setTimeout(function() {
var userMenu = document.querySelector("ul.isuser");
if (userMenu !== null) {
if (document.getElementById("ngb_subload_switch") === null) {
userMenu.innerHTML += '<li><a id="ngb_subload_switch" data-status="off" style="margin-left: 10px; margin-right: 15px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl [an]</a></li>';
document.getElementById("ngb_subload_switch").addEventListener("click", toggleVisibility, true);
}
} else {
var subMenu = document.querySelector("ul.floatcontainer > ul.floatcontainer");
if (document.getElementById("ngb_subload_switch") === null) {
subMenu.innerHTML += '<li><a id="ngb_subload_switch" class="popupmenu" data-status="off" style="margin-left: 30px; margin-right: 15px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl [an]</a></li>';
document.getElementById("ngb_subload_switch").addEventListener("click", toggleVisibility, true);
}
}
}, 450);
}[/src]
 
Zuletzt bearbeitet:

theSplit

1998
Veteran Barkeeper

Registriert
3 Aug. 2014
Beiträge
28.577
  • Thread Starter Thread Starter
  • #18
Update v1.2.2 (bitte nutzt v1.2.3, weiter unten)

Changelog:
- einen Button "NGB-Sl Buttons [an/aus] im Usermenü (für uneingeloggt im "Untermenü im Forum") hinzugefügt
- neuer Button blendet den Button zum "Add to subload" / "Remove of subload" aus (über Cookies)
- Fehlermeldungen zeigen nun auch auf die Zeile im Skript, in der der Fehler passiert ist
- Code cleanups

[src=javascript]// ==UserScript==
// @name NGB Subloader
// @namespace ngb_subload
// @description NGB Subloader
// @include https://ngb.to/
// @include https://ngb.to/#*
// @include https://ngb.to/forum*
// @version 1.2.2
// @grant none
// ==/UserScript==

var loaded = 0;
var hasLoaded = false;
var boardLinks;

function toggleVisibility(event) {
var ngbSubloadDivs = document.getElementsByClassName("ngbSubloadDiv");

var show = "inline-block";
if (event.target.dataset.status == "on") {
show = "none";
event.target.dataset.status = "off";
event.target.innerHTML = "NGB-Sl [an]";
document.cookie = "subload_switch=off";
} else {
event.target.dataset.status = "on";
event.target.innerHTML = "NGB-Sl [aus]";
document.cookie = "subload_switch=on";
}

for (var i = 0; i < ngbSubloadDivs.length; ++i) {
ngbSubloadDivs.style.display = show;
}

if (!hasLoaded) {
for (var i = 0; i < boardLinks.length; ++i) {
var hrefLink = boardLinks.innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, i);
}
}

return false;
}

function toggleButtons(event) {
var ngbSubloadToggles = document.getElementsByClassName("subLoadtoggleForum");

var show = "inline-block";
if (event.target.dataset.status == "on") {
show = "none";
event.target.dataset.status = "off";
event.target.innerHTML = "NGB-Sl Buttons [an]";
document.cookie = "subload_switch_buttons=off";
} else {
event.target.dataset.status = "on";
event.target.innerHTML = "NGB-Sl Buttons [aus]";
document.cookie = "subload_switch_buttons=on";
}

for (var i = 0; i < ngbSubloadToggles.length; ++i) {
ngbSubloadToggles.style.display = show;
}

return false;
}


function toggleSubLoad(event) {
var forumId = event.target.dataset.name;
if (document.cookie.indexOf("subload_"+ forumId +"=true") != -1) {
document.cookie = "subload_"+forumId+"=false";
} else {
document.cookie = "subload_"+forumId+"=true";
}

var oldData = document.querySelector("div.ngbSubloadDiv."+forumId);
oldData.parentNode.removeChild(oldData);
loaded--;

boardLinks = document.querySelectorAll('h2.forumtitle');
var index = parseInt(event.target.dataset.index);
var hrefLink = boardLinks[index].innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, index);
}

function checkLoad() {
if (loaded >= boardLinks.length-2) {
var userMenu = document.querySelector("ul.isuser");
if (userMenu !== null) {
if (document.getElementById("ngb_subload_switch") === null) {
userMenu.innerHTML += '<li><a id="ngb_subload_switch_buttons" data-status="on" style="margin-right: 15px; cursor: pointer; text-decoration: none;" title="NGB Subload Buttons">NGB-Sl Buttons[aus]</a></li>';
userMenu.innerHTML += '<li><a id="ngb_subload_switch" data-status="on" style="margin-left: 10px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl [aus]</a></li>';
document.getElementById("ngb_subload_switch_buttons").addEventListener("click", toggleButtons, true);
document.getElementById("ngb_subload_switch").addEventListener("click", toggleVisibility, true);
}
} else {
var subMenu = document.querySelector("ul.floatcontainer > ul.floatcontainer");
if (document.getElementById("ngb_subload_switch") === null) {
subMenu.innerHTML += '<li><a id="ngb_subload_switch" class="popupmenu" data-status="on" style="margin-left: 30px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl [aus]</a></li>';
subMenu.innerHTML += '<li><a id="ngb_subload_switch_buttons" class="popmenu" data-status="on" style="margin-right: 15px; cursor: pointer; text-decoration: none;" title="NGB Subload Buttons umschalten">NGB-Sl Buttons [aus]</a></li>';
document.getElementById("ngb_subload_switch_buttons").addEventListener("click", toggleButtons, true);
document.getElementById("ngb_subload_switch").addEventListener("click", toggleVisibility, true);
}
}

var displayStr = "inline-block";
if (document.cookie.indexOf("subload_switch_buttons=off") != -1) {
displayStr = "none";
}

var toggleButtonsArray = document.getElementsByClassName("subLoadtoggleForum");
for (var i = 0; i < toggleButtonsArray.length; ++i) {
toggleButtonsArray.addEventListener("click", toggleSubLoad, true);
toggleButtonsArray.style.display = displayStr;
}

hasLoaded = true;
}
}

function loaderChangeStatus(loader) {
loader = loader.target;
if (loader.readyState == 4 && loader.status == 200) {
data = loader.responseText.replace(/\n|\t|\b/g, '');
try {
var threadLinks = data.match(/class="titl.*<\/a>/g);
var threadLastPosts = data.match(/<a .*lastpostdate.*<\/a>/g);
var threadPrefixes = data.replace(/\n|\t|\b|\r/g, '').match(/id="thread_prefix.*\<\/span>/g);
var threadAuthors = data.match(/<a[\s\w\b].* popupctr.*<\/a>/g);
var threadTimes = data.match(/<dd>.*<\/span>/g);
} catch (error) {
console.log("[ERROR] Error in script: "+ error + ", lineNumber, "+error.lineNumber+", loader: " + loader.responseURL);
loaded++;
return;
}

for (var i = 0; i < threadTimes.length; i++) {
if (threadTimes.match(/"time"/) === null) {
threadTimes.splice(i, 1);
i--;
}
}

var forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.id
if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

var htmlData = '<div class="ngbSubloadDiv ' + forumId +'" style="clear: both; display: inline-block; width: 100%; margin: 10px 0px 10px 20px;">';

if (document.cookie.indexOf("subload_"+ forumId +"=true") == -1) {
loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+ loader.index +'" style="clear:both; float: right; margin-top: 15px;">Add to subload</button></div>';
loaded++;

checkLoad();
return;
}

if (threadLinks.length !== 0) {
try {
var threadTitle = "";
var threadUrl = '';
var threadAuthor = '';
var threadAuthorId = 0;
var threadTime = '';
var threadId = "";
var lastThreadPrefix = 0;

var now = new Date();
var offset = 0;
var offsetUser = Math.abs(threadAuthors.length - threadLinks.length);

for (var x = 0; x < 8; x++) {
if (offset + x + offsetUser == threadAuthors.length || offset + x == threadLinks.length || offset + x == threadTimes.length) {
break;
}

threadTitle = threadLinks[x + offset].match(/">.*<\/a>/g)[0];
threadTitle = threadTitle.substring(2, threadTitle.length-4);
threadUrl = threadLastPosts[x + offset].match(/href="threads[\s\wäöüÄÖÜ\\\/\#\?\+\-\_\=\(\)\[\]]*/g)[0];
threadUrl = threadUrl.substr(6, threadUrl.length - 1);
threadAuthor = threadAuthors[x + offset + offsetUser].match(/<strong\>[\s\w\däöüÄÖÜ\-\\\\/_\(\)\[\]].*<\/strong>/g)[0];
threadAuthor = threadAuthor.substring(8,threadAuthor.length-9);
threadAuthorId = threadAuthors[x + offset].match(/members\/[0-9]*\-/g)[0];
threadAuthorId.substring(7, threadAuthorId.length);
threadTime = threadTimes[x + offset].replace(/<dd>|<span class="time">|<\/span>/g, '');
threadId = threadLinks[x + offset].match(/href="threads\/[0-9]*/g)[0];
threadId = threadId.substring(14, threadId.length);

if (threadTime.indexOf("Heute,") === -1 && threadTime.indexOf("Gestern,") === -1) {
var timeDate = threadTime.match(/[0-9].?/g);
var dateObj = new Date();
dateObj.setDate(parseInt(timeDate[0]));
dateObj.setMonth(parseInt(timeDate[1])-1);
dateObj.setFullYear(parseInt("20"+timeDate[2]));
dateObj.setHours(parseInt(timeDate[3]));
dateObj.setMinutes(parseInt(timeDate[4]));
dateObj.setSeconds(0);
dateObj.setMilliseconds(0);
if (dateObj.getTime() < now - ((3600 * 1000) * 24 * 30)) { // 30 - Anzahl der Tage die Themen alt sein duerfen
offset++;
x--;
continue;
}
}

var prefix = "";
if (threadPrefixes !== null) {
for (var i = lastThreadPrefix; i < threadPrefixes.length; ++i) {
if (threadPrefixes.indexOf(threadId) != -1) {
lastThreadPrefix = i;
prefix = threadPrefixes.match(/>[\s\w\b\-\_\(\)\[\]äöüÄÖÜ\:\,\;\#\+\*\&\/]*<\/span>/g)[0].trimRight();
prefix = prefix.substring(1, prefix.length-7);
}
}
}

if (prefix != "") {
htmlData += '<span style="clear: both; float:left;"><i>' + prefix + '</i> <a href="https://ngb.to/' + threadUrl + '" target="_blank">' + threadTitle + '</a></span>';
} else {
htmlData += '<a style="clear: left; float: left;" href="https://ngb.to/' + threadUrl + '" target="_blank">' + threadTitle + '</a>';
}

htmlData += '<p style="display: block; text-align: right; margin-left: 10%;">[ <a href="https://ngb.to/members/'+threadAuthorId+threadAuthor+'">' + threadAuthor + '</a>, ' + threadTime + ' Uhr ]</p>';
}

loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+loader.index+'" style="clear:both; float: right; margin-top: 15px;">Remove of subload</button></div>';
loaded++;
checkLoad();

} catch (error) {
console.log("[ERROR] Error in script: "+ error + ", lineNumber, "+error.lineNumber+", loader: " + loader.responseURL);
}
}

} else if (loader.readyState == 4) {
console.log("[ERROR] Loader status: " + loader.responseURL + " : (" + loader.status + ") "+ loader.statusText);
loaded++;
checkLoad();
}

return;
}

function ajaxLoader(url, index) {
var loader = new XMLHttpRequest();
loader.addEventListener('readystatechange', loaderChangeStatus);
loader.parent = boardLinks[index].parentNode.parentNode;
loader.index = index;

var forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.id;
if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

if (document.cookie.indexOf("subload_"+ forumId +"=true") == -1) {
var htmlData = '<div class="ngbSubloadDiv ' + forumId +'" style="clear: both; display: inline-block; width: 100%; margin: 10px 0px 10px 20px;">';
loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+loader.index+'" style="clear:both; float: right; margin-top: 15px;">Add to subload</button></div>';
loaded++;
checkLoad();
return;
}

loader.open('GET', 'https://ngb.to/' + url.replace("http:\/\/", "https:\/\/"), true);
loader.send();
return;
}

//-----------------------------------------------------------------------------------------------

boardLinks = document.querySelectorAll('h2.forumtitle');
for (var i = 0; i < boardLinks.length; ++i) {
var forumId = boardLinks.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;

if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = boardLinks.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

if (document.cookie.indexOf("subload_"+ forumId +"=true") == -1 && document.cookie.indexOf("subload_"+ forumId +"=false") == -1) {
document.cookie = "subload_"+ forumId +"=false";
}
}

// Check for existing subload main cookies
if (document.cookie.indexOf("subload_switch=on") == -1 && document.cookie.indexOf("subload_switch=off") == -1) {
document.cookie = "subload_switch=on";
}
if (document.cookie.indexOf("subload_switch_buttons=on") == -1 && document.cookie.indexOf("subload_switch_buttons=off") == -1) {
document.cookie = "subload_switch_buttons=on";
}

if (document.cookie.indexOf("subload_switch=on") != -1) {
for (var i = 0; i < boardLinks.length; ++i) {
var hrefLink = boardLinks.innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, i);
}
} else {
setTimeout(function() {
var userMenu = document.querySelector("ul.isuser");
if (userMenu !== null) {
if (document.getElementById("ngb_subload_switch") === null) {
userMenu.innerHTML += '<li><a id="ngb_subload_switch_buttons" data-status="off" style="margin-right: 15px; cursor: pointer; text-decoration: none;" title="NGB Subload Buttons umschalten">NGB-Sl Buttons [an]</a></li>';
userMenu.innerHTML += '<li><a id="ngb_subload_switch" data-status="off" style="margin-left: 10px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl [an]</a></li>';
document.getElementById("ngb_subload_switch").addEventListener("click", toggleVisibility, true);
document.getElementById("ngb_subload_switch_buttons").addEventListener("click", toggleButtons, true);
}
} else {
var subMenu = document.querySelector("ul.floatcontainer > ul.floatcontainer");
if (document.getElementById("ngb_subload_switch") === null) {
subMenu.innerHTML += '<li><a id="ngb_subload_switch" class="popupmenu" data-status="off" style="margin-left: 30px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl [an]</a></li>';
subMenu.innerHTML += '<li><a id="ngb_subload_switch_buttons" class="popupmenu" data-status="off" style="margin-right: 15px; cursor: pointer; text-decoration: none;" title="NGB Subload Buttons umschalten">NGB-Sl Buttons [an]</a></li>';
document.getElementById("ngb_subload_switch").addEventListener("click", toggleVisibility, true);
document.getElementById("ngb_subload_switch_buttons").addEventListener("click", toggleButtons, true);
}
}
}, 450);
}
[/src]

Update 1.2.3 (1.2.4 weiter unten!)
- Important Change: Die Schalter für Subload sind nun nicht mehr im Usermenü, sondern auf einer Höhe mit der Breadcrumb Liste, weil ansonsten die "Popups" für die Menüs nicht mehr funktioniert haben, nachdem die Subload Einträge hinzugefügt worden sind.
- Change: Die Schalter sind nun keine Textlinks mehr, sondern Buttons
- Bugfix "Der Button ein/ausschalter" hatte nicht den korrekten Status beim Neuladen übernommen


[src=javascript]
// ==UserScript==
// @name NGB Subloader
// @namespace ngb_subload
// @description NGB Subloader
// @include https://ngb.to/
// @include https://ngb.to/#*
// @include https://ngb.to/forum*
// @version 1.2.3
// @grant none
// ==/UserScript==

var loaded = 0;
var hasLoaded = false;
var boardLinks;

function toggleVisibility(event) {
var ngbSubloadDivs = document.getElementsByClassName("ngbSubloadDiv");

var show = "inline-block";
if (event.target.dataset.status == "on") {
show = "none";
event.target.dataset.status = "off";
event.target.innerHTML = "NGB-Sl [an]";
document.cookie = "subload_switch=off";
} else {
event.target.dataset.status = "on";
event.target.innerHTML = "NGB-Sl [aus]";
document.cookie = "subload_switch=on";
}

for (var i = 0; i < ngbSubloadDivs.length; ++i) {
ngbSubloadDivs.style.display = show;
}

if (!hasLoaded) {
for (var i = 0; i < boardLinks.length; ++i) {
var hrefLink = boardLinks.innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, i);
}
}

return false;
}

function toggleButtons(event) {
var ngbSubloadToggles = document.getElementsByClassName("subLoadtoggleForum");

var show = "inline-block";
if (event.target.dataset.status == "on") {
show = "none";
event.target.dataset.status = "off";
event.target.innerHTML = "NGB-Sl Buttons [an]";
document.cookie = "subload_switch_buttons=off";
} else {
event.target.dataset.status = "on";
event.target.innerHTML = "NGB-Sl Buttons [aus]";
document.cookie = "subload_switch_buttons=on";
}

for (var i = 0; i < ngbSubloadToggles.length; ++i) {
ngbSubloadToggles.style.display = show;
}

return false;
}


function toggleSubLoad(event) {
var forumId = event.target.dataset.name;
if (document.cookie.indexOf("subload_"+ forumId +"=true") != -1) {
document.cookie = "subload_"+forumId+"=false";
} else {
document.cookie = "subload_"+forumId+"=true";
}

var oldData = document.querySelector("div.ngbSubloadDiv."+forumId);
oldData.parentNode.removeChild(oldData);
loaded--;

boardLinks = document.querySelectorAll('h2.forumtitle');
var index = parseInt(event.target.dataset.index);
var hrefLink = boardLinks[index].innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, index);
}

function checkLoad() {
if (loaded >= boardLinks.length-2) {

var subLoadStatus = "off";
var subLoadText = "an";
if (document.cookie.indexOf("subload_switch=on") != -1) {
subLoadStatus = "on";
subLoadText = "aus";
}

var buttonStatus = "off";
var buttonText = "an";
if (document.cookie.indexOf("subload_switch_buttons=on") != -1) {
buttonStatus = "on";
buttonText = "aus";
}

var subMenu = document.querySelector("div.breadcrumb > ul");
if (document.getElementById("ngb_subload_switch") === null) {
subMenu.innerHTML += '<li><div style="float: right;"> \
<button id="ngb_subload_switch" data-status="'+ subLoadStatus +'" style="margin-right: 10px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl ['+ subLoadText +']</button> \
<button id="ngb_subload_switch_buttons" data-status="'+ buttonStatus +'" style="cursor: pointer; text-decoration: none;" title="NGB Subload Buttons umschalten">NGB-Sl Buttons ['+ buttonText +']</button></div></li>';
document.getElementById("ngb_subload_switch").addEventListener("click", toggleVisibility, true);
document.getElementById("ngb_subload_switch_buttons").addEventListener("click", toggleButtons, true);
}


var displayStr = "inline-block";
if (document.cookie.indexOf("subload_switch_buttons=off") != -1) {
displayStr = "none";
}

var toggleButtonsArray = document.getElementsByClassName("subLoadtoggleForum");
for (var i = 0; i < toggleButtonsArray.length; ++i) {
toggleButtonsArray.addEventListener("click", toggleSubLoad, true);
toggleButtonsArray.style.display = displayStr;
}

hasLoaded = true;
}
}

function loaderChangeStatus(loader) {
loader = loader.target;
if (loader.readyState == 4 && loader.status == 200) {
data = loader.responseText.replace(/\n|\t|\b/g, '');
try {
var threadLinks = data.match(/class="titl.*<\/a>/g);
var threadLastPosts = data.match(/<a .*lastpostdate.*<\/a>/g);
var threadPrefixes = data.replace(/\n|\t|\b|\r/g, '').match(/id="thread_prefix.*\<\/span>/g);
var threadAuthors = data.match(/<a[\s\w\b].* popupctr.*<\/a>/g);
var threadTimes = data.match(/<dd>.*<\/span>/g);
} catch (error) {
console.log("[ERROR] Error in script: "+ error + ", lineNumber, "+error.lineNumber+", loader: " + loader.responseURL);
loaded++;
return;
}

for (var i = 0; i < threadTimes.length; i++) {
if (threadTimes.match(/"time"/) === null) {
threadTimes.splice(i, 1);
i--;
}
}

var forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.id
if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

var htmlData = '<div class="ngbSubloadDiv ' + forumId +'" style="clear: both; display: inline-block; width: 100%; margin: 10px 0px 10px 20px;">';

if (document.cookie.indexOf("subload_"+ forumId +"=true") == -1) {
loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+ loader.index +'" style="clear:both; float: right; margin-top: 15px;">Add to subload</button></div>';
loaded++;

checkLoad();
return;
}

if (threadLinks.length !== 0) {
try {
var threadTitle = "";
var threadUrl = '';
var threadAuthor = '';
var threadAuthorId = 0;
var threadTime = '';
var threadId = "";
var lastThreadPrefix = 0;

var now = new Date();
var offset = 0;
var offsetUser = Math.abs(threadAuthors.length - threadLinks.length);

for (var x = 0; x < 8; x++) {
if (offset + x + offsetUser == threadAuthors.length || offset + x == threadLinks.length || offset + x == threadTimes.length) {
break;
}

threadTitle = threadLinks[x + offset].match(/">.*<\/a>/g)[0];
threadTitle = threadTitle.substring(2, threadTitle.length-4);
threadUrl = threadLastPosts[x + offset].match(/href="threads[\s\wäöüÄÖÜ\\\/\#\?\+\-\_\=\(\)\[\]]*/g)[0];
threadUrl = threadUrl.substr(6, threadUrl.length - 1);
threadAuthor = threadAuthors[x + offset + offsetUser].match(/<strong\>[\s\w\däöüÄÖÜ\-\\\\/_\(\)\[\]].*<\/strong>/g)[0];
threadAuthor = threadAuthor.substring(8,threadAuthor.length-9);
threadAuthorId = threadAuthors[x + offset].match(/members\/[0-9]*\-/g)[0];
threadAuthorId.substring(7, threadAuthorId.length);
threadTime = threadTimes[x + offset].replace(/<dd>|<span class="time">|<\/span>/g, '');
threadId = threadLinks[x + offset].match(/href="threads\/[0-9]*/g)[0];
threadId = threadId.substring(14, threadId.length);

if (threadTime.indexOf("Heute,") === -1 && threadTime.indexOf("Gestern,") === -1) {
var timeDate = threadTime.match(/[0-9].?/g);
var dateObj = new Date();
dateObj.setDate(parseInt(timeDate[0]));
dateObj.setMonth(parseInt(timeDate[1])-1);
dateObj.setFullYear(parseInt("20"+timeDate[2]));
dateObj.setHours(parseInt(timeDate[3]));
dateObj.setMinutes(parseInt(timeDate[4]));
dateObj.setSeconds(0);
dateObj.setMilliseconds(0);
if (dateObj.getTime() < now - ((3600 * 1000) * 24 * 30)) { // 30 - Anzahl der Tage die Themen alt sein duerfen
offset++;
x--;
continue;
}
}

var prefix = "";
if (threadPrefixes !== null) {
for (var i = lastThreadPrefix; i < threadPrefixes.length; ++i) {
if (threadPrefixes.indexOf(threadId) != -1) {
lastThreadPrefix = i;
prefix = threadPrefixes.match(/>[\s\w\b\-\_\(\)\[\]äöüÄÖÜ\:\,\;\#\+\*\&\/]*<\/span>/g)[0].trimRight();
prefix = prefix.substring(1, prefix.length-7);
}
}
}

if (prefix != "") {
htmlData += '<span style="clear: both; float:left;"><i>' + prefix + '</i> <a href="https://ngb.to/' + threadUrl + '" target="_blank">' + threadTitle + '</a></span>';
} else {
htmlData += '<a style="clear: left; float: left;" href="https://ngb.to/' + threadUrl + '" target="_blank">' + threadTitle + '</a>';
}

htmlData += '<p style="display: block; text-align: right; margin-left: 10%;">[ <a href="https://ngb.to/members/'+threadAuthorId+threadAuthor+'">' + threadAuthor + '</a>, ' + threadTime + ' Uhr ]</p>';
}

loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+loader.index+'" style="clear:both; float: right; margin-top: 15px;">Remove of subload</button></div>';
loaded++;
checkLoad();

} catch (error) {
console.log("[ERROR] Error in script: "+ error + ", lineNumber, "+error.lineNumber+", loader: " + loader.responseURL);
}
}

} else if (loader.readyState == 4) {
console.log("[ERROR] Loader status: " + loader.responseURL + " : (" + loader.status + ") "+ loader.statusText);
loaded++;
checkLoad();
}

return;
}

function ajaxLoader(url, index) {
var loader = new XMLHttpRequest();
loader.addEventListener('readystatechange', loaderChangeStatus);
loader.parent = boardLinks[index].parentNode.parentNode;
loader.index = index;

var forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.id;
if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

if (document.cookie.indexOf("subload_"+ forumId +"=true") == -1) {
var htmlData = '<div class="ngbSubloadDiv ' + forumId +'" style="clear: both; display: inline-block; width: 100%; margin: 10px 0px 10px 20px;">';
loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+loader.index+'" style="clear:both; float: right; margin-top: 15px;">Add to subload</button></div>';
loaded++;
checkLoad();
return;
}

loader.open('GET', 'https://ngb.to/' + url.replace("http:\/\/", "https:\/\/"), true);
loader.send();
return;
}

//-----------------------------------------------------------------------------------------------

boardLinks = document.querySelectorAll('h2.forumtitle');
for (var i = 0; i < boardLinks.length; ++i) {
var forumId = boardLinks.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;

if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = boardLinks.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

if (document.cookie.indexOf("subload_"+ forumId +"=true") == -1 && document.cookie.indexOf("subload_"+ forumId +"=false") == -1) {
document.cookie = "subload_"+ forumId +"=false";
}
}

// Check for existing subload main cookies
if (document.cookie.indexOf("subload_switch=on") == -1 && document.cookie.indexOf("subload_switch=off") == -1) {
document.cookie = "subload_switch=on";
}
if (document.cookie.indexOf("subload_switch_buttons=on") == -1 && document.cookie.indexOf("subload_switch_buttons=off") == -1) {
document.cookie = "subload_switch_buttons=on";
}

if (document.cookie.indexOf("subload_switch=on") != -1) {
for (var i = 0; i < boardLinks.length; ++i) {
var hrefLink = boardLinks.innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, i);
}
} else {
setTimeout(function() {
var subLoadStatus = "off";
var subLoadText = "an";
if (document.cookie.indexOf("subload_switch=on") != -1) {
subLoadStatus = "on";
subLoadText = "aus";
}

var buttonStatus = "off";
var buttonText = "an";
if (document.cookie.indexOf("subload_switch_buttons=on") != -1) {
buttonStatus = "on";
buttonText = "aus";
}

var subMenu = document.querySelector("div.breadcrumb > ul");
if (document.getElementById("ngb_subload_switch") === null) {
subMenu.innerHTML += '<li><div style="float: right;"> \
<button id="ngb_subload_switch" data-status="'+ subLoadStatus +'" style="margin-right: 10px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl ['+ subLoadText +']</button> \
<button id="ngb_subload_switch_buttons" data-status="'+ buttonStatus +'" style="cursor: pointer; text-decoration: none;" title="NGB Subload Buttons umschalten">NGB-Sl Buttons ['+ buttonText +']</button></div></li>';
document.getElementById("ngb_subload_switch").addEventListener("click", toggleVisibility, true);
document.getElementById("ngb_subload_switch_buttons").addEventListener("click", toggleButtons, true);
}
}, 450);
}
[/src]


Update 1.2.4

- Change: Einstellung über Variable: "useGMinsteadOfCookies" (Standard: true)
.... welche aussagt das wir SQLite über GM_setValue/GM_getValue nutzen, und nicht Cookies, welche gelöscht werden können. Wer Cookies verwenden will, muß Zeile 17 den Wert auf "false" (ohne "") setzen.


[src=javascript]// ==UserScript==
// @name NGB Subloader
// @namespace ngb_subload
// @description NGB Subloader
// @include https://ngb.to/
// @include https://ngb.to/#*
// @include https://ngb.to/forum*
// @version 1.2.4
// @author theSplit
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==



// Change either to: true OR false ---- in order to use OR not to use GM_setValue and GM_getValue with SQLite as storage out side the cookies, default: true
var useGMinsteadOfCookies = true;

// Dont change this
var loaded = 0;
var hasLoaded = false;
var boardLinks;


function toggleVisibility(event) {
var ngbSubloadDivs = document.getElementsByClassName("ngbSubloadDiv");

var show = "inline-block";
if (event.target.dataset.status == "on") {
show = "none";
event.target.dataset.status = "off";
event.target.innerHTML = "NGB-Sl [an]";
if (useGMinsteadOfCookies) {
GM_setValue("subload_switch", "off");
} else {
document.cookie = "subload_switch=off";
}

} else {
event.target.dataset.status = "on";
event.target.innerHTML = "NGB-Sl [aus]";
if (useGMinsteadOfCookies) {
GM_setValue("subload_switch", "on");
} else {
document.cookie = "subload_switch=on";
}
}

for (var i = 0; i < ngbSubloadDivs.length; ++i) {
ngbSubloadDivs.style.display = show;
}

if (!hasLoaded) {
for (var i = 0; i < boardLinks.length; ++i) {
var hrefLink = boardLinks.innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, i);
}
}

return false;
}

function toggleButtons(event) {
var ngbSubloadToggles = document.getElementsByClassName("subLoadtoggleForum");

var show = "inline-block";
if (event.target.dataset.status == "on") {
show = "none";
event.target.dataset.status = "off";
event.target.innerHTML = "NGB-Sl Buttons [an]";

if (useGMinsteadOfCookies) {
GM_setValue("subload_switch_buttons", "off");
} else {
document.cookie = "subload_switch_buttons=off";
}
} else {
event.target.dataset.status = "on";
event.target.innerHTML = "NGB-Sl Buttons [aus]";

if (useGMinsteadOfCookies) {
GM_setValue("subload_switch_buttons", "on");
} else {
document.cookie = "subload_switch_buttons=on";
}
}

for (var i = 0; i < ngbSubloadToggles.length; ++i) {
ngbSubloadToggles.style.display = show;
}

return false;
}


function toggleSubLoad(event) {
var forumId = event.target.dataset.name;
if (useGMinsteadOfCookies) {
if (GM_getValue("subload_"+ forumId) == "true") {
GM_setValue("subload_"+ forumId, "false");
} else {
GM_setValue("subload_"+ forumId, "true");
}
} else {
if (document.cookie.indexOf("subload_"+ forumId +"=true") != -1) {
document.cookie = "subload_"+forumId+"=false";
} else {
document.cookie = "subload_"+forumId+"=true";
}
}

var oldData = document.querySelector("div.ngbSubloadDiv."+forumId);
oldData.parentNode.removeChild(oldData);
loaded--;

boardLinks = document.querySelectorAll('h2.forumtitle');
var index = parseInt(event.target.dataset.index);
var hrefLink = boardLinks[index].innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, index);
}

function checkLoad() {
if (loaded >= boardLinks.length-2) {

var subLoadStatus = "off";
var subLoadText = "an";

var buttonStatus = "off";
var buttonText = "an";

if ((!useGMinsteadOfCookies && document.cookie.indexOf("subload_switch=on") != -1) || (useGMinsteadOfCookies && GM_getValue("subload_switch") == "on")) {
subLoadStatus = "on";
subLoadText = "aus";
}

if ((!useGMinsteadOfCookies && document.cookie.indexOf("subload_switch_buttons=on") != -1) || (useGMinsteadOfCookies && GM_getValue("subload_switch_buttons") == "on")) {
buttonStatus = "on";
buttonText = "aus";
}

var subMenu = document.querySelector("div.breadcrumb > ul");
if (document.getElementById("ngb_subload_switch") === null) {
subMenu.innerHTML += '<li><div style="float: right;"> \
<button id="ngb_subload_switch" data-status="'+ subLoadStatus +'" style="margin-right: 10px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl ['+ subLoadText +']</button> \
<button id="ngb_subload_switch_buttons" data-status="'+ buttonStatus +'" style="cursor: pointer; text-decoration: none;" title="NGB Subload Buttons umschalten">NGB-Sl Buttons ['+ buttonText +']</button></div></li>';
document.getElementById("ngb_subload_switch").addEventListener("click", toggleVisibility, true);
document.getElementById("ngb_subload_switch_buttons").addEventListener("click", toggleButtons, true);
}

var displayStr = "inline-block";
if ((!useGMinsteadOfCookies && document.cookie.indexOf("subload_switch_buttons=off") != -1) || (useGMinsteadOfCookies && GM_getValue("subload_switch_buttons") == "off")) {
displayStr = "none";
}

var toggleButtonsArray = document.getElementsByClassName("subLoadtoggleForum");
for (var i = 0; i < toggleButtonsArray.length; ++i) {
toggleButtonsArray.addEventListener("click", toggleSubLoad, true);
toggleButtonsArray.style.display = displayStr;
}

hasLoaded = true;
}
}

function loaderChangeStatus(loader) {
loader = loader.target;
if (loader.readyState == 4 && loader.status == 200) {
data = loader.responseText.replace(/\n|\t|\b/g, '');
try {
var threadLinks = data.match(/class="titl.*<\/a>/g);
var threadLastPosts = data.match(/<a .*lastpostdate.*<\/a>/g);
var threadPrefixes = data.replace(/\n|\t|\b|\r/g, '').match(/id="thread_prefix.*\<\/span>/g);
var threadAuthors = data.match(/<a[\s\w\b].* popupctr.*<\/a>/g);
var threadTimes = data.match(/<dd>.*<\/span>/g);
} catch (error) {
console.log("[ERROR] Error in script: "+ error + ", lineNumber, "+error.lineNumber+", loader: " + loader.responseURL);
loaded++;
return;
}

for (var i = 0; i < threadTimes.length; i++) {
if (threadTimes.match(/"time"/) === null) {
threadTimes.splice(i, 1);
i--;
}
}

var forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.id
if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

var htmlData = '<div class="ngbSubloadDiv ' + forumId +'" style="clear: both; display: inline-block; width: 100%; margin: 10px 0px 10px 20px;">';

if ((!useGMinsteadOfCookies && document.cookie.indexOf("subload_"+ forumId +"=true") == -1) || (useGMinsteadOfCookies && GM_getValue("subload_"+forumId) == "false")) {
loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+ loader.index +'" style="clear:both; float: right; margin-top: 15px;">Add to subload</button></div>';
loaded++;

checkLoad();
return;
}


if (threadLinks.length !== 0) {
try {
var threadTitle = "";
var threadUrl = '';
var threadAuthor = '';
var threadAuthorId = 0;
var threadTime = '';
var threadId = "";
var lastThreadPrefix = 0;

var now = new Date();
var offset = 0;
var offsetUser = Math.abs(threadAuthors.length - threadLinks.length);

for (var x = 0; x < 8; x++) {
if (offset + x + offsetUser == threadAuthors.length || offset + x == threadLinks.length || offset + x == threadTimes.length) {
break;
}

threadTitle = threadLinks[x + offset].match(/">.*<\/a>/g)[0];
threadTitle = threadTitle.substring(2, threadTitle.length-4);
threadUrl = threadLastPosts[x + offset].match(/href="threads[\s\wäöüÄÖÜ\\\/\#\?\+\-\_\=\(\)\[\]]*/g)[0];
threadUrl = threadUrl.substr(6, threadUrl.length - 1);
threadAuthor = threadAuthors[x + offset + offsetUser].match(/<strong\>[\s\w\däöüÄÖÜ\-\\\\/_\(\)\[\]].*<\/strong>/g)[0];
threadAuthor = threadAuthor.substring(8,threadAuthor.length-9);
threadAuthorId = threadAuthors[x + offset].match(/members\/[0-9]*\-/g)[0];
threadAuthorId.substring(7, threadAuthorId.length);
threadTime = threadTimes[x + offset].replace(/<dd>|<span class="time">|<\/span>/g, '');
threadId = threadLinks[x + offset].match(/href="threads\/[0-9]*/g)[0];
threadId = threadId.substring(14, threadId.length);

if (threadTime.indexOf("Heute,") === -1 && threadTime.indexOf("Gestern,") === -1) {
var timeDate = threadTime.match(/[0-9].?/g);
var dateObj = new Date();
dateObj.setDate(parseInt(timeDate[0]));
dateObj.setMonth(parseInt(timeDate[1])-1);
dateObj.setFullYear(parseInt("20"+timeDate[2]));
dateObj.setHours(parseInt(timeDate[3]));
dateObj.setMinutes(parseInt(timeDate[4]));
dateObj.setSeconds(0);
dateObj.setMilliseconds(0);
if (dateObj.getTime() < now - ((3600 * 1000) * 24 * 30)) { // 30 - Anzahl der Tage die Themen alt sein duerfen
offset++;
x--;
continue;
}
}

var prefix = "";
if (threadPrefixes !== null) {
for (var i = lastThreadPrefix; i < threadPrefixes.length; ++i) {
if (threadPrefixes.indexOf(threadId) != -1) {
lastThreadPrefix = i;
prefix = threadPrefixes.match(/>[\s\w\b\-\_\(\)\[\]äöüÄÖÜ\:\,\;\#\+\*\&\/]*<\/span>/g)[0].trimRight();
prefix = prefix.substring(1, prefix.length-7);
}
}
}

if (prefix != "") {
htmlData += '<span style="clear: both; float:left;"><i>' + prefix + '</i> <a href="https://ngb.to/' + threadUrl + '" target="_blank">' + threadTitle + '</a></span>';
} else {
htmlData += '<a style="clear: left; float: left;" href="https://ngb.to/' + threadUrl + '" target="_blank">' + threadTitle + '</a>';
}

htmlData += '<p style="display: block; text-align: right; margin-left: 10%;">[ <a href="https://ngb.to/members/'+threadAuthorId+threadAuthor+'">' + threadAuthor + '</a>, ' + threadTime + ' Uhr ]</p>';
}

loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+loader.index+'" style="clear:both; float: right; margin-top: 15px;">Remove of subload</button></div>';
loaded++;
checkLoad();

} catch (error) {
console.log("[ERROR] Error in script: "+ error + ", lineNumber, "+error.lineNumber+", loader: " + loader.responseURL);
}
}

} else if (loader.readyState == 4) {
console.log("[ERROR] Loader status: " + loader.responseURL + " : (" + loader.status + ") "+ loader.statusText);
loaded++;
checkLoad();
}

return;
}

function ajaxLoader(url, index) {
var loader = new XMLHttpRequest();
loader.addEventListener('readystatechange', loaderChangeStatus);
loader.parent = boardLinks[index].parentNode.parentNode;
loader.index = index;

var forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.id;
if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

if ((!useGMinsteadOfCookies && document.cookie.indexOf("subload_"+ forumId +"=true") == -1) || (useGMinsteadOfCookies && GM_getValue("subload_"+forumId) == "false")) {
var htmlData = '<div class="ngbSubloadDiv ' + forumId +'" style="clear: both; display: inline-block; width: 100%; margin: 10px 0px 10px 20px;">';
loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+loader.index+'" style="clear:both; float: right; margin-top: 15px;">Add to subload</button></div>';
loaded++;
checkLoad();
return;
}

loader.open('GET', 'https://ngb.to/' + url.replace("http:\/\/", "https:\/\/"), true);
loader.send();
return;
}

boardLinks = document.querySelectorAll('h2.forumtitle');
for (var i = 0; i < boardLinks.length; ++i) {
var forumId = boardLinks.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;

if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = boardLinks.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

if (useGMinsteadOfCookies && GM_getValue("subload_"+forumId) != "true" && GM_getValue("subload_"+forumId) != "false") {
GM_setValue("subload_"+forumId, "false");
} else if (document.cookie.indexOf("subload_"+ forumId +"=true") == -1 && document.cookie.indexOf("subload_"+ forumId +"=false") == -1) {
document.cookie = "subload_"+ forumId +"=false";
}
}

// Check for existing subload main cookies
var subLoadOn = true;
var buttonsOn = true;
if (useGMinsteadOfCookies) {
if (GM_getValue("subload_switch") != "on" && GM_getValue("subload_switch") != "off") {
GM_setValue("subload_switch", "on");
} else if (GM_getValue("subload_switch") != "on") {
subLoadOn = false;
}

if (GM_getValue("subload_switch_buttons") != "on" && GM_getValue("subload_switch_buttons") != "off") {
GM_setValue("subload_switch_buttons", "on");
} else if (GM_getValue("subload_switch_buttons") != "on") {
buttonsOn = false;
}
} else {
if (document.cookie.indexOf("subload_switch=on") == -1 && document.cookie.indexOf("subload_switch=off") == -1) {
document.cookie = "subload_switch=on";
} else if (document.cookie.indexOf("subload_switch=on") == -1) {
subLoadOn = false;
}

if (document.cookie.indexOf("subload_switch_buttons=on") == -1 && document.cookie.indexOf("subload_switch_buttons=off") == -1) {
document.cookie = "subload_switch_buttons=on";
} else if (document.cookie.indexOf("subload_switch_buttons=on") == -1) {
buttonsOn = false;
}
}

if (subLoadOn) {
for (var i = 0; i < boardLinks.length; ++i) {
var hrefLink = boardLinks.innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, i);
}
} else {
var subLoadStatus = "off";
var subLoadText = "an";

var buttonStatus = "off";
var buttonText = "an";

if (subLoadOn) {
subLoadStatus = "on";
subLoadText = "aus";
}

if (buttonsOn) {
buttonStatus = "on";
buttonText = "aus";
}

var subMenu = document.querySelector("div.breadcrumb > ul");
if (document.getElementById("ngb_subload_switch") === null) {
subMenu.innerHTML += '<li><div style="float: right;"> \
<button id="ngb_subload_switch" data-status="'+ subLoadStatus +'" style="margin-right: 10px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl ['+ subLoadText +']</button> \
<button id="ngb_subload_switch_buttons" data-status="'+ buttonStatus +'" style="cursor: pointer; text-decoration: none;" title="NGB Subload Buttons umschalten">NGB-Sl Buttons ['+ buttonText +']</button></div></li>';
document.getElementById("ngb_subload_switch").addEventListener("click", toggleVisibility, true);
document.getElementById("ngb_subload_switch_buttons").addEventListener("click", toggleButtons, true);
}
}
[/src]
 
Zuletzt bearbeitet:

theSplit

1998
Veteran Barkeeper

Registriert
3 Aug. 2014
Beiträge
28.577
  • Thread Starter Thread Starter
  • #19
Update 1.2.5 (Bugfix)

- Waren Themen in einem Forum "verschoben", sind die Benutzer um eine Stelle verrutscht - dies ist nun behoben (dies könnte auch bereits gemeldete Probleme beheben mit den Nicknames beheben)
- Verschobene Themen haben keine Information zum letzten Benutzer des Themas, also werden diese korrekterweise nicht angezeigt
- Themen mit "ß" werden nun auch korrekt eingelesen (Update 1)
- Themen mit "!" werden nun auch korrekt eingelesen (Update 2)


[src=javascript]// ==UserScript==
// @name NGB Subloader
// @namespace ngb_subload
// @description NGB Subloader
// @include https://ngb.to/
// @include https://ngb.to/#*
// @include https://ngb.to/forum*
// @version 1.2.5
// @author theSplit
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==



// Change either to: true OR false ---- in order to use OR not to use GM_setValue and GM_getValue with SQLite as storage out side the cookies, defaults: true
var useGMinsteadOfCookies = true;

// Dont change this
var loaded = 0;
var hasLoaded = false;
var boardLinks;


function toggleVisibility(event) {
var ngbSubloadDivs = document.getElementsByClassName("ngbSubloadDiv");

var show = "inline-block";
if (event.target.dataset.status == "on") {
show = "none";
event.target.dataset.status = "off";
event.target.innerHTML = "NGB-Sl [an]";
if (useGMinsteadOfCookies) {
GM_setValue("subload_switch", "off");
} else {
document.cookie = "subload_switch=off";
}

} else {
event.target.dataset.status = "on";
event.target.innerHTML = "NGB-Sl [aus]";
if (useGMinsteadOfCookies) {
GM_setValue("subload_switch", "on");
} else {
document.cookie = "subload_switch=on";
}
}

for (var i = 0; i < ngbSubloadDivs.length; ++i) {
ngbSubloadDivs.style.display = show;
}

if (!hasLoaded) {
for (var i = 0; i < boardLinks.length; ++i) {
var hrefLink = boardLinks.innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, i);
}
}

return false;
}

function toggleButtons(event) {
var ngbSubloadToggles = document.getElementsByClassName("subLoadtoggleForum");

var show = "inline-block";
if (event.target.dataset.status == "on") {
show = "none";
event.target.dataset.status = "off";
event.target.innerHTML = "NGB-Sl Buttons [an]";

if (useGMinsteadOfCookies) {
GM_setValue("subload_switch_buttons", "off");
} else {
document.cookie = "subload_switch_buttons=off";
}
} else {
event.target.dataset.status = "on";
event.target.innerHTML = "NGB-Sl Buttons [aus]";

if (useGMinsteadOfCookies) {
GM_setValue("subload_switch_buttons", "on");
} else {
document.cookie = "subload_switch_buttons=on";
}
}

for (var i = 0; i < ngbSubloadToggles.length; ++i) {
ngbSubloadToggles.style.display = show;
}

return false;
}


function toggleSubLoad(event) {
var forumId = event.target.dataset.name;
if (useGMinsteadOfCookies) {
if (GM_getValue("subload_"+ forumId) == "true") {
GM_setValue("subload_"+ forumId, "false");
} else {
GM_setValue("subload_"+ forumId, "true");
}
} else {
if (document.cookie.indexOf("subload_"+ forumId +"=true") != -1) {
document.cookie = "subload_"+forumId+"=false";
} else {
document.cookie = "subload_"+forumId+"=true";
}
}

var oldData = document.querySelector("div.ngbSubloadDiv."+forumId);
oldData.parentNode.removeChild(oldData);
loaded--;

boardLinks = document.querySelectorAll('h2.forumtitle');
var index = parseInt(event.target.dataset.index);
var hrefLink = boardLinks[index].innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, index);
}

function checkLoad() {
if (loaded >= boardLinks.length-2) {

var subLoadStatus = "off";
var subLoadText = "an";

var buttonStatus = "off";
var buttonText = "an";

if ((!useGMinsteadOfCookies && document.cookie.indexOf("subload_switch=on") != -1) || (useGMinsteadOfCookies && GM_getValue("subload_switch") == "on")) {
subLoadStatus = "on";
subLoadText = "aus";
}

if ((!useGMinsteadOfCookies && document.cookie.indexOf("subload_switch_buttons=on") != -1) || (useGMinsteadOfCookies && GM_getValue("subload_switch_buttons") == "on")) {
buttonStatus = "on";
buttonText = "aus";
}

var subMenu = document.querySelector("div.breadcrumb > ul");
if (document.getElementById("ngb_subload_switch") === null) {
subMenu.innerHTML += '<li><div style="float: right;"> \
<button id="ngb_subload_switch" data-status="'+ subLoadStatus +'" style="margin-right: 10px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl ['+ subLoadText +']</button> \
<button id="ngb_subload_switch_buttons" data-status="'+ buttonStatus +'" style="cursor: pointer; text-decoration: none;" title="NGB Subload Buttons umschalten">NGB-Sl Buttons ['+ buttonText +']</button></div></li>';
document.getElementById("ngb_subload_switch").addEventListener("click", toggleVisibility, true);
document.getElementById("ngb_subload_switch_buttons").addEventListener("click", toggleButtons, true);
}

var displayStr = "inline-block";
if ((!useGMinsteadOfCookies && document.cookie.indexOf("subload_switch_buttons=off") != -1) || (useGMinsteadOfCookies && GM_getValue("subload_switch_buttons") == "off")) {
displayStr = "none";
}

var toggleButtonsArray = document.getElementsByClassName("subLoadtoggleForum");
for (var i = 0; i < toggleButtonsArray.length; ++i) {
toggleButtonsArray.addEventListener("click", toggleSubLoad, true);
toggleButtonsArray.style.display = displayStr;
}

hasLoaded = true;
}
}

function loaderChangeStatus(loader) {
loader = loader.target;
if (loader.readyState == 4 && loader.status == 200) {
data = loader.responseText.replace(/\n|\t|\b/g, '');

try {
var threadLinks = data.match(/class="title.*<\/a>/g);
var threadLastPosts = data.match(/<a .*lastpostdate.*\<\/a\>/g);
var threadPrefixes = data.replace(/\n|\t|\b|\r/g, '').match(/id="thread_prefix.*\<\/span\>/g);
var threadAuthors = data.match(/<a[\s\w\b].* popupctr.*\<\/a\>/g);
var threadTimes = data.match(/<dd>.*class="time".*\<\/span\>/g);
} catch (error) {
console.log("[ERROR] Error in script: "+ error + ", lineNumber, "+error.lineNumber+", loader: " + loader.responseURL);
loaded++;
return;
}

for (var i = 0; i < threadTimes.length; i++) {
if (threadTimes.match(/"time"/) === null) {
threadTimes.splice(i, 1);
i--;
}
}

var forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.id
if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

var htmlData = '<div class="ngbSubloadDiv ' + forumId +'" style="clear: both; display: inline-block; width: 100%; margin: 10px 0px 10px 20px;">';

if ((!useGMinsteadOfCookies && document.cookie.indexOf("subload_"+ forumId +"=true") == -1) || (useGMinsteadOfCookies && GM_getValue("subload_"+forumId) == "false")) {
loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+ loader.index +'" style="clear:both; float: right; margin-top: 15px;">Add to subload</button></div>';
loaded++;

checkLoad();
return;
}


if (threadLinks.length !== 0) {
try {
var threadsMoved = 0;

if (threadPrefixes !== null) {
for (var i = 0; i < threadPrefixes.length; ++i) {
if (threadPrefixes.indexOf("Verschoben") != -1) {
++threadsMoved;
}
}
}

var threadTitle = "";
var threadUrl = '';
var threadAuthor = '';
var threadAuthorId = 0;
var threadTime = '';
var threadId = "";
var lastThreadPrefix = 0;
var lastMovedThread = 0;

var now = new Date();
var offset = 0;
var offsetUser = Math.abs(threadAuthors.length - threadLinks.length) - threadsMoved;

for (var x = 0; x < 8; x++) {
if (offset + x + offsetUser == threadAuthors.length || offset + x == threadLinks.length || offset + x == threadTimes.length) {
break;
}

threadTitle = threadLinks[x + offset].match(/\"\>.*\<\/a\>/g)[0];
threadTitle = threadTitle.substring(2, threadTitle.length-4);
threadUrl = threadLastPosts[x + offset].match(/href="threads[\s\wäöüÄÖÜ\\\/\ß\#\?\+\-\_\=\(\)\[\]\!\%\$]*/g)[0];
threadUrl = threadUrl.substring(6, threadUrl.length);
threadId = threadLinks[x + offset].match(/href="threads\/[0-9]*/g)[0];
threadId = threadId.substring(14, threadId.length);
threadTime = threadTimes[x + offset].replace(/\<dd\>|\<span class\=\"time\"\>|<\/span>/g, '');
threadAuthor = threadAuthors[x + offset + offsetUser].match(/\<strong\>.*<\/strong>/g)[0];
threadAuthor = threadAuthor.substring(8,threadAuthor.length-9);
threadAuthorId = threadAuthors[x + offset].match(/members\/[0-9]*\-/g)[0];
threadAuthorId.substring(7, threadAuthorId.length);

if (threadTime.indexOf("Heute,") === -1 && threadTime.indexOf("Gestern,") === -1) {
var timeDate = threadTime.match(/[0-9].?/g);
var dateObj = new Date();
dateObj.setDate(parseInt(timeDate[0]));
dateObj.setMonth(parseInt(timeDate[1])-1);
dateObj.setFullYear(parseInt("20"+timeDate[2]));
dateObj.setHours(parseInt(timeDate[3]));
dateObj.setMinutes(parseInt(timeDate[4]));
dateObj.setSeconds(0);
dateObj.setMilliseconds(0);
if (dateObj.getTime() < now - ((3600 * 1000) * 24 * 30)) { // 30 - Anzahl der Tage die Themen alt sein duerfen
offset++;
x--;
continue;
}
}

var prefix = "";
if (threadPrefixes !== null) {
for (var i = lastThreadPrefix; i < threadPrefixes.length; ++i) {
if (threadPrefixes.indexOf(threadId+'"') != -1) {
lastThreadPrefix = i+1;
prefix = threadPrefixes.match(/>[\s\w\b\-\_\(\)\[\]äöüÄÖÜ\:\,\;\#\+\*\&\/]*<\/span>/g)[0].trimRight();
prefix = prefix.substring(1, prefix.length-7);
}
}
}

if (prefix != "") {
htmlData += '<span style="clear: both; float:left;"><i>' + prefix + '</i> <a href="https://ngb.to/' + threadUrl + '" target="_blank">' + threadTitle + '</a></span>';
} else {
htmlData += '<a style="clear: left; float: left;" href="https://ngb.to/' + threadUrl + '" target="_blank">' + threadTitle + '</a>';
}

if (prefix.indexOf("Verschoben") == -1) {
htmlData += '<p style="display: block; text-align: right; margin-left: 10%;">[ <a href="https://ngb.to/members/'+threadAuthorId+threadAuthor+'">' + threadAuthor + '</a>, ' + threadTime + ' Uhr ]</p>';
} else {
htmlData += '<p style="display: block; text-align: right; margin-left: 10%;">[ ' + threadTime + ' Uhr ]</p>';
}
}

loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+loader.index+'" style="clear:both; float: right; margin-top: 15px;">Remove of subload</button></div>';
loaded++;
checkLoad();

} catch (error) {
console.log("[ERROR] Error in script: "+ error + ", lineNumber, "+error.lineNumber+", loader: " + loader.responseURL);
}
}

} else if (loader.readyState == 4) {
console.log("[ERROR] Loader status: " + loader.responseURL + " : (" + loader.status + ") "+ loader.statusText);
loaded++;
checkLoad();
}

return;
}

function ajaxLoader(url, index) {
var loader = new XMLHttpRequest();
loader.addEventListener('readystatechange', loaderChangeStatus);
loader.parent = boardLinks[index].parentNode.parentNode;
loader.index = index;

var forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.id;
if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

if ((!useGMinsteadOfCookies && document.cookie.indexOf("subload_"+ forumId +"=true") == -1) || (useGMinsteadOfCookies && GM_getValue("subload_"+forumId) == "false")) {
var htmlData = '<div class="ngbSubloadDiv ' + forumId +'" style="clear: both; display: inline-block; width: 100%; margin: 10px 0px 10px 20px;">';
loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="'+forumId+'" data-index="'+loader.index+'" style="clear:both; float: right; margin-top: 15px;">Add to subload</button></div>';
loaded++;
checkLoad();
return;
}

loader.open('GET', 'https://ngb.to/' + url.replace("http:\/\/", "https:\/\/"), true);
loader.send();
return;
}

boardLinks = document.querySelectorAll('h2.forumtitle');
for (var i = 0; i < boardLinks.length; ++i) {
var forumId = boardLinks.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;

if (window.location.pathname.indexOf("/forums/") != -1) {
forumId = boardLinks.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;
}

if (useGMinsteadOfCookies && GM_getValue("subload_"+forumId) != "true" && GM_getValue("subload_"+forumId) != "false") {
GM_setValue("subload_"+forumId, "false");
} else if (document.cookie.indexOf("subload_"+ forumId +"=true") == -1 && document.cookie.indexOf("subload_"+ forumId +"=false") == -1) {
document.cookie = "subload_"+ forumId +"=false";
}
}

// Check for existing subload main cookies
var subLoadOn = true;
var buttonsOn = true;
if (useGMinsteadOfCookies) {
if (GM_getValue("subload_switch") != "on" && GM_getValue("subload_switch") != "off") {
GM_setValue("subload_switch", "on");
} else if (GM_getValue("subload_switch") != "on") {
subLoadOn = false;
}

if (GM_getValue("subload_switch_buttons") != "on" && GM_getValue("subload_switch_buttons") != "off") {
GM_setValue("subload_switch_buttons", "on");
} else if (GM_getValue("subload_switch_buttons") != "on") {
buttonsOn = false;
}
} else {
if (document.cookie.indexOf("subload_switch=on") == -1 && document.cookie.indexOf("subload_switch=off") == -1) {
document.cookie = "subload_switch=on";
} else if (document.cookie.indexOf("subload_switch=on") == -1) {
subLoadOn = false;
}

if (document.cookie.indexOf("subload_switch_buttons=on") == -1 && document.cookie.indexOf("subload_switch_buttons=off") == -1) {
document.cookie = "subload_switch_buttons=on";
} else if (document.cookie.indexOf("subload_switch_buttons=on") == -1) {
buttonsOn = false;
}
}

if (subLoadOn) {
for (var i = 0; i < boardLinks.length; ++i) {
var hrefLink = boardLinks.innerHTML.match(/href=".*"/g) [0];
var url = hrefLink.substring(6, hrefLink.length - 1);
ajaxLoader(url, i);
}
} else {
var subLoadStatus = "off";
var subLoadText = "an";

var buttonStatus = "off";
var buttonText = "an";

if (subLoadOn) {
subLoadStatus = "on";
subLoadText = "aus";
}

if (buttonsOn) {
buttonStatus = "on";
buttonText = "aus";
}

var subMenu = document.querySelector("div.breadcrumb > ul");
if (document.getElementById("ngb_subload_switch") === null) {
subMenu.innerHTML += '<li><div style="float: right;"> \
<button id="ngb_subload_switch" data-status="'+ subLoadStatus +'" style="margin-right: 10px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl ['+ subLoadText +']</button> \
<button id="ngb_subload_switch_buttons" data-status="'+ buttonStatus +'" style="cursor: pointer; text-decoration: none;" title="NGB Subload Buttons umschalten">NGB-Sl Buttons ['+ buttonText +']</button></div></li>';
document.getElementById("ngb_subload_switch").addEventListener("click", toggleVisibility, true);
document.getElementById("ngb_subload_switch_buttons").addEventListener("click", toggleButtons, true);
}
}[/src]
 
Zuletzt bearbeitet:

theSplit

1998
Veteran Barkeeper

Registriert
3 Aug. 2014
Beiträge
28.577
  • Thread Starter Thread Starter
  • #20
Update auf 1.2.6

- Cookie Speicherung komplett deaktivert, nun werden nur noch die GM.get/.set verwendet um Einstellungen zu speichern
- Aktualisiert auf Greasemonkey GM.setValue and GM.getValue Funktionen, auch in Hinblick das Werte als Promises zurückgeliefert werden
- Fehler behoben das Benutzernamen/Zeiten/Titel in Foren mit Unterforen falsch dargestellt werden
- Hinzugefügt das Postings und Themen von Unterforen, so fern das letzte, im Hauptforum sichtbare, Posting nicht älter als 30 Tage alt ist, mit angezeigt werden
- Fehler behoben das Zeitangaben falsche Zeiten verursachen
- URLs mit Parametern/Ankern hinzugefügt die das Skript hier im Forum auslösen können....
- Behoben, das verschobene Themen die anzeige Fehlerhaft gemacht haben
- Regex etwas weiter angepasst, was in einem Regex weniger endete
- Code Cleanups

Viel Spaß damit! :coffee:


Greasemonkey Code:

[src=javascript]
// ==UserScript==
// @name NGB Subloader
// @namespace ngb_subload
// @description NGB Subloader
// @include https://ngb.to/
// @include https://ngb.to/?*
// @include https://ngb.to/#*
// @include https://ngb.to/forum*
// @version 1.2.6
// @author theSplit
// @grant GM.getValue
// @grant GM.setValue
// ==/UserScript==

var loaded = 0
var hasLoaded = false
var boardLinks

async function toggleButtons (event) {
var ngbSubloadToggles = document.getElementsByClassName('subLoadtoggleForum')

var show = 'inline-block'
if (event.target.dataset.status === 'on') {
show = 'none'
event.target.dataset.status = 'off'
event.target.innerHTML = 'NGB-Sl Buttons [an]'
await GM.setValue('subload_switch_buttons', 'off')
} else {
event.target.dataset.status = 'on'
event.target.innerHTML = 'NGB-Sl Buttons [aus]'
await GM.setValue('subload_switch_buttons', 'on')
}

for (var i = 0; i < ngbSubloadToggles.length; ++i) {
ngbSubloadToggles.style.display = show
}

return false
}

async function toggleSubLoad (event) {
var forumId = event.target.dataset.name
var forumState = await GM.getValue('subload_' + forumId, 'false') === 'true' ? 'false' : 'true'
await GM.setValue('subload_' + forumId, forumState)

var oldData = document.querySelector('div.ngbSubloadDiv.' + forumId)
oldData.parentNode.removeChild(oldData)
loaded--

boardLinks = document.querySelectorAll('h2.forumtitle')
var index = parseInt(event.target.dataset.index)
var hrefLink = boardLinks[index].innerHTML.match(/href=".*"/g)[0]
var url = hrefLink.substring(6, hrefLink.length - 1)
ajaxLoader(url, index)
}

async function checkLoad () {
if (loaded >= boardLinks.length - 2) {
var subLoadStatus = 'off'
var subLoadText = 'an'

var buttonStatus = 'off'
var buttonText = 'an'

if (await GM.getValue('subload_switch', 'on') === 'on') {
subLoadStatus = 'on'
subLoadText = 'aus'
}

if (await GM.getValue('subload_switch_buttons', 'on') === 'on') {
buttonStatus = 'on'
buttonText = 'aus'
}

var subMenu = document.querySelector('div.breadcrumb > ul')
if (document.getElementById('ngb_subload_switch') === null) {
subMenu.innerHTML += '<li><div style="float: right;"><button id="ngb_subload_switch" data-status="' + subLoadStatus + '" style="margin-right: 10px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl [' + subLoadText + ']</button><button id="ngb_subload_switch_buttons" data-status="' + buttonStatus + '" style="cursor: pointer; text-decoration: none;" title="NGB Subload Buttons umschalten">NGB-Sl Buttons [' + buttonText + ']</button></div></li>'
document.getElementById('ngb_subload_switch').addEventListener('click', toggleVisibility, true)
document.getElementById('ngb_subload_switch_buttons').addEventListener('click', toggleButtons, true)
}

var displayStr
if (await GM.getValue('subload_switch_buttons', 'on') === 'off') displayStr = 'none'
else displayStr = 'inline-block'

var toggleButtonsList = document.querySelectorAll('.subLoadtoggleForum')
for (var button of toggleButtonsList) {
button.addEventListener('click', toggleSubLoad, true)
button.style.display = displayStr
}

hasLoaded = true
}
}

async function loaderChangeStatus (loader) {
loader = loader.target
if (loader.readyState === 4 && loader.status === 200) {
var data = loader.responseText.replace(/\n|\t|\b/g, '')
var i = 0

try {
var threadLinks = data.match(/<a.*(id|class)="(thread_title|threadtitle).*<\/a>/g)
var threadPrefixes = data.replace(/\n|\t|\b|\r/g, '').match(/id="thread_prefix.*<\/span>/g)
var threadAuthors = data.match(/<a.*username.*popupctr.*<\/a>/g)
var threadTimes = data.match(/(<dd>|<p).*class="time".*<\/span>/g)
var threadTitleData = data.replace(/\n|\t|\b|\r/g, '').match(/class="threadtitle".*<\/a>/g)
} catch (error) {
console.log('[ERROR] Error in script: ' + error + ', lineNumber, ' + error.lineNumber + ', loader: ' + loader.responseURL)
loaded++
return
}

for (i = 0; i < threadTimes.length; i++) {
if (threadTimes.match(/"time"/) === null) {
threadTimes.splice(i, 1)
i--
}
}

var forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.id
if (window.location.pathname.indexOf('/forums/') !== -1) {
forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.parentNode.id
}

var htmlData = '<div class="ngbSubloadDiv ' + forumId + '" style="clear: both; display: inline-block; width: 100%; margin: 10px 0px 10px 20px;">'

if (await GM.getValue('subload_' + forumId, 'true') === 'false') {
loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="' + forumId + '" data-index="' + loader.index + '" style="clear:both; float: right; margin-top: 15px;">Add to subload</button></div>'
loaded++

checkLoad()
return
}

if (threadLinks.length !== 0) {
try {
var threadsMoved = []

if (threadPrefixes !== null) {
for (i = 0; i < threadLinks.length; ++i) {
if (threadTitleData !== undefined && threadTitleData.indexOf('id="thread_prefix') !== -1 && threadTitleData.indexOf('Verschoben:') !== -1) threadsMoved.push(i)
}
}

var threadTitle = ''
var threadUrl = ''
var threadAuthor = ''
var threadAuthorId = 0
var threadTime = ''
var threadId = ''
var lastThreadPrefix = 0

var now = new Date()

var offset = 0

for (var x = 0; x < 8; x++) {
if (offset + x === threadLinks.length || offset + x === threadTimes.length) {
break
}

threadTitle = threadLinks[x + offset].match(/">.*<\/a>/g)[0]
threadTitle = threadTitle.substring(2, threadTitle.length - 4)
threadUrl = threadLinks[x + offset].match(/href="threads[\s\wäöüÄÖÜ\/ß#?+\-_=()\[\]!\*%$]*/g)[0]
threadUrl = threadUrl.substring(6, threadUrl.length)
threadId = threadLinks[x + offset].match(/href="threads\/[0-9]*/g)[0]
threadId = threadId.substring(14, threadId.length)

if (threadsMoved.indexOf(x + offset) === -1) {
threadAuthor = threadAuthors[x + offset].match(/<strong>.*<\/strong>/g)[0]
threadAuthor = threadAuthor.substring(8, threadAuthor.length - 9)
threadAuthorId = threadAuthors[x + offset].match(/members\/[0-9]*/g)[0]
threadAuthorId.substring(7, threadAuthorId.length)

if (threadTimes !== null) {
threadTime = threadTimes[x + offset].replace(/<dd>|<span class="time">|<p class="lastpostdate">|<\/span>|<\/p>/g, '')

if (threadTime.indexOf('Heute,') === -1 && threadTime.indexOf('Gestern,') === -1) {
var timeDate = threadTime.match(/[0-9].?/g)
var dateObj = new Date()
dateObj.setTime(0)
dateObj.setDate(parseInt(timeDate[0]))
dateObj.setMonth(parseInt(timeDate[1]) - 1)
dateObj.setFullYear(parseInt('20' + timeDate[2]))
dateObj.setHours(parseInt(timeDate[3]))
dateObj.setMinutes(parseInt(timeDate[4]))
dateObj.setSeconds(0)
dateObj.setMilliseconds(0)

if (dateObj.getTime() < now.getTime() - ((3600 * 1000) * 24 * 30)) { // 30 - Anzahl der Tage die Themen alt sein duerfen
offset++
x--
continue
}
}
}
} else {
++offset;
}

var prefix = ''
if (threadPrefixes !== null) {
for (i = lastThreadPrefix; i < threadPrefixes.length; ++i) {
if (threadPrefixes.indexOf(threadId + '"') !== -1) {
lastThreadPrefix = i + 1
prefix = threadPrefixes.match(/>[\s\w\b\-_()\[\]äöüÄÖÜ:,;#+*&\/]*<\/span>/g)[0].trimRight()
prefix = prefix.substring(1, prefix.length - 7)
}
}
}

if (prefix !== '') {
htmlData += '<span style="clear: both; float:left;"><i>' + prefix + '</i> <a href="https://ngb.to/' + threadUrl + '" target="_blank">' + threadTitle + '</a></span>'
} else {
htmlData += '<a style="clear: left; float: left;" href="https://ngb.to/' + threadUrl + '" target="_blank">' + threadTitle + '</a>'
}

if (prefix.indexOf('Verschoben') === -1) {
if (threadTime != '') {
htmlData += '<p style="display: block; text-align: right; margin-left: 10%;">[ <a href="https://ngb.to/members/' + threadAuthorId + '-' + threadAuthor + '">' + threadAuthor + '</a>, ' + threadTime + ' Uhr ]</p>'
} else {
htmlData += '<p style="display: block; text-align: right; margin-left: 10%;">[ <a href="https://ngb.to/members/' + threadAuthorId + '-' + threadAuthor + '">' + threadAuthor + '</a> ]</p>'
}
} else {
if (threadTime != '') htmlData += '<p style="display: block; text-align: right; margin-left: 10%;">[ ' + threadTime + ' Uhr ]</p>'
}
}

loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="' + forumId + '" data-index="' + loader.index + '" style="clear:both; float: right; margin-top: 15px;">Remove of subload</button></div>'
loaded++
checkLoad()
} catch (error) {
console.log('[ERROR] Error in script: ' + error + ', lineNumber, ' + error.lineNumber + ', loader: ' + loader.responseURL)
}
}
} else if (loader.readyState === 4) {
console.log('[ERROR] Loader status: ' + loader.responseURL + ' : (' + loader.status + ') ' + loader.statusText)
loaded++
checkLoad()
}
}

async function ajaxLoader (url, index) {
var loader = new XMLHttpRequest()
loader.addEventListener('readystatechange', loaderChangeStatus)
loader.parent = boardLinks[index].parentNode.parentNode
loader.index = index

var forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.id
if (window.location.pathname.indexOf('/forums/') !== -1) forumId = loader.parent.parentNode.parentNode.parentNode.parentNode.parentNode.id

if (await GM.getValue('subload_' + forumId, 'false') === 'false') {
var htmlData = '<div class="ngbSubloadDiv ' + forumId + '" style="clear: both; display: inline-block; width: 100%; margin: 10px 0px 10px 20px;">'
loader.parent.innerHTML += htmlData + '<button class="subLoadtoggleForum" data-name="' + forumId + '" data-index="' + loader.index + '" style="clear:both; float: right; margin-top: 15px;">Add to subload</button></div>'
loaded++
checkLoad()
return
}

if (url.indexOf('https://ngb.to/') === -1) loader.open('GET', 'https://ngb.to/' + url.replace('http://', 'https://'))
else loader.open('GET', url.replace('http://', 'https://'))
loader.send()
}

async function toggleVisibility (event) {
var ngbSubloadDivs = document.querySelectorAll('.ngbSubloadDiv')

var show = 'inline-block'
if (event.target.dataset.status === 'on') {
show = 'none'
event.target.dataset.status = 'off'
event.target.innerHTML = 'NGB-Sl [an]'
await GM.setValue('subload_switch', 'off')
} else {
event.target.dataset.status = 'on'
event.target.innerHTML = 'NGB-Sl [aus]'
await GM.setValue('subload_switch', 'on')
}

for (var i = 0; i < ngbSubloadDivs.length; ++i) {
ngbSubloadDivs.style.display = show
}

if (!hasLoaded) {
for (i = 0; i < boardLinks.length; ++i) {
var hrefLink = boardLinks.innerHTML.match(/href=".*"/g)[0]
var url = hrefLink.substring(6, hrefLink.length - 1)
ajaxLoader(url, i)
}
}

return false
}

boardLinks = document.querySelectorAll('h2.forumtitle')

async function initFunc() {

for (var i = 0; i < boardLinks.length; ++i) {
var forumId = boardLinks.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id

if (window.location.pathname.indexOf('/forums/') !== -1) forumId = boardLinks.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id
if (await GM.getValue('subload_' + forumId, 'false') !== 'true') await GM.setValue('subload_' + forumId, 'false')
}

var subLoadOn = true
var buttonsOn = true

if (await GM.getValue('subload_switch', 'on') === 'off') subLoadOn = false
else await GM.setValue('subload_switch', 'on')

if (await GM.getValue('subload_switch_buttons', 'on') === 'off') buttonsOn = false
else await GM.setValue('subload_switch_buttons', 'on')

if (subLoadOn) {
for (var i = 0; i < boardLinks.length; ++i) {
var hrefLink = boardLinks.innerHTML.match(/href=".*"/g)[0]
var url = hrefLink.substring(6, hrefLink.length - 1)
ajaxLoader(url, i)
}
} else {
var subLoadStatus = 'off'
var subLoadText = 'an'

var buttonStatus = 'off'
var buttonText = 'an'

if (subLoadOn) {
subLoadStatus = 'on'
subLoadText = 'aus'
}

if (buttonsOn) {
buttonStatus = 'on'
buttonText = 'aus'
}

var subMenu = document.querySelector('div.breadcrumb > ul')
if (document.getElementById('ngb_subload_switch') === null) {
subMenu.innerHTML += '<li><div style="float: right;"><button id="ngb_subload_switch" data-status="' + subLoadStatus + '" style="margin-right: 10px; cursor: pointer; text-decoration: none;" title="NGB Subload umschalten">NGB-Sl [' + subLoadText + ']</button><button id="ngb_subload_switch_buttons" data-status="' + buttonStatus + '" style="cursor: pointer; text-decoration: none;" title="NGB Subload Buttons umschalten">NGB-Sl Buttons [' + buttonText + ']</button></div></li>'
document.getElementById('ngb_subload_switch').addEventListener('click', toggleVisibility, true)
document.getElementById('ngb_subload_switch_buttons').addEventListener('click', toggleButtons, true)
}
}
}


// ----------------------------------------------------------------------------------
initFunc()

[/src]
 
Zuletzt bearbeitet:
Oben