-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
131 lines (121 loc) · 5.18 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
var radio = document.querySelectorAll("input[type=radio]");
var val = 0;
var lastFilter = 8;
var state = false;
var number = document.querySelectorAll('input[type=number]');
var vl = new Array(number.length);
for (i = 0; i < radio.length; i++)
radio[i].addEventListener("change", function () {
val = this.value;
localStorage.setItem("youtube_filter_selected_index", val);
chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { "youtube_filter_selected_index": val });
});
for (j = 0; j < radio.length; j++)
radio[j].parentElement.style.color = "white";
radio[val].parentElement.style.color = "lime";
if(val==lastFilter){
document.getElementById('manualfilter').style.display = '';
document.getElementById('mfcontainer').style.height = 'auto';
}else{
document.getElementById('manualfilter').style.display = 'none';
document.getElementById('mfcontainer').style.height = '29px';
}
});
radio[radio.length-1].addEventListener("change", function () {
val = this.value;
localStorage.setItem("youtube_filter_selected_index", val);
for(q=0; q<number.length; q++){
var vdom = document.getElementById('manual'+(q+1));
if(vdom!=null)
vl[q] = vdom.value;
else
vl[q] = 0;
}
localStorage.setItem('youtube_video_filters_manual', JSON.stringify(vl));
chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { "youtube_filter_selected_index": val, "youtube_video_filters_manual": JSON.stringify(vl)});
});
for (j = 0; j < radio.length; j++)
radio[j].parentElement.style.color = "white";
radio[val].parentElement.style.color = "lime";
document.getElementById('manualfilter').style.display = '';
document.getElementById('mfcontainer').style.height = 'auto';
});
document.getElementById('setvalue').addEventListener("click", function(){
for (p = 0; p<number.length; p++){
if(parseInt(number[p].value)>parseInt(number[p].max))
number[p].value=number[p].max;
if(parseInt(number[p].value)<parseInt(number[p].min))
number[p].value=number[p].min;
}
for(q=0; q<number.length; q++){
var vdom = document.getElementById('manual'+(q+1));
if(vdom!=null)
vl[q] = vdom.value;
else
vl[q] = 0;
}
localStorage.setItem('youtube_video_filters_manual', JSON.stringify(vl));
chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { "youtube_filter_selected_index": radio[radio.length-1].value, "youtube_video_filters_manual": JSON.stringify(vl) });
});
});
document.getElementById('manualfilter').addEventListener('keydown', function(ev){
if(ev.code == "Enter" && ev.key == "Enter")
document.getElementById('setvalue').click();
});
document.addEventListener("DOMContentLoaded", function () {
val = 0;
if (localStorage.getItem("youtube_filter_selected_index") !== undefined && localStorage.getItem("youtube_filter_selected_index") !== null)
val = localStorage.getItem("youtube_filter_selected_index");
for (i = 0; i < radio.length; i++)
radio[i].checked = false;
radio[val].checked = true;
radio[val].parentElement.style.color = "lime";
radio[val].scrollIntoView(false);
if(val==lastFilter){
document.getElementById('manualfilter').style.display = '';
document.getElementById('mfcontainer').style.height = 'auto';
}else{
document.getElementById('manualfilter').style.display = 'none';
document.getElementById('mfcontainer').style.height = '29px';
}
if (localStorage.getItem("youtube_video_filters_manual") !== undefined && localStorage.getItem("youtube_video_filters_manual") !== null){
vl = JSON.parse(localStorage.getItem('youtube_video_filters_manual'));
for(q=0; q<number.length; q++){
var vdom = document.getElementById('manual'+(q+1));
if(vdom!=null)
vdom.value = vl[q];
}
}
if (localStorage.getItem("youtube_darkmode_clicked") !== undefined && localStorage.getItem("youtube_darkmode_clicked") !== null)
state = (localStorage.getItem("youtube_darkmode_clicked") === "true" ? true : false);
document.getElementById('switchdm').checked = state;
});
document.getElementById('switchdm').addEventListener('change', function () {
state = document.getElementById('switchdm').checked;
localStorage.setItem("youtube_darkmode_clicked", state);
chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { "youtube_darkmode_clicked": state });
});
});
document.getElementById('moption').addEventListener('click', function () {
chrome.runtime.openOptionsPage();
});
document.getElementById('showhidenote').addEventListener('click', function(){
var note = document.querySelectorAll('.note');
if(note.length>0)
for(k=0; k<note.length; k++)
if(note[k].style.display!=='-webkit-box'){
note[k].style.display = '-webkit-box';
this.setAttribute('title', 'Close it');
document.getElementById('showhidenote').innerHTML="Close";
}
else{
note[k].style.display = 'none';
this.setAttribute('title', 'Read more');
document.getElementById('showhidenote').innerHTML="« Tips »";
}
this.scrollIntoView();
});