-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent_script.js
48 lines (44 loc) · 1.63 KB
/
content_script.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
document.addEventListener('load', main(), false)
function main(){
if (location.href.includes('portswigger.net')){
injectButton();
}
if (location.href.includes('exploit-server.net')){
censorLabTitle('Exploit Server');
}
if (location.href.includes('web-security-academy.net')){
censorLabTitle('MysteryLab');
}
}
function injectButton(){
let examButton = document.createElement('button');
examButton.classList = 'button-orange-small';
examButton.innerText = 'Mystery Lab';
document.getElementsByClassName('login-buttons')[0].appendChild(examButton);
examButton.addEventListener('click', ()=>{
fetch('https://portswigger.net/web-security/all-labs')
.then((r)=>r.text())
.then((data)=>{
let d = new DOMParser().parseFromString(data, 'text/html');
let links = d.getElementById('all-labs').getElementsByTagName('a');
let randomIndex = Math.round(Math.random() * links.length - 1);
randomLab = links[randomIndex];
// This is where the difficulty check will go in the future
openLab(randomLab.href);
});
})
}
function openLab(labUrl){
fetch(labUrl)
.then((r)=>r.text())
.then((data)=>{
let x = new DOMParser().parseFromString(data, 'text/html');
let labUrl = x.getElementsByClassName('icon-erlenmeyer')[0].parentElement.href;
window.open(labUrl);
})
}
function censorLabTitle(title){
let academyLabHeader = document.getElementById('academyLabHeader')
academyLabHeader.getElementsByTagName('h2')[0].innerText = title;
document.title = title;
}