forked from rule34plus1/rule34plus1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent_script.js
79 lines (64 loc) · 2.57 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
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
function storeImagesOrAddNavigation() {
const query = window.location.search;
const urlParams = new URLSearchParams(query);
if(urlParams.get("page") !== "post") {
return;
}
if(urlParams.get("s") === "list") {
const images = Array.from(document.getElementsByClassName("thumb"));
if (images.length === 0) {
return;
}
const firstImageId = images.at(0).id.slice(1);
let previousImageId = images.at(-1).id.slice(1);
let currentImageId = firstImageId;
let nextImageId;
for(let i = 1; i < images.length; ++i) {
nextImageId = images.at(i).id.slice(1);
chrome.storage.local.set({
[currentImageId]: {
previous: previousImageId,
next: nextImageId,
}
});
previousImageId = currentImageId;
currentImageId = nextImageId;
}
chrome.storage.local.set({
[currentImageId]: {
previous: previousImageId,
next: firstImageId,
}
});
}
else if(urlParams.get("s") === "view" && urlParams.has("id")) {
const imageId = urlParams.get("id");
chrome.storage.local.get([imageId]).then((result) => {
const navigationInfo = result[imageId];
const content = document.querySelector("div.flexi > div");
const previous = document.createElement("a");
previous.innerHTML = "Previous";
previous.href = "https://rule34.xxx/index.php?page=post&s=view&id="
+ navigationInfo.previous;
const next = document.createElement("a");
next.innerHTML = "Next";
next.href = "https://rule34.xxx/index.php?page=post&s=view&id="
+ navigationInfo.next;
const previousNextSeparator = document.createTextNode(" | ");
const previousNextContainer = document.createElement("h4");
previousNextContainer.appendChild(previous);
previousNextContainer.appendChild(previousNextSeparator);
previousNextContainer.appendChild(next);
content.appendChild(previousNextContainer);
document.addEventListener("keydown", event => {
if(event.key === "ArrowRight") {
window.location.href = next.href;
}
else if(event.key === "ArrowLeft") {
window.location.href = previous.href;
}
});
});
}
}
storeImagesOrAddNavigation();