-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
81 lines (66 loc) · 2.49 KB
/
content.js
File metadata and controls
81 lines (66 loc) · 2.49 KB
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
document.addEventListener("DOMContentLoaded", () => {
let webTheme = localStorage.getItem("theme") || "light";
document.body.classList = [webTheme];
if(webTheme === "dark"){
document.getElementById("toggleMode").innerHTML = "🌙";
}
else {
document.getElementById("toggleMode").innerHTML = "💡";
}
let buttonColor = localStorage.getItem("button_color") || "green";
document.getElementById("main").classList = [buttonColor];
document.getElementById("toggleMode").addEventListener("click", toggleMode);
document.getElementById("options").addEventListener("click", editOptions);
});
document.querySelectorAll(".sectionButton").forEach(button => {
button.addEventListener("click", async () => {
let sectionId = button.value;
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
if (tab.url && tab.url.includes("https://bulbapedia.bulbagarden.net/wiki/") && tab.url.endsWith("_(Pok%C3%A9mon)")) {
chrome.scripting.executeScript({
target: { tabId: tab.id },
func: scrollToSection,
args: [sectionId]
});
} else {
alert("This is not a Pokemon Bulbapedia page.");
}
});
})
document.querySelectorAll(".colorButton").forEach(button => {
button.addEventListener("click", async () => {
let color = button.value;
localStorage.setItem("button_color", color);
document.getElementById("main").classList = [color];
});
})
function scrollToSection(sectionName) {
const section = document.querySelector(`#${sectionName}`);
if(sectionName === "START"){
window.scrollTo({ top: 0, behavior: "smooth" });
}
else if(section){
section.scrollIntoView({ behavior: "smooth" });
}
else {
alert("Error. Please try redownloading.");
}
}
function toggleMode(){
document.body.classList.toggle("light");
document.body.classList.toggle("dark");
let theme = "";
if(document.body.classList.contains("light")){
document.getElementById("toggleMode").innerHTML = "💡";
theme = "light";
}
else {
document.getElementById("toggleMode").innerHTML = "🌙";
theme = "dark";
}
localStorage.setItem("theme", theme);
}
function editOptions(){
document.getElementById("colorSelect").classList.toggle("option-mode");
document.getElementById("credits").classList.toggle("option-mode");
}