28 lines
944 B
TypeScript
Executable file
28 lines
944 B
TypeScript
Executable file
/**
|
||
* Stop/pause control helpers for browser scripts
|
||
* Generates JavaScript code strings for script control
|
||
*/
|
||
|
||
export function generateControlHelpers(storageKey: string): string {
|
||
return `
|
||
// ============== STOP CONTROL ==============
|
||
window.STOP_SCRIPT = false;
|
||
window.PAUSE_SCRIPT = false;
|
||
console.log('%c⏹️ To stop: window.STOP_SCRIPT = true', 'color: orange');
|
||
console.log('%c⏸️ To pause: window.PAUSE_SCRIPT = true', 'color: orange');
|
||
console.log('%c🗑️ To reset: localStorage.removeItem("${storageKey}")', 'color: orange');
|
||
|
||
async function checkStopPoints() {
|
||
if (window.STOP_SCRIPT) {
|
||
console.log('%c🛑 Stopped', 'color: red');
|
||
return true;
|
||
}
|
||
while (window.PAUSE_SCRIPT) {
|
||
console.log('%c⏸️ Paused...', 'color: yellow');
|
||
await sleep(1000);
|
||
if (window.STOP_SCRIPT) return true;
|
||
}
|
||
return false;
|
||
}
|
||
// ==========================================`;
|
||
}
|