Skip to content

Commit 4937a23

Browse files
committed
first commit (1.0, Firefox initial version)
0 parents  commit 4937a23

File tree

10 files changed

+885
-0
lines changed

10 files changed

+885
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web-ext-artifacts

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

60 Bytes

librus_enhancer_extension

background.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict";
2+
3+
// these dicks would redirect you to the main page if you visit the link directly
4+
// so you have to do extra clicks just to get to the login page
5+
// so they count that you will read their articles and watch their ads
6+
// in a webapp we all paid for, disgusting
7+
function appendReferer(e) {
8+
e.requestHeaders.push({name: "Referer", value: "https://portal.librus.pl/rodzina"});
9+
return {requestHeaders: e.requestHeaders};
10+
}
11+
12+
browser.webRequest.onBeforeSendHeaders.addListener(appendReferer,
13+
{urls: ["https://portal.librus.pl/rodzina/synergia/loguj"]},
14+
["blocking", "requestHeaders"]
15+
);
16+
17+
browser.webRequest.onBeforeRequest.addListener(e => {
18+
let redirectUrl = "data:application/json;charset=utf-8," + encodeURIComponent('{}'); // lol that triggers CORS
19+
return {redirectUrl};
20+
},
21+
{urls: ["https://portal.librus.pl/ad*"]},
22+
["blocking"]
23+
);
24+
25+
browser.webRequest.onBeforeRequest.addListener(e => {
26+
return {redirectUrl: 'https://portal.librus.pl/rodzina/synergia/loguj'};
27+
},
28+
{urls: ["https://synergia.librus.pl/loguj", "https://synergia.librus.pl/loguj/przenies*"]},
29+
["blocking"]
30+
);

contentscript.js

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
}

icons/icon_48.png

824 Bytes
Loading

icons/icon_48.xcf

7.26 KB
Binary file not shown.

jquery.slim.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"typeAcquisition": {
3+
"include": [
4+
"firefox-webext-browser",
5+
"jquery"
6+
]
7+
}
8+
9+
}

manifest.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
3+
"manifest_version": 2,
4+
"name": "Librus Enhancer",
5+
"version": "1.0",
6+
7+
"description": "Sprawia, że Librus jest trochę mniej antyludzki.",
8+
9+
"icons": {
10+
"48": "icons/icon_48.png"
11+
},
12+
13+
"content_scripts": [
14+
{
15+
"matches": [
16+
"https://portal.librus.pl/*",
17+
"https://synergia.librus.pl/*",
18+
"https://www.librus.pl/*"
19+
],
20+
"js": ["jquery.slim.min.js", "contentscript.js"]
21+
}
22+
],
23+
24+
"permissions": [
25+
"webRequest", "webRequestBlocking", "https://portal.librus.pl/*", "https://synergia.librus.pl/*"
26+
],
27+
28+
"background": {
29+
"scripts": ["background.js"]
30+
}
31+
32+
}

0 commit comments

Comments
 (0)