-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
126 lines (116 loc) · 4.31 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
window.onload = function (ev) {
var value
var min
var max
var diff
var url
var data = []
document.getElementById("btn-submit").onclick = function (ev) {
ev.preventDefault();
min = document.getElementById("min").value;
max = document.getElementById("max").value;
console.log(min);
console.log(max);
diff = max - min;
value = parseInt(Math.floor(Math.random() * diff)) + parseInt(min);
chrome.tabs.query({
active: true,
lastFocusedWindow: true
}, function (tabs) {
// and use that tab to fill in out title and url
var tab = tabs[0];
if(tab.url!==undefined)
url = tab.url;
// console.log(tab.url);
// url_display(url);
});
// alert(url)
if(url!==undefined){
var obj = {
min: min,
max: max,
diff: diff,
value: value,
url: url,
update: update,
};
if (!obj.update()) {
if (localStorage.getItem("data_string") !== null) {
if (typeof localStorage.data_string !== 'undefined') {
data = JSON.parse(localStorage.data_string);}
}
data.push(obj);
localStorage.data_string = JSON.stringify(data)
}
document.getElementById("output").innerHTML = value;
// document.getElementById("output").innerHTML = "active";
}
}
document.getElementById("btn-stop").onclick = function (ev) {
ev.preventDefault();
chrome.tabs.query({
active: true,
lastFocusedWindow: true
}, function (tabs) {
// and use that tab to fill in out title and url
var tab = tabs[0];
// console.log(tab.url);
// alert(tab.url);
if (localStorage.getItem("data_string") !== null) {
var data = JSON.parse(localStorage.data_string);
data = data.filter(n => n.url !== tab.url);
localStorage.data_string = JSON.stringify(data)}
console.log("assasa");
// url_display(tab.url);
});
document.getElementById("output").innerHTML = "stopped";
}
var x = setInterval(function () {
if (localStorage.getItem("data_string") !== null){
chrome.tabs.query({
active: true,
lastFocusedWindow: true
}, function (tabs) {
// and use that tab to fill in out title and url
var tab = tabs[0];
if (tab){
if(tab.url!==undefined)
url = tab.url;
}
});
// console.log(tab.url);
// alert(tab.url);
if(url!==undefined){
var json = JSON.parse(localStorage.data_string);
for (var index = 0; index < json.length; ++index) {
var data = json[index];
if (data.url == url) {
document.getElementById("output").innerHTML = data.value;
// document.getElementById("output").innerHTML = "active";
break;
}
}
}}
}, 1);
function url_display(url) {
document.getElementById("url").innerHTML = url;
}
function update() {
if (localStorage.getItem("data_string") !== null){
var json = JSON.parse(localStorage.data_string);
for (var index = 0; index < json.length; ++index) {
var animal = json[index];
if (animal.url == this.url) {
animal.min = this.min;
animal.max = this.max;
animal.diff = this.diff;
animal.url = this.url;
animal.value = this.value;
localStorage.data_string = JSON.stringify(json)
return true;
}
}
return false;
}
}
}