-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
128 lines (106 loc) · 4.85 KB
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
if (location.href.includes("https://moodle-app2.let.ethz.ch/")) {
try {
document.getElementsByClassName("main-inner-wrapper main-inner-outside-none main-inner-outside-nextmaincontent")[0].style.maxWidth = "1000px";
document.getElementsByClassName("main-inner-wrapper main-inner-outside-none main-inner-outside-nextmaincontent")[0].style.margin = "auto";
var activities = document.getElementsByClassName("activity-item ")
for (var i = 0; i < activities.length; i++) {
activities[i].style.paddingTop = "0.5rem";
activities[i].style.paddingBottom = "0.5rem";
}
} catch { }
}
window.onload = function () {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function demo() {
console.log("ETH improvements loaded");
var english = true;
chrome.storage.sync.get(['english'], function (result) {
console.log('content.js: english currently is ' + result.english);
if(result.english == undefined)return;
english = result.english;
});
var buttons = true;
chrome.storage.sync.get(['buttons'], function (result) {
console.log('content.js: buttons currently is ' + result.buttons);
if(result.buttons == undefined)return;
buttons = result.buttons;
});
var fillpasswords = false;
chrome.storage.sync.get(['fillpasswords'], function (result) {
console.log('content.js: fillpasswords currently is ' + result.fillpasswords);
if(result.fillpasswords == undefined)return;
fillpasswords = result.fillpasswords;
});
await sleep(400);
// if (location.href.includes("quiz") || location.href.includes("feedback") || location.href.includes("test") || location.href.includes("exam") || location.href.includes("prüfung")) return;
//the following code is used to skip useless buttons and switch to english mode
if (english && location.href.includes("https://www.lehrbetrieb.ethz.ch/myStudies/studSessionException.view")) {
// console.log('switching to english');
await sleep(400);
console.log('skipping useless button');
try { document.querySelectorAll('a[href="index.jsp"]')[0].click(); } catch { }
try { document.querySelectorAll('a[href="index_en.jsp"]')[0].click(); } catch { }
}
if (english && location.href.includes("https://www.lehrbetrieb.ethz.ch/myStudies/studWillkommen.view")) {
console.log('switching to english');
try { document.querySelectorAll('a[href="?lang=en"].engl')[0].click(); } catch { }
await sleep(400);
}
if (buttons && location.href.includes("https://www.lehrbetrieb.ethz.ch/myStudies/login.view")) {
console.log('skipping useless button');
await sleep(400);
try { document.querySelectorAll('input[value="Start"]')[0].click(); } catch { }
}
if (english && location.href.includes("https://moodle-app2.let.ethz.ch/")) {
console.log('moodle english');
var page_is_german = false;
var element = document.querySelectorAll('a[href="https://moodle-app2.let.ethz.ch/course/index.php"]')[0];
if(element && element.innerText.includes("Kurssuche")){
page_is_german = true;
}
if(page_is_german){
//go through every element with class "dropdown-item" and check if the title attribute contains "English"
var elements = document.getElementsByClassName("dropdown-item");
for (var i = 0; i < elements.length; i++) {
if (elements[i].innerHTML.includes("English")) {
console.log('switching to english');
elements[i].click();
}
}
}
}
if (buttons && location.href.includes("https://moodle-app2.let.ethz.ch/auth/shibboleth/login.php")) {
console.log('skipping useless moodle login button');
try { document.querySelectorAll('button.btn.btn-primary.btn-block')[0].click(); } catch { }
}
if (fillpasswords && location.href.includes("https://aai-logon.ethz.ch/idp/profile/SAML2") && document.querySelectorAll('#username')[0]) {
console.log('searching for password');
navigator.credentials.get({ password: true }).then(function(credential) {
if (credential && credential.password) {
// Found saved password, use it to fill in the input field
document.querySelectorAll('#username')[0].value=credential.id;
document.querySelectorAll('#password')[0].value=credential.password;
document.querySelectorAll('button[name="_eventId_proceed"]')[0].click();
} else {
console.log('no saved password');
}
})
}
if(fillpasswords && document.querySelectorAll('input[placeholder="username@ethz.ch"]')[0]){
console.log('searching for password');
navigator.credentials.get({ password: true }).then(function(credential) {
if (credential && credential.password) {
// Found saved password, use it to fill in the input field
document.querySelectorAll('#userNameInput')[0].value=credential.id;
document.querySelectorAll('#passwordInput')[0].value=credential.password;
} else {
console.log('no saved password');
}
})
}
console.log('done');
}
demo();
}