// ==UserScript== // @name SweClockers JavaScript sidladdare // @namespace hAPsdWxok4bTePK8JZdG // @author LemonIllusion // @version 2.0 // @match https://www.sweclockers.com/forum/trad/* // @match https://www.sweclockers.com/forum/post/* // @description Lägger till en knapp som läser in kommande inlägg utan uppdatering av sidan. // @downloadURL none // ==/UserScript== let nextURL, canLoad = false; function getHTML(url, callback) { let xhr = new XMLHttpRequest(); xhr.addEventListener("load", () => callback(xhr.responseXML)); xhr.open("GET", url); xhr.responseType = "document"; xhr.send(); } HTMLDocument.prototype.hasNextPage = function() { return this.getElementsByClassName("next-page").length !== 0 }; HTMLDocument.prototype.getNextPageURL = function() { return this.getElementsByClassName("next-page")[0].href }; HTMLDocument.prototype.prepareNextPage = function() { if (this.hasNextPage()) { nextURL = this.getNextPageURL(); nextButton.setText("Ladda fler inlägg"); nextButton.classList.add("clickable"); canLoad = true; } else { nextButton.setText("Det finns inga fler inlägg att ladda"); } } HTMLDocument.prototype.importPosts = function() { let forumPosts = this.getElementsByClassName("forumPosts")[0]; nextButton.parentNode.insertBefore(forumPosts, nextButton); for (let script of forumPosts.getElementsByTagName("script")) { eval(script.text); } } function loadNext() { if (canLoad) { canLoad = false; nextButton.classList.remove("clickable"); nextButton.setText("Laddar..."); getHTML(nextURL, function(doc) { doc.importPosts(); doc.prepareNextPage(); }); } } { let style = document.createElement('style'); document.head.appendChild(style); style.sheet.insertRule(".forumPosts {margin-bottom: 8px;}"); style.sheet.insertRule(".nextButton {margin-bottom: 16px; text-align: center;}"); style.sheet.insertRule(".nextButton.clickable {cursor: pointer}"); } let nextButton = document.createElement("div"); nextButton.className = "forumPost nextButton"; nextButton.innerHTML = '