mirror of
https://github.com/tiennm99/WPlace-AutoBOT.git
synced 2026-10-14 18:18:16 +00:00
feat: full migration to extension
This commit is contained in:
1 parent
266e2e8f97
commit
12e871ec26
19 files changed
+11363
-245
No files matched your search
@@ -125,7 +125,7 @@ if (window.location.hostname === 'wplace.live') {
|
||||
window.addEventListener('autobot-execute-script', async (event) => {
|
||||
const { scriptName } = event.detail;
|
||||
console.log(`%c📡 Content script received execution request for: ${scriptName}`, 'color: #00ff41; font-weight: bold;');
|
||||
|
||||
|
||||
// Execute the script using the content script's Chrome API access
|
||||
try {
|
||||
const response = await chrome.runtime.sendMessage({
|
||||
@@ -274,6 +274,76 @@ if (window.location.hostname === 'wplace.live') {
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener("message", (event) => {
|
||||
if (event.source !== window) return;
|
||||
if (event.data.source !== "my-userscript") return;
|
||||
const message = event.data;
|
||||
if (message.type === "setCookie" && message.value) {
|
||||
chrome.runtime.sendMessage(
|
||||
{ type: "setCookie", value: message.value },
|
||||
(response) => {
|
||||
if (response.status === "ok") {
|
||||
console.log("✅ Forwarded token to background.");
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener("message", (event) => {
|
||||
if (event.source !== window) return;
|
||||
const msg = event.data;
|
||||
if (msg && msg.source === "my-userscript") {
|
||||
if (msg.type === "getAccounts") {
|
||||
chrome.runtime.sendMessage({ type: "getAccounts" }, (response) => {
|
||||
if (response && response.accounts) {
|
||||
window.postMessage(
|
||||
{
|
||||
source: "extension",
|
||||
type: "accountsData",
|
||||
accounts: response.accounts,
|
||||
},
|
||||
"*"
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
chrome.runtime.onMessage.addListener((msg) => {
|
||||
if (msg.type === "cookieSet") {
|
||||
window.postMessage(
|
||||
{
|
||||
source: "my-extension",
|
||||
type: "cookieSet",
|
||||
value: msg.value,
|
||||
},
|
||||
"*"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener("message", (event) => {
|
||||
if (event.source !== window) return;
|
||||
const msg = event.data;
|
||||
if (msg?.type === "deleteAccount" && typeof msg.index === "number") {
|
||||
chrome.runtime.sendMessage(
|
||||
{ type: "deleteAccount", index: msg.index },
|
||||
(response) => {
|
||||
window.postMessage(
|
||||
{
|
||||
type: "deleteAccountResult",
|
||||
index: msg.index,
|
||||
status: response?.status || "error",
|
||||
},
|
||||
"*"
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Initialization
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
Reference in new issue
Block a user