1
+ chrome . webRequest . onBeforeRequest . addListener ( onBeforeRequest ,
2
+ { urls : [ "https://draft.blogger.com/_/BloggerUi/data/*" ] , types : [ "xmlhttprequest" ] }
3
+ ) ;
4
+
1
5
chrome . webRequest . onCompleted . addListener ( onRequestCompleted ,
2
6
{ urls : [ "https://draft.blogger.com/_/BloggerUi/data/*" ] , types : [ "xmlhttprequest" ] }
3
7
) ;
4
8
5
- function onRequestCompleted ( details ) {
9
+ let isNotifiedForErrors = false ;
10
+
11
+ function onBeforeRequest ( ) {
12
+ isNotifiedForErrors = false ;
13
+ }
14
+
15
+ function waitUntil ( stateCheckCallback , delay = 100 ) {
16
+ return new Promise ( resolve => {
17
+ let interval = setInterval ( ( ) => {
18
+ let shouldResolve = stateCheckCallback ( ) ;
19
+ if ( shouldResolve ) {
20
+ clearInterval ( interval ) ;
21
+ resolve ( ) ;
22
+ }
23
+ } , delay ) ;
24
+ } ) ;
25
+ }
26
+
27
+ let waitTimeout ;
28
+
29
+ async function onRequestCompleted ( details ) {
6
30
7
31
if ( ! details . url . includes ( 'rpcids=ZmRkFc' ) ) return ;
8
-
32
+
33
+ waitTimeout = setTimeout ( ( ) => {
34
+ isNotifiedForErrors = true ;
35
+ sendNotif ( 'Check for errors' ) ;
36
+ } , 1000 ) ;
37
+ }
38
+
39
+ function sendNotif ( message ) {
40
+
9
41
let notifId = '1' ;
10
42
const notificationOptions = {
11
43
type : 'basic' ,
12
44
iconUrl : "data:image/webp;base64,UklGRiIBAABXRUJQVlA4TBUBAAAvH8AHAH/AJgDAJNMo6/8vjbsb8FHDSCQp675/ETKhUCgKoCaSFGlsIB5JaCCnyN7Lbv4D4P/flT5lC5QSUOHABniGRfBybZ80y3YB3GrblidVBviti2eYtPrEPQE2YIPICqwQrdA3UlH9tFRU7u5u3/viA0T0fwK0f9Jz/pVzzfO59ZfTkxXnJ9bzKBRgO6URWFtYz3CzTm50XQBwXYDNrGfGjwDGj1jmCOKsUxnCEQbgCANSSAkBa0ywDHU6EOeaU6g1gfpMfJWpx2FpwMQUmBGAWhPqJ8RtZfyVc2SkWaXQIoEIbk17fV0iZZbaD2m3pmlaf4nUdsv9ypy3WkTUbh1o4mu/1Wq1DtySdv56enLi1v5HAA==" ,
13
- title : `Done. Refresh blog page or check errors. ` ,
14
- message : `` ,
45
+ title : `` ,
46
+ message,
15
47
requireInteraction : true ,
16
48
} ;
17
49
chrome . notifications . create ( notifId , notificationOptions ) ;
18
50
19
- // execInPage('console.log(123)');
20
-
21
-
22
51
setTimeout ( function ( ) {
23
52
chrome . notifications . clear ( notifId ) ;
24
53
} , 2000 ) ;
25
-
26
54
}
27
55
28
56
@@ -47,10 +75,11 @@ async function execInPage(code) {
47
75
// background.js
48
76
chrome . runtime . onMessage . addListener ( function ( request , sender , sendResponse ) {
49
77
if ( request . action === 'sendMessageFromBackground' ) {
50
- console . log ( 'Message received in background:' , request . data ) ;
51
-
52
- // Send a response back to the content script
53
- // sendResponse({ response: 'Response from background' });
78
+ if ( request . data == 200 ) {
79
+ clearInterval ( waitTimeout ) ;
80
+ if ( ! isNotifiedForErrors ) {
81
+ sendNotif ( 'Template updated' ) ;
82
+ }
83
+ }
54
84
}
55
- } ) ;
56
-
85
+ } ) ;
0 commit comments