-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from HoangTran0410/dev
Fix clickContentScript, onDocumentStart/Idle/End by correct world: MAIN/ISOLATED
- Loading branch information
Showing
15 changed files
with
112 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import("./scripts/ufs_global_webpage_context.js"); | ||
|
||
// communication between page-script and content-script | ||
(() => { | ||
function sendToPageScript(event, data) { | ||
window.dispatchEvent( | ||
new CustomEvent("ufs-contentscript-sendto-pagescript", { | ||
detail: { event, data }, | ||
}) | ||
); | ||
} | ||
window.addEventListener("ufs-pagescript-sendto-contentscript", async (e) => { | ||
let { event, data } = e.detail; | ||
switch (event) { | ||
case "getURL": | ||
sendToPageScript(event, chrome.runtime.getURL(data)); | ||
break; | ||
case "getActiveScripts": | ||
const key = "activeScripts"; | ||
let ids = (await chrome.storage.sync.get([key]))?.[key] || ""; | ||
let path = chrome.runtime.getURL("/scripts/"); | ||
sendToPageScript(event, { ids, path }); | ||
break; | ||
} | ||
}); | ||
})(); | ||
|
||
// Run script on user click (if clicked script has onClickContentScript event) | ||
(async () => { | ||
try { | ||
const { MsgType, ClickType } = await import("../helpers/constants.js"); | ||
const { isFunction } = await import("../helpers/utils.js"); | ||
|
||
chrome.runtime.onMessage.addListener(async function ( | ||
message, | ||
sender, | ||
sendResponse | ||
) { | ||
console.log("> Received message:", message); | ||
|
||
switch (message.type) { | ||
case MsgType.runScript: | ||
let scriptId = message.scriptId; | ||
const script = ( | ||
await import(chrome.runtime.getURL("/scripts/") + scriptId + ".js") | ||
)?.default; | ||
|
||
if (script && isFunction(script[ClickType.onClickContentScript])) { | ||
script[ClickType.onClickContentScript](); | ||
console.log("> Run script " + scriptId); | ||
} | ||
break; | ||
} | ||
}); | ||
} catch (e) { | ||
console.log("ERROR: ", e); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
(async () => { | ||
let key = "activeScripts"; | ||
let ids = (await chrome.storage.sync.get([key]))?.[key] || ""; | ||
window.dispatchEvent( | ||
new CustomEvent("ufs-run-page-scripts", { | ||
detail: { | ||
event: "onDocumentEnd", | ||
ids: ids.split(","), | ||
}, | ||
detail: { event: "onDocumentEnd" }, | ||
}) | ||
); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
(async () => { | ||
let key = "activeScripts"; | ||
let ids = (await chrome.storage.sync.get([key]))?.[key] || ""; | ||
window.dispatchEvent( | ||
new CustomEvent("ufs-run-page-scripts", { | ||
detail: { | ||
event: "onDocumentIdle", | ||
ids: ids.split(","), | ||
}, | ||
detail: { event: "onDocumentIdle" }, | ||
}) | ||
); | ||
})(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.