forked from NottPeak/skiovox-breakout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (61 loc) · 2.22 KB
/
index.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
let extensionPrefix = document.querySelectorAll("input")[0].value;
let payload = document.querySelectorAll("textarea")[0].value;
let filePath = document.querySelectorAll("input")[1].value;
let arbitraryFileContent = document.querySelectorAll("textarea")[1];
let status = document.querySelector("#status");
let [cancel, start] = document.querySelectorAll("button");
function sections() {
return document.querySelectorAll('body>div');
}
function changeStatusMessage(message) {
status.textContent = ([message] || [""]).join();
}
function checkIfValid() {
return new Promise((resolve, reject) => {
resolve(Boolean(document.querySelector("input").value.length > 0));
});
}
start.addEventListener("click", async function () {
let valid = await checkIfValid();
if (!valid) return;
payload = document.querySelector("textarea").value;
extensionPrefix = document.querySelector("input").value;
let msg = await chrome.runtime.sendMessage({ type: "start-inspect", prefix: extensionPrefix, payload: payload === '' ? undefined : payload });
if (!msg) return changeStatusMessage("failed!");
return changeStatusMessage(msg.status);
});
cancel.addEventListener("click", async function () {
let msg = await chrome.runtime.sendMessage({ type: "cancel-inspect" });
if (!msg) return changeStatusMessage("failed!");
return changeStatusMessage("canceled");
});
sections().forEach(function (element) {
element.style.display = 'none';
});
sections()[0].style.display = 'block';
var currentIndex = 0;
function switchToNextSlide(offset) {
sections()[currentIndex].style.display = 'none';
currentIndex = currentIndex + offset;
if (currentIndex >= sections().length) {
currentIndex = 0;
}
if (currentIndex < 0) {
currentIndex = sections().length - 1;
}
var newIndex = currentIndex;
sections()[newIndex].style.display = 'block';
newIndex = currentIndex;
}
document.onkeydown = async function (ev) {
if (ev.repeat) return;
console.log()
if (!([document.body, document].includes(ev.target))) {
return false;
}
if (ev.key === 'ArrowLeft') {
switchToNextSlide(-1)
} else if (ev.key === 'ArrowRight') {
switchToNextSlide(1);
}
}