-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathredirectState.function.js
106 lines (96 loc) · 3.23 KB
/
redirectState.function.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
function attachToRedirectStateSetting() {
var redirectStateSetting = document.getElementById("redirect");
// redirect element is an input with type checkbox, if it's checked then send a message to the background script
// to set chartRedirect state to true
redirectStateSetting.addEventListener("change", function () {
if (this.checked) {
browser.runtime.sendMessage({
message: "setChartRedirectState",
state: true,
});
} else {
browser.runtime.sendMessage({
message: "setChartRedirectState",
state: false,
});
}
});
}
// execute the function on DOM content loaded
document.addEventListener("DOMContentLoaded", attachToRedirectStateSetting);
function updateCheckBoxState() {
// get the state and update the checkbox
browser.runtime.sendMessage(
{ message: "getChartRedirectState" },
function (response) {
console.log(response);
if (response.chartRedirectState) {
document.getElementById("redirect").defaultChecked = true;
} else {
document.getElementById("redirect").defaultChecked = false;
}
}
);
}
// execute the function on DOM content loaded
document.addEventListener("DOMContentLoaded", updateCheckBoxState);
// KITE REDIRECT BT
function attachToKiteBt() {
var kiteBtState = document.getElementById("kite-bt");
// redirect element is an input with type checkbox, if it's checked then send a message to the background script
// to set chartRedirect state to true
kiteBtState.addEventListener("change", function () {
if (this.checked) {
browser.runtime.sendMessage({
message: "setKiteEnabled",
state: true,
});
} else {
browser.runtime.sendMessage({
message: "setKiteEnabled",
state: false,
});
}
});
}
// execute the function on DOM content loaded
document.addEventListener("DOMContentLoaded", attachToKiteBt);
function updateKiteCheckBoxState() {
// get the state and update the checkbox
browser.runtime.sendMessage(
{ message: "getKiteEnabled" },
function (response) {
console.log(response);
if (response.kiteEnabled) {
document.getElementById("kite-bt").defaultChecked = true;
} else {
document.getElementById("kite-bt").defaultChecked = false;
}
}
);
}
function attachToKiteChartType() {
var kiteChartType = document.getElementById("chart-type");
// redirect element is an input with type checkbox, if it's checked then send a message to the background script
// to set chartRedirect state to true
kiteChartType.addEventListener("change", function () {
browser.runtime.sendMessage({
message: "setKiteChartType",
type: this.value,
});
});
}
function updateKiteChartType() {
// get the state and update the checkbox
browser.runtime.sendMessage(
{ message: "getKiteChartType" },
function (response) {
console.log(response);
document.getElementById("chart-type").value = response.kiteChartType;
}
);
}
// execute the functions on DOM content loaded
document.addEventListener("DOMContentLoaded", updateKiteCheckBoxState);
document.addEventListener("DOMContentLoaded", attachToKiteChartType);
document.addEventListener("DOMContentLoaded", updateKiteChartType);