mirror of
https://github.com/tiennm99/WPlace-AutoBOT.git
synced 2026-10-11 12:08:55 +00:00
Merge pull request #203 from SKProCH/main
Fix account swapping order, make charges increment local, make droplets updatable
This commit is contained in:
4 files changed
+11520
-11354
No files matched your search
@@ -13,29 +13,6 @@ chrome.runtime.onInstalled.addListener(async () => {
|
||||
console.log('📦 Installation resource test:', resources);
|
||||
});
|
||||
|
||||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
if (request.action === 'executeScript') {
|
||||
// Get tabId from sender or requests
|
||||
const tabId = request.tabId || sender.tab?.id;
|
||||
|
||||
if (!tabId) {
|
||||
sendResponse({ success: false, error: 'Could not determine target tab' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Use IIFE for async handlings
|
||||
(async () => {
|
||||
try {
|
||||
await executeLocalScript(request.scriptName, tabId);
|
||||
sendResponse({ success: true });
|
||||
} catch (error) {
|
||||
sendResponse({ success: false, error: error.message });
|
||||
}
|
||||
})();
|
||||
|
||||
return true; // Important: indicates async response
|
||||
}
|
||||
});
|
||||
|
||||
async function executeLocalScript(scriptName, tabId) {
|
||||
try {
|
||||
|
||||
@@ -7517,38 +7517,16 @@
|
||||
return;
|
||||
}
|
||||
|
||||
swapAccountTrigger(nextToken);
|
||||
|
||||
let maxRetries = 20;
|
||||
let retryCount = 0;
|
||||
let swapSuccess = false;
|
||||
|
||||
while (!swapSuccess && retryCount < maxRetries) {
|
||||
console.log(`⏳ Waiting for account swap... (Attempt ${retryCount + 1}/${maxRetries})`);
|
||||
|
||||
// Wait for a short period before checking.
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
|
||||
try {
|
||||
await fetchAccount();
|
||||
|
||||
console.log("✅ Account swap confirmed.");
|
||||
swapSuccess = true;
|
||||
} catch (error) {
|
||||
console.warn("❌ Account swap not yet successful. Retrying...", error);
|
||||
retryCount++;
|
||||
}
|
||||
}
|
||||
const swapSuccess = await swapAccountTrigger(nextToken);
|
||||
|
||||
if (swapSuccess) {
|
||||
|
||||
const { charges, cooldown } = await WPlaceService.getCharges();
|
||||
state.currentCharges = Math.floor(charges);
|
||||
state.cooldown = cooldown;
|
||||
Utils.performSmartSave();
|
||||
updateStats();
|
||||
} else {
|
||||
console.error("❌ Failed to swap account after multiple retries. Stopping loop.");
|
||||
console.error("❌ Failed to swap account after confirmation timeout. Stopping loop.");
|
||||
state.stopFlag = true;
|
||||
}
|
||||
}
|
||||
@@ -7800,7 +7778,7 @@
|
||||
const token = accountsTokens[i];
|
||||
|
||||
console.log(`🔄 Refreshing account ${i + 1}/${accountsTokens.length} for data collection only...`);
|
||||
swapAccountTrigger(token);
|
||||
await swapAccountTrigger(token);
|
||||
|
||||
let retries = 0;
|
||||
let swapped = false;
|
||||
@@ -7834,7 +7812,7 @@
|
||||
|
||||
if (originalToken) {
|
||||
console.log("🔄 Switching back to original account after data collection...");
|
||||
swapAccountTrigger(originalToken);
|
||||
await swapAccountTrigger(originalToken);
|
||||
}
|
||||
await Utils.sleep(1000);
|
||||
|
||||
@@ -8486,15 +8464,44 @@
|
||||
console.error("An error occurred during the purchase:", e);
|
||||
}
|
||||
}
|
||||
function swapAccountTrigger(token) {
|
||||
async function waitForCookieSet(timeout = 10000) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const onMessage = (event) => {
|
||||
if (event.source !== window) return;
|
||||
const data = event.data || {};
|
||||
if (data.type === 'cookieSet') {
|
||||
window.removeEventListener('message', onMessage);
|
||||
clearTimeout(timer);
|
||||
resolve(true);
|
||||
}
|
||||
};
|
||||
const timer = setTimeout(() => {
|
||||
window.removeEventListener('message', onMessage);
|
||||
reject(new Error('cookieSet timeout'));
|
||||
}, timeout);
|
||||
window.addEventListener('message', onMessage);
|
||||
});
|
||||
}
|
||||
async function swapAccountTrigger(token) {
|
||||
localStorage.removeItem("lp");
|
||||
if (!token) return;
|
||||
if (!token) {
|
||||
console.error('❌ Cannot swap account: token is null or undefined');
|
||||
return false;
|
||||
}
|
||||
console.log("Sending token to extension...");
|
||||
window.postMessage({
|
||||
source: 'my-userscript',
|
||||
type: 'setCookie',
|
||||
value: token
|
||||
}, '*');
|
||||
try {
|
||||
await waitForCookieSet(10000);
|
||||
console.log('✅ Cookie set confirmed');
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.warn('⚠️ No cookieSet confirmation:', e.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
async function getAccounts() {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
+11482
-11301
File diff suppressed because it is too large.
Load diff
@@ -595,9 +595,10 @@
|
||||
console.log('✅ Found wasm Module...');
|
||||
return url.split('/').pop();
|
||||
}
|
||||
} catch { }
|
||||
} catch (e) { /* ignore individual fetch errors */ }
|
||||
}
|
||||
console.error(`❌ Could not find Pawtect chunk with string: ${str}`);
|
||||
console.error('❌ Could not find Pawtect chunk among preloaded modules');
|
||||
return null;
|
||||
}
|
||||
|
||||
// Audio notification system
|
||||
|
||||
Reference in new issue
Block a user