|
1 | 1 | (async () => { |
2 | | - // https://stackoverflow.com/a/53033388 |
3 | | - const { getURL, injectScript, injectCss } = await import("./utils.js"); |
4 | | - injectScript(getURL("useful-scripts-utils.js")); |
| 2 | + try { |
| 3 | + const { MsgType, Events, ClickType: OnClickType } = await import( |
| 4 | + "../helpers/constants.js" |
| 5 | + ); |
| 6 | + const { sendEventToBackground, isFunction } = await import( |
| 7 | + "../helpers/utils.js" |
| 8 | + ); |
5 | 9 |
|
6 | | - // injectScript(getURL("bypass_all_shortlink.js")); |
7 | | - // injectScript(getURL("track_settimeout.js")); |
8 | | - // injectScript(getURL("globals_debugger.js")); |
9 | | - // if (location.hostname === "mp3.zing.vn") |
10 | | - // injectScript(getURL("mp3.zing.vn.js")); |
11 | | - // if (location.hostname === "www.instagram.com") { |
12 | | - // injectCss(getURL("instagram.css")); |
13 | | - // injectScript(getURL("instagram_downloadBtn.js")); |
14 | | - // } |
15 | | - // if (location.hostname === "www.studyphim.vn") |
16 | | - // injectScript(getURL("studyphim.js")); |
17 | | - // if (location.hostname === "www.studocu.com") |
18 | | - // injectCss(getURL("studocu.css")); |
19 | | -})(); |
20 | | - |
21 | | -(async () => { |
22 | | - const { allScripts } = await import("../index.js"); |
23 | | - const { MsgType, Events, ScriptType, OnClickType } = await import( |
24 | | - "../helpers/constants.js" |
25 | | - ); |
26 | | - const { runAllScriptWithEventType, sendEventToBackground, isFunction } = |
27 | | - await import("../helpers/utils.js"); |
| 10 | + sendEventToBackground({ |
| 11 | + type: MsgType.runScript, |
| 12 | + event: Events.onDocumentStart, |
| 13 | + }); |
28 | 14 |
|
29 | | - runAllScriptWithEventType( |
30 | | - Events.document_start, |
31 | | - ScriptType.contentScript, |
32 | | - location.href |
33 | | - ); |
| 15 | + const { allScripts } = await import("../index.js"); |
| 16 | + chrome.runtime.onMessage.addListener(function ( |
| 17 | + message, |
| 18 | + sender, |
| 19 | + sendResponse |
| 20 | + ) { |
| 21 | + console.log("> Received message:", message); |
34 | 22 |
|
35 | | - sendEventToBackground({ |
36 | | - type: MsgType.runScript, |
37 | | - event: Events.document_start, |
38 | | - }); |
| 23 | + switch (message.type) { |
| 24 | + // run script on receive event from popup |
| 25 | + case MsgType.runScript: |
| 26 | + let scriptId = message.scriptId; |
| 27 | + if ( |
| 28 | + scriptId in allScripts && |
| 29 | + isFunction(allScripts[scriptId][OnClickType.onClickContentScript]) |
| 30 | + ) { |
| 31 | + allScripts[scriptId][OnClickType.onClickContentScript](); |
| 32 | + console.log("> Run script " + scriptId); |
| 33 | + } |
| 34 | + break; |
| 35 | + } |
| 36 | + }); |
39 | 37 |
|
40 | | - // run script on receive event from popup |
41 | | - chrome.runtime.onMessage.addListener(function ( |
42 | | - message, |
43 | | - sender, |
44 | | - sendResponse |
45 | | - ) { |
46 | | - console.log("> Received message:", message); |
47 | | - switch (message.type) { |
48 | | - case MsgType.runScript: |
49 | | - let scriptId = message.scriptId; |
50 | | - if ( |
51 | | - scriptId in allScripts && |
52 | | - isFunction(allScripts[scriptId][OnClickType.onClickContentScript]) |
53 | | - ) { |
54 | | - allScripts[scriptId][OnClickType.onClickContentScript](); |
55 | | - console.log("> Run script " + scriptId); |
56 | | - } |
57 | | - break; |
58 | | - } |
59 | | - }); |
| 38 | + // https://stackoverflow.com/a/53033388 |
| 39 | + const { getURL, injectScript, injectCss } = await import("./utils.js"); |
| 40 | + injectScript(getURL("useful-scripts-utils.js")); |
| 41 | + } catch (e) { |
| 42 | + console.log("ERROR: ", e); |
| 43 | + } |
60 | 44 | })(); |
0 commit comments