From a6f852361509a674d1e9746681c05455a92ddd50 Mon Sep 17 00:00:00 2001 From: Thorsten S Date: Tue, 14 Jun 2022 18:18:46 +0200 Subject: [PATCH] init --- dfde-singlepage.user.js | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 dfde-singlepage.user.js diff --git a/dfde-singlepage.user.js b/dfde-singlepage.user.js new file mode 100644 index 0000000..8558d69 --- /dev/null +++ b/dfde-singlepage.user.js @@ -0,0 +1,67 @@ +// ==UserScript== +// @name dfde-singlepage +// @namespace de.debianforum +// @version 0.1 +// @description View all pages of a thread on one page +// @author You +// @match https://debianforum.de/forum/viewtopic.php*t=* +// @icon https://www.google.com/s2/favicons?sz=64&domain=debianforum.de +// @grant none +// ==/UserScript== + +(function() { + 'use strict'; + const pages = [...document.querySelector(".pagination").querySelectorAll("li")] + .map((p) => parseInt(p.innerText)) + .filter(n => !isNaN(n)) + .slice(-1)[0]; + + const thread_id = window.location.search.match(/t=[0-9]+/); + const unsuitable = window.location.search.match(/p=[0-9]+|start=/); + + const pageBody = document.querySelector("#page-body"); + const pageBar = pageBody.querySelector(".action-bar.bar-bottom"); + + const myButton = document.createElement("li") + const myButton_a = document.createElement("a") + myButton_a.className = "button"; + myButton_a.innerText = "∞"; + + myButton.appendChild(myButton_a) + document.querySelector(".pagination ul").prepend(myButton); + + function clickit() { + if (unsuitable) { window.location.href= "https://debianforum.de/forum/viewtopic.php?" + thread_id; } + let promises = [] + + // async wrapper to fix the order of requests/posts + const fn = async() => { + for (var p=1; p nodelist.forEach(posts => posts.forEach(post => pageBody.insertBefore(post, pageBar)))); + } + fn(); + + document.querySelectorAll(".pagination li a").forEach((pg, idx) => { + if(idx > 0 && pg.innerHTML.match(/[0-9]+/)) + pg.style.backgroundColor = "#d70751"; + pg.style.color = "#fff"; + }) + } + myButton.addEventListener("click", clickit); +})(); + -- 2.39.2