-
Notifications
You must be signed in to change notification settings - Fork 4
/
popup.js
79 lines (63 loc) · 1.98 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
var pixels,waitTime,timeout, sliderVal;
var startScroll = document.getElementById('startScroll');
var stopScroll = document.getElementById('stopScroll');
var slider = document.getElementById("myRange");
startScroll.style.backgroundColor = '#00FF7F';
stopScroll.style.backgroundColor = '#FF007F';
//Scroll object
startScroll.onclick = setSlider;
slider.onchange = setSlider;
stopScroll.onclick = function(){
pixels = 0;
};
document.onreadystatechange = function() {
console.log("local storage");
var saved_timeout;
var saved_pixel;
var saved_slider;
saved_timeout = localStorage.getItem("timeout");
saved_pixel = localStorage.getItem("pixel");
saved_slider = localStorage.getItem("slider");
if(saved_timeout) timeout = saved_timeout;
if(saved_pixel) pixels = saved_pixel;
if(saved_slider) sliderVal = saved_slider;
};
function setSlider(){
clearTimeout(timeout);
if (slider.value < 300)
waitTime = 300 - slider.value;
else
waitTime = 1;
pixels = 1;
if (slider.value >= 300)
pixels = 2;
else if (slider.value >= 350)
pixels = 3;
else if (slider.value >= 400)
pixels = 4;
else if (slider.value >= 450)
pixels = 5;
else if (slider.value >= 500)
pixels = 6;
timeout = setInterval(scroll, waitTime);
localStorage.setItem("pixels", JSON.stringify(pixels));
localStorage.setItem("timeout", JSON.stringify(timeout));
localStorage.setItem("slider", JSON.stringify(slider.value));
}
function scroll(element) {
chrome.tabs.executeScript({
code: returnScript()
});
}
function returnScript(){
var script = [
'if(document.title.includes(\'Google Sheets\')){',
'}else if(document.title.includes(\'Google Doc\')){',
'}else{',
'window.scrollBy(0, ', pixels, ');',
'}'
];
var joinedScript = script.join('');
console.log(joinedScript);
return joinedScript;
}