-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
109 lines (104 loc) · 4.45 KB
/
popup.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
let scanBtn = document.getElementById("scanButton")
scanBtn.onclick = function () {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
if (!tabs[0].url.startsWith('https://discord.com/channels/@me/')) {
scanBtn.disabled = true
scanBtn.innerHTML = "Nothing to Scan."
scanBtn.style.backgroundColor = "red";
return setTimeout(() => {
scanBtn.disabled = false
scanBtn.innerHTML = "Scan"
scanBtn.style.backgroundColor = "#2a2d31";
}, 1500);
}
scanBtn.innerHTML = "Refreshing..."
chrome.tabs.reload(tabs[0].id)
let stillWaiting = true
chrome.tabs.onUpdated.addListener(function (tabId, info) {
if (info.status === 'complete' && tabId == tabs[0].id && stillWaiting) {
setTimeout(() => {
chrome.tabs.executeScript(tabs[0].id, { code: "let interval=setInterval(function(){if(document.readyState==='complete'){clearInterval(interval); setTimeout(() => {chrome.runtime.sendMessage({action: 'iWasRefreshed'})}, 3000);}},200);", runAt: 'document_end' })
}, 500);
stillWaiting = false
}
});
});
}
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if (request.action == "iWasRefreshed") scan()
}
);
function scan() {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
scanBtn.disabled = true
scanBtn.style.backgroundColor = "lightblue";
scanBtn.style.color = "black";
scanBtn.innerHTML = "Scanning..."
chrome.tabs.sendMessage(tabs[0].id, { action: "scan" }, async function (response) {
let css = await downloadCss(response.cssLink)
var htmlCode = `<html><head><meta charset="UTF-8"><style>${css} body,html{background:#36393f;color: white;overflow:auto!important;}body{padding:20px}.drep-scanned {font-size:2rem;font-weight:700;text-align:center;color:#7289DA}</style></head><body><h1 class="drep-scanned">Scanned By <a style="color:#7289DA" href="https://discordrep.com">DiscordRep</a><br><small style="color:orangered;">Date of scan: ${new Date()}</small></h1><br><br>${response.output}</body></html>`
scanBtn.style.backgroundColor = "lightgreen";
scanBtn.innerHTML = "Uploading..."
let uploadedTo = await uploadProof(htmlCode)
let parsed = JSON.parse(uploadedTo)
var url = `https://discordrep-paste.glitch.me/proof/${parsed.key}`
chrome.tabs.create({ url: url })
scanBtn.innerHTML = "Scan"
scanBtn.style.backgroundColor = "#2a2d31";
scanBtn.style.color = "white";
scanBtn.disabled = false
});
});
}
function downloadCss(link) {
return new Promise(function (resolve, reject) {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else { // for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", link, true);
xmlhttp.send();
xmlhttp.onerror = function () {
reject({
status: this.status,
statusText: xmlhttp.statusText
});
};
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
resolve(xmlhttp.responseText)
}
};
})
}
function uploadProof(data) {
return new Promise(function (resolve, reject) {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST", "https://discordrep-paste.glitch.me/documents", true);
xmlhttp.withCredentials = false;
xmlhttp.setRequestHeader('Accept', 'application/json');
xmlhttp.send(data);
xmlhttp.onerror = function () {
reject({
status: this.status,
statusText: xmlhttp.statusText
});
scanBtn.innerHTML = "Failed."
scanBtn.style.backgroundColor = "red";
};
xmlhttp.onreadystatechange = function () {
console.log(xmlhttp)
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
resolve(xmlhttp.responseText)
}
};
})
}