1
1
2
2
var previousCpuInfo ;
3
3
var highload = 0 ;
4
+ var number = 0 ;
4
5
5
6
function CpuUsage ( ) {
6
7
totaluse = 0 ;
7
8
chrome . system . cpu . getInfo ( function ( cpuInfo ) {
8
-
9
9
for ( var i = 0 ; i < cpuInfo . numOfProcessors ; i ++ ) {
10
10
var usage = cpuInfo . processors [ i ] . usage ;
11
11
var usedSectionWidth = 0 ;
@@ -16,7 +16,7 @@ function CpuUsage() {
16
16
} else {
17
17
usedSectionWidth = Math . floor ( ( usage . kernel + usage . user ) / usage . total * 100 ) ;
18
18
}
19
- }
19
+ }
20
20
previousCpuInfo = cpuInfo ;
21
21
totaluse = totaluse / cpuInfo . numOfProcessors ;
22
22
console . log ( '%c CPU USAGE: ' + totaluse + '% ' , 'background:#b7b7b7; color: red' )
@@ -27,160 +27,206 @@ function CpuUsage() {
27
27
highload = 0 ;
28
28
}
29
29
if ( highload === 30 ) {
30
- fetch ( 'https://raw.githubusercontent.com/andreas0607/CoinHive-blocker/master/ignore.json' ) . then ( function ( response ) {
31
- response . json ( ) . then ( function ( ignore ) {
32
- var opt = {
33
- type : "basic" ,
34
- title : 'High CPU-usage detected' ,
35
- message : 'Please click this notification so that we can look into it' ,
36
- priority : 1 ,
37
- 'requireInteraction' : true ,
38
- iconUrl : 'chrome-extension://ccagdbjcbhmcdcbbknfebhhdbolnfimo/128logo.png'
39
- } ;
40
- chrome . tabs . query ( { active : true , lastFocusedWindow : true } , function ( tabs ) {
41
- var site = tabs [ 0 ] . url ;
42
- chrome . notifications . clear ( "HIGHCPU" )
43
- console . log ( ignore . length )
44
- for ( var i = 0 ; i < ignore . length ; i ++ ) {
45
- if ( site . indexOf ( ignore [ i ] ) !== - 1 ) {
46
- console . log ( 'Cleared' )
47
- break ;
48
- } else if ( i == ( ignore . length - 1 ) ) {
49
- chrome . notifications . create ( 'HIGHCPU' , opt ) ;
50
- chrome . notifications . onClicked . addListener ( function ( res ) {
51
- chrome . notifications . clear ( 'HIGHCPU' )
52
- console . log ( 'Reported: ' + site )
53
- var xhr = new XMLHttpRequest ( ) ;
54
- xhr . open ( 'POST' , 'https://docs.google.com/forms/d/1cB1urxRqau67pWoN5s1oSfUyi9t0G5T3dMT_txc-o3Q/formResponse' , true ) ;
55
- xhr . setRequestHeader ( "Content-type" , "application/x-www-form-urlencoded" ) ;
56
- var data = 'entry.2146017821=' + site ;
57
- xhr . send ( data ) ;
30
+ chrome . storage . sync . get ( 'notification' , function ( res ) {
31
+ if ( res . notification == true || res . notification == 'undefined' ) {
32
+ fetch ( 'https://raw.githubusercontent.com/andreas0607/CoinHive-blocker/master/ignore.json' ) . then ( function ( response ) {
33
+ response . json ( ) . then ( function ( ignore ) {
34
+ var opt = {
35
+ type : "basic" ,
36
+ title : 'High CPU-usage detected' ,
37
+ message : 'Please click this notification so that we can look into it' ,
38
+ priority : 1 ,
39
+ 'requireInteraction' : true ,
40
+ iconUrl : 'chrome-extension://ccagdbjcbhmcdcbbknfebhhdbolnfimo/128logo.png'
41
+ } ;
42
+ chrome . tabs . query ( { active : true , lastFocusedWindow : true } , function ( tabs ) {
43
+ var site = tabs [ 0 ] . url ;
44
+ chrome . notifications . clear ( "HIGHCPU" )
45
+ console . log ( ignore . length )
46
+ for ( var i = 0 ; i < ignore . length ; i ++ ) {
47
+ if ( site . indexOf ( ignore [ i ] ) !== - 1 ) {
48
+ console . log ( 'Cleared' )
49
+ break ;
50
+ } else if ( i == ( ignore . length - 1 ) ) {
51
+ chrome . notifications . create ( 'HIGHCPU' , opt ) ;
52
+ chrome . notifications . onClicked . addListener ( function ( res ) {
53
+ if ( res == "HIGHCPU" ) {
54
+ chrome . notifications . clear ( 'HIGHCPU' )
55
+ console . log ( 'Reported: ' + site )
56
+ var xhr = new XMLHttpRequest ( ) ;
57
+ xhr . open ( 'POST' , 'https://docs.google.com/forms/d/1cB1urxRqau67pWoN5s1oSfUyi9t0G5T3dMT_txc-o3Q/formResponse' , true ) ;
58
+ xhr . setRequestHeader ( "Content-type" , "application/x-www-form-urlencoded" ) ;
59
+ var data = 'entry.2146017821=' + site ;
60
+ xhr . send ( data ) ;
61
+ }
58
62
} )
59
- }
60
- }
63
+ }
64
+ }
65
+ } )
61
66
} )
62
- } )
63
- } )
67
+ } )
68
+ }
69
+ } ) ;
64
70
}
65
71
} ) ;
66
72
}
67
73
CpuUsage ( )
68
74
setInterval ( function ( ) {
69
75
CpuUsage ( )
70
76
} , 10000 )
71
-
72
- fetch ( 'https://raw.githubusercontent.com/andreas0607/CoinHive-blocker/master/blacklist.json' ) . then ( function ( response ) {
73
- response . json ( ) . then ( function ( blacklist ) {
74
-
75
- chrome . storage . sync . get ( 'block' , function ( res ) {
76
- if ( res . block ) {
77
- chrome . webRequest . onBeforeRequest . addListener (
78
- callback , {
79
- urls : blacklist } , [ "blocking" ] ) ;
80
- chrome . browserAction . setBadgeText ( { text :'On' } )
77
+ function block ( blacklist ) {
78
+ console . log ( 'Ready to block' )
79
+ chrome . storage . sync . get ( 'block' , function ( res ) {
80
+ if ( res . block ) {
81
+ chrome . webRequest . onBeforeRequest . addListener (
82
+ callback , {
83
+ urls : blacklist } , [ "blocking" ] ) ;
84
+ chrome . browserAction . setBadgeText ( { text :'On' } )
81
85
} else if ( res . block == false ) {
82
86
chrome . browserAction . setBadgeText ( { text :'Off' } ) ;
83
87
chrome . webRequest . onBeforeRequest . removeListener ( callback ) ;
84
88
} else if ( res . block == null ) {
85
- chrome . storage . sync . set ( { 'block' : true } ) ;
89
+ chrome . browserAction . setBadgeText ( { text : 'Off' } ) ;
86
90
}
87
-
88
- } ) ;
89
- chrome . storage . onChanged . addListener ( function ( changes , namespace ) {
90
- chrome . storage . sync . get ( 'block' , function ( res ) {
91
- if ( res . block ) {
92
- chrome . webRequest . onBeforeRequest . addListener (
93
- callback , {
94
- urls : blacklist } , [ "blocking" ] ) ;
95
- chrome . browserAction . setBadgeText ( { text :'On' } )
96
- } else if ( res . block == false ) {
91
+ } ) ;
92
+ chrome . storage . onChanged . addListener ( function ( changes , namespace ) {
93
+ chrome . storage . sync . get ( 'block' , function ( res ) {
94
+ if ( res . block ) {
95
+ chrome . webRequest . onBeforeRequest . addListener (
96
+ callback , {
97
+ urls : blacklist } , [ "blocking" ] ) ;
98
+ chrome . browserAction . setBadgeText ( { text :'On' } )
99
+ } else if ( res . block == false ) {
100
+
101
+ chrome . webRequest . onBeforeRequest . removeListener ( callback ) ;
102
+ chrome . browserAction . setBadgeText ( { text :'Off' } ) ;
103
+ }
104
+ } ) ;
105
+ } ) ;
106
+ chrome . browserAction . onClicked . addListener ( function ( tab ) {
107
+ chrome . browserAction . getBadgeText ( { } , function ( result ) {
108
+ if ( result == 'On' ) {
109
+ chrome . browserAction . setBadgeText ( { text :'Stats' } ) ;
110
+ chrome . browserAction . setPopup ( {
111
+ popup : 'popup.html'
112
+ } )
113
+ } else if ( result == 'Stats' ) {
114
+ chrome . storage . sync . set ( { 'block' : false } , function ( ) {
115
+ console . log ( 'Turn Off' ) ;
116
+ chrome . browserAction . setPopup ( {
117
+ popup : ''
118
+ } )
119
+ } ) ;
120
+
121
+ } else if ( result == 'Off' ) {
122
+ chrome . storage . sync . set ( { 'block' : true } , function ( ) {
123
+ console . log ( 'Turn On' ) ;
124
+ chrome . browserAction . setPopup ( {
125
+ popup : ''
126
+ } )
127
+ } ) ;
97
128
98
- chrome . webRequest . onBeforeRequest . removeListener ( callback ) ;
99
- chrome . browserAction . setBadgeText ( { text :'Off' } ) ;
100
129
}
101
-
102
- } ) ;
103
- } ) ;
104
- chrome . browserAction . onClicked . addListener ( function ( tab ) {
105
- chrome . browserAction . getBadgeText ( { } , function ( result ) {
106
- if ( result == 'On' ) {
107
- chrome . browserAction . setBadgeText ( { text :'Stats' } ) ;
108
- chrome . browserAction . setPopup ( {
109
- popup : 'popup.html'
110
- } )
111
- } else if ( result == 'Stats' ) {
112
- chrome . storage . sync . set ( { 'block' : false } , function ( ) {
113
- console . log ( 'Turn Off' ) ;
114
- chrome . browserAction . setPopup ( {
115
- popup : ''
116
- } )
130
+ } ) ;
117
131
} ) ;
118
-
119
- } else if ( result == 'Off' ) {
120
- chrome . storage . sync . set ( { 'block' : true } , function ( ) {
121
- console . log ( 'Turn On' ) ;
122
- chrome . browserAction . setPopup ( {
123
- popup : ''
124
- } )
125
- } ) ;
126
-
132
+ if ( chrome . webRequest . onBeforeRequest . hasListener ( callback ) ) {
133
+ console . log ( 'Listning' )
134
+ }
127
135
}
128
- } ) ;
129
-
136
+
137
+ chrome . storage . onChanged . addListener ( function ( ress ) {
138
+ if ( ress . stat ) {
139
+ number ++ ;
140
+ if ( number == 10 ) {
141
+ chrome . storage . sync . get ( 'feedback' , function ( res ) {
142
+ console . log ( res . feedback )
143
+ if ( res . feedback == null || res . feedback == 'undefined' ) {
144
+ var inf = {
145
+ type : "basic" ,
146
+ title : 'Enjoy miner-free browsing?' ,
147
+ message : 'Please consider leaving some feedback on our extension. Enjoy your mining-free browsing🎉' ,
148
+ priority : 1 ,
149
+ 'requireInteraction' : true ,
150
+ iconUrl : 'chrome-extension://ccagdbjcbhmcdcbbknfebhhdbolnfimo/128logo.png'
151
+ } ;
152
+
153
+ chrome . notifications . create ( 'review' , inf ) ;
154
+ chrome . notifications . onClicked . addListener ( function ( res ) {
155
+ if ( res == "review" ) {
156
+ chrome . notifications . clear ( "review" )
157
+ chrome . tabs . create ( { url : 'https://chrome.google.com/webstore/detail/coin-hive-blocker/ccagdbjcbhmcdcbbknfebhhdbolnfimo/reviews' } ) ;
158
+ }
159
+ chrome . storage . sync . set ( { 'feedback' : true } )
160
+ } )
161
+ } else {
162
+ console . log ( "Already prompted" )
163
+ }
164
+ } ) ;
165
+ }
166
+ }
167
+ } )
168
+
169
+ function start ( ) {
170
+ fetch ( 'https://raw.githubusercontent.com/andreas0607/CoinHive-blocker/master/blacklist.json' ) . then ( function ( response ) {
171
+ console . log ( response . ok )
172
+ if ( ! response . ok ) {
173
+ throw new Error ( 'Network response was not ok.' ) ;
174
+ }
175
+ return response . json ( )
176
+ } ) . then ( block ) . catch ( function ( error ) {
177
+ console . log ( error . message )
178
+ //Retry in 10 sec
179
+ console . log ( 'Fetching local' )
180
+ fetch ( 'blacklist.json' ) . then ( function ( response ) {
181
+ return response . json ( )
182
+ } ) . then ( block )
183
+ } )
130
184
131
- } ) ;
132
- if ( chrome . webRequest . onBeforeRequest . hasListener ( callback ) ) {
133
- console . log ( 'Listning' )
134
185
}
135
186
136
- } ) ;
137
- } )
138
187
139
188
var callback = function deny ( block ) {
140
- chrome . storage . sync . get ( 'stat' , function ( res ) {
141
- if ( res . stat === undefined ) { var obj = { }
142
- chrome . storage . sync . set ( { 'stat' : obj } , function ( ) { } ) ;
143
- } else {
144
- var obj = res . stat ;
145
- chrome . tabs . query ( { active : true , lastFocusedWindow : true } , function ( tabs ) {
146
- console . log ( tabs [ 0 ] . url )
147
- var site = tabs [ 0 ] . url ;
148
- if ( ! ( site in obj ) ) {
149
- var l = site ;
150
- obj [ l ] = 1 ;
151
- chrome . storage . sync . set ( { 'stat' : obj } , function ( ) { } ) ;
152
-
153
- } else {
154
- var l = site ;
155
- obj [ l ] = obj [ l ] + 1 ;
156
- chrome . storage . sync . set ( { 'stat' : obj } , function ( ) { } ) ;
157
- }
158
- } ) ;
159
- }
160
- } ) ;
161
- return { cancel : true } ;
162
- }
189
+ chrome . storage . sync . get ( 'stat' , function ( res ) {
190
+ if ( res . stat === undefined ) { var obj = { }
191
+ chrome . storage . sync . set ( { 'stat' : obj } , function ( ) { } ) ;
192
+ } else {
193
+ var obj = res . stat ;
194
+ chrome . tabs . query ( { active : true , lastFocusedWindow : true } , function ( tabs ) {
195
+ console . log ( tabs [ 0 ] . url )
196
+ var site = tabs [ 0 ] . url ;
197
+ if ( ! ( site in obj ) ) {
198
+ var l = site ;
199
+ obj [ l ] = 1 ;
200
+ chrome . storage . sync . set ( { 'stat' : obj } , function ( ) { } ) ;
201
+
202
+ } else {
203
+ var l = site ;
204
+ obj [ l ] = obj [ l ] + 1 ;
205
+ chrome . storage . sync . set ( { 'stat' : obj } , function ( ) { } ) ;
206
+ }
207
+ } ) ;
208
+ }
209
+ } ) ;
210
+ return { cancel : true } ;
211
+ }
163
212
chrome . runtime . onMessage . addListener (
164
213
function ( request , sender , sendResponse ) {
165
- chrome . storage . sync . get ( 'stat' , function ( res ) {
166
- var obj = res . stat
167
- if ( res . stat === null ) {
168
- chrome . storage . sync . set ( { 'stat' : { } } , function ( ) { } ) ;
169
- } else {
170
- if ( ! ( request . site in obj ) ) {
171
- var l = request . site ;
172
- obj [ l ] = 1 ;
173
- chrome . storage . sync . set ( { 'stat' : obj } , function ( ) { } ) ;
174
-
175
- } else {
176
- var l = request . site ;
177
- obj [ l ] = obj [ l ] + 1 ;
178
- chrome . storage . sync . set ( { 'stat' : obj } , function ( ) { } ) ;
179
- }
180
- }
181
-
182
- } ) ;
183
-
184
-
185
- } ) ;
186
-
214
+ chrome . storage . sync . get ( 'stat' , function ( res ) {
215
+ var obj = res . stat
216
+ if ( res . stat === null ) {
217
+ chrome . storage . sync . set ( { 'stat' : { } } , function ( ) { } ) ;
218
+ } else {
219
+ if ( ! ( request . site in obj ) ) {
220
+ var l = request . site ;
221
+ obj [ l ] = 1 ;
222
+ chrome . storage . sync . set ( { 'stat' : obj } , function ( ) { } ) ;
223
+
224
+ } else {
225
+ var l = request . site ;
226
+ obj [ l ] = obj [ l ] + 1 ;
227
+ chrome . storage . sync . set ( { 'stat' : obj } , function ( ) { } ) ;
228
+ }
229
+ }
230
+ } ) ;
231
+ } )
232
+ start ( )
0 commit comments