|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +let url = document.location.toString(); |
| 4 | +let didInjectCssAlready = false; |
| 5 | + |
| 6 | +console.log("[Librus Enhancer] loading start", {readyState: document.readyState, url}); |
| 7 | +document.addEventListener('readystatechange', ev => { |
| 8 | + console.log("[Librus Enhancer] ready?", {readyState: document.readyState, url}); |
| 9 | + if (document.readyState !== 'complete') return; |
| 10 | + onDocumentReady(); |
| 11 | +}); |
| 12 | +if (document.readyState === 'complete') |
| 13 | + onDocumentReady(); // execute immediately |
| 14 | +setTimeout(() => modifyStuff(), 500); // just to make sure and catch the late loaded stuff |
| 15 | +setTimeout(() => modifyStuff(), 1500); // apparently the one above was not enough... |
| 16 | + |
| 17 | +// separated function in case I want to add something to run on document ready once |
| 18 | +function onDocumentReady() { |
| 19 | + modifyStuff(); |
| 20 | +} |
| 21 | + |
| 22 | +function modifyStuff() { |
| 23 | + |
| 24 | + //let date = new Date(); console.log("modifyStuff start"); |
| 25 | + $("#cookieBox").remove(); |
| 26 | + let css = ''; |
| 27 | + |
| 28 | + if (url.startsWith('https://portal.librus.pl/')) { |
| 29 | + |
| 30 | + $('.btn[href="https://konto.librus.pl/sklep"]').remove(); // make more space for button by removing bs |
| 31 | + let ad1 = $('.article-list').children()[0]; |
| 32 | + if (ad1 && ad1.classList && !ad1.classList.contains('row')) ad1.remove(); |
| 33 | + $('.article__container').has('.article__sponsored').remove(); |
| 34 | + //css += '.article__container--small { flex: 1; }'; // don't leave out weird blank spaces |
| 35 | + css += '.article__container { flex: 1; }'; // don't leave out weird blank spaces |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + if (url.startsWith('https://portal.librus.pl/rodzina') && url !== 'https://portal.librus.pl/rodzina/synergia/loguj') { |
| 40 | + |
| 41 | + if (!window.didInsertConvenientLoginButton) { |
| 42 | + let html = '<a class="btn btn-synergia-top btn-navbar" href="https://portal.librus.pl/rodzina/synergia/loguj">ZALOGUJ</a>'; |
| 43 | + if ($("a.btn-synergia-top:contains('LIBRUS Synergia')").after(html)) |
| 44 | + window.didInsertConvenientLoginButton = true; |
| 45 | + } |
| 46 | + |
| 47 | + } |
| 48 | + |
| 49 | + if (url === 'https://portal.librus.pl/rodzina/synergia/loguj') { |
| 50 | + $("#synergiaLogin").next().remove(); |
| 51 | + } |
| 52 | + |
| 53 | + if (url === 'https://portal.librus.pl/rodzina') { |
| 54 | + $('.row > div').not('.article__container').has("img[src*='librus_aplikacja_mobilna'").remove(); // inline ad |
| 55 | + $('.row > div').not('.article__container').has("img[src*='aplikacjamobilna'").remove(); // inline ad |
| 56 | + } |
| 57 | + |
| 58 | + if (url === 'https://portal.librus.pl/') { |
| 59 | + $('.widget-container--small').remove(); // right-side ad |
| 60 | + if (!window.didInsertMainPageDirectLoginButton) { |
| 61 | + let html = '<a class="btn btn-third btn-navbar" href="https://portal.librus.pl/rodzina/synergia/loguj" style="width: 130px;">ZALOGUJ OD RAZU</a>'; |
| 62 | + if ($("a.btn-third:contains('Zaloguj jako')").before(html)) |
| 63 | + window.didInsertMainPageDirectLoginButton = true; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + if (url === 'https://synergia.librus.pl/uczen/index') { |
| 68 | + let b = $('html body div#page.systema div#body div.container.static.welcome-page.student div.container-background div.content-box h1 b'); |
| 69 | + if (b && !!b.length && b.text() === 'ułatwia Twój każdy dzień w szkole!') { |
| 70 | + b.text('utrudnia Twój każdy dzień w szkole!'); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + if (url === 'https://www.librus.pl/') { |
| 75 | + if (!window.didInsertLibrusPageDirectLoginButton) { |
| 76 | + let html = '<a class="menuLink" href="https://portal.librus.pl/rodzina/synergia/loguj" style="font-weight: bold; text-decoration: underline;">ZALOGUJ OD RAZU</a>'; |
| 77 | + if ($("a.menuLink[href='/kontakt/']").after(html)) |
| 78 | + window.didInsertLibrusPageDirectLoginButton = true; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + if (css && !didInjectCssAlready) { |
| 83 | + didInjectCssAlready = true; |
| 84 | + let style = document.createElement('style'); |
| 85 | + style.innerHTML = css; |
| 86 | + document.head.appendChild(style) |
| 87 | + console.log("[Librus Enhancer] Injected CSS", style); |
| 88 | + } |
| 89 | + |
| 90 | + //console.log("modifyStuff end", (+new Date() - date), 'ms'); // takes up to 2 ms |
| 91 | + |
| 92 | +} |
| 93 | + |
| 94 | +const PAGE_REFRESH_INTERVAL = 3 * 60 * 1000; |
| 95 | +if (url.startsWith('https://synergia.librus.pl/')) { |
| 96 | + |
| 97 | + let isLoggedIn = !!$('#user-section').length; |
| 98 | + let div = $('#page .container .inside'); |
| 99 | + let isLoggedOut = div && !!div.length && div.text() === 'Brak dostępu'; |
| 100 | + |
| 101 | + if (isLoggedIn && !isLoggedOut) { |
| 102 | + console.log("[Librus Enhancer] You are logged in!"); |
| 103 | + setInterval(() => refreshPageInBackground(), PAGE_REFRESH_INTERVAL); |
| 104 | + //setTimeout(() => refreshPageInBackground(), 3000); // testing |
| 105 | + } else { |
| 106 | + console.log("[Librus Enhancer] You are logged out!"); |
| 107 | + if (isLoggedOut) { |
| 108 | + let button = $("input[value='Loguj']"); |
| 109 | + if (button && !!button.length) { |
| 110 | + button.attr('onclick', ''); |
| 111 | + button.click(ev => { |
| 112 | + ev.preventDefault(); |
| 113 | + ev.stopImmediatePropagation(); |
| 114 | + window.location.replace('https://portal.librus.pl/rodzina/synergia/loguj'); // take us to the login page directly... |
| 115 | + }); |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | +} |
| 121 | + |
| 122 | +// prevent session expiration, so we don't get logged out... |
| 123 | +function refreshPageInBackground() { |
| 124 | + console.log("[Librus Enhancer] Running refreshPageInBackground in page context..."); |
| 125 | + /*fetch('https://synergia.librus.pl/uczen/index', { // content.fetch crashes tab lol |
| 126 | + //mode: 'same-origin', |
| 127 | + cache: 'no-cache', |
| 128 | + credentials: 'include' |
| 129 | + }).then(response => console.log("[Librus Enhancer] Refreshed page in background to preserve the session (response status: " + response.status + ", length: " + response.headers.get("content-length") + ")")); |
| 130 | + */ |
| 131 | + |
| 132 | + let code = `fetch('https://synergia.librus.pl/uczen/index', { |
| 133 | + cache: 'no-cache', |
| 134 | + credentials: 'include' |
| 135 | + }).then(response => console.log("[Librus Enhancer] Refreshed page in background to preserve the session (response status: " + response.status + ", length: " + response.headers.get("content-length") + ")"));`; |
| 136 | + window.eval(code); |
| 137 | +} |
0 commit comments