Created
February 8, 2023 18:44
-
-
Save Kyiro/d524d314cf75d64cac3defc6cd1482df to your computer and use it in GitHub Desktop.
Makes your synergia.librus.pl experience faster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name SynergiaFast | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Makes your synergia.librus.pl experience faster | |
// @author Kyiro | |
// @match https://synergia.librus.pl/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=librus.pl | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
const cache = new Map(); | |
async function load(url) { | |
if (cache.has(url)) { | |
console.log(`${url} już załadowane`); | |
return; | |
} | |
const parser = new DOMParser(); | |
const response = await fetch(url).then(r => r.text()); | |
const resDocument = parser.parseFromString(response, "text/html"); | |
console.log(`Ładowanie ${url}`); | |
cache.set(url, resDocument.getElementById("body")); | |
} | |
function replaceAnchors() { | |
for (const anchor of document.getElementsByTagName("a")) { | |
const url = new String(anchor.href); | |
if (!anchor.href.startsWith("http")) continue; | |
anchor.href = "javascript:void(0)"; | |
anchor.onclick = () => load(url).then(() => switchTab(url)); | |
} | |
} | |
function switchTab(url) { | |
const body = document.getElementById("body"); | |
body.outerHTML = cache.get(url).outerHTML; | |
window.history.pushState({}, "", url); | |
replaceAnchors(); | |
removeExtensionWarning(); | |
} | |
function removeExtensionWarning() { | |
for (const scriptTag of document.getElementsByTagName("script")) { | |
if (scriptTag.innerHTML.includes("librusowy-asystent-ucznia")) { | |
console.log("Usunięto ogłoszenie o rozszerzeniach"); | |
scriptTag.remove(); | |
} | |
} | |
} | |
// Patches otworz_w_nowym_oknie | |
function patchNewWindow() { | |
if (typeof otworz_w_nowym_oknie == "undefined") { | |
console.error("otworz_w_nowym_oknie nie istnieje"); | |
return; | |
} | |
otworz_w_nowym_oknie = function (url) { | |
load(url).then(() => switchTab(url)); | |
} | |
} | |
window.addEventListener("load", () => { | |
cache.set(window.location.toString(), document.getElementById("body")); | |
patchNewWindow(); | |
replaceAnchors(); | |
removeExtensionWarning(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment