Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- // =========================================================================
- // USER CONFIGURATION (Adjust speeds here)
- // =========================================================================
- const CONFIG = {
- PASTE_SPEED: 64, // Characters per second (e.g., 64, 128, 256)
- CLEAR_DELAY: 10 // Milliseconds to wait between clearing each coordinate
- };
- // =========================================================================
- // 1. Setup Global State
- window.clearState = window.clearState || {
- isRunning: false,
- _abortInternal: false
- };
- /**
- * Core Logic: Paste from Clipboard
- * Instantly schedules writing tasks using the configured speed.
- */
- window.pasteToArea = async function(startX, startY) {
- if (window.clearState.isRunning) return w.showToast("Task already running.");
- try {
- const rawText = await navigator.clipboard.readText();
- if (!rawText) return w.showToast("Clipboard is empty.");
- // Strip carriage returns to keep grid alignment accurate
- const text = rawText.replace(/\r/g, "");
- window.clearState.isRunning = true;
- window.clearState._abortInternal = false;
- w.showToast(`Pasting queued at ${startX}, ${startY} (~${CONFIG.PASTE_SPEED} char/s)...`);
- let currentX = startX;
- let currentY = startY;
- let typedCount = 0;
- // Dynamically calculate millisecond spacing based on config
- const MS_PER_CHAR = 1000 / CONFIG.PASTE_SPEED;
- for (let i = 0; i < text.length; i++) {
- const char = text[i];
- if (char === "\n") {
- currentX = startX;
- currentY++;
- continue;
- }
- if (char === " ") {
- currentX++;
- continue;
- }
- // Scope variables for the async execution block
- const targetX = currentX;
- const targetY = currentY;
- const targetChar = char;
- const executionDelay = typedCount * MS_PER_CHAR;
- // Non-blocking schedule
- setTimeout(() => {
- if (window.clearState._abortInternal) return;
- w.tp(targetX, targetY);
- w.typeChar(targetChar, 1);
- }, executionDelay);
- currentX++;
- typedCount++;
- }
- // Reset execution states when the background scheduler finishes
- setTimeout(() => {
- w.showToast(window.clearState._abortInternal ? "Paste stopped." : "Paste complete!");
- window.clearState.isRunning = false;
- window.clearState._abortInternal = false;
- }, typedCount * MS_PER_CHAR);
- } catch (err) {
- w.showToast("Error: Clipboard access denied. Focus the window!");
- window.clearState.isRunning = false;
- }
- };
- /**
- * Core Logic: Clear Area
- * Uses the configured clearing delay.
- */
- window.clearArea = async function(x1, y1, x2, y2) {
- if (window.clearState.isRunning) return w.showToast("Wait! Task in progress.");
- const startX = Math.min(x1, x2), endX = Math.max(x1, x2);
- const startY = Math.min(-y1, -y2), endY = Math.max(-y1, -y2);
- window.clearState.isRunning = true;
- window.clearState._abortInternal = false;
- try {
- let count = 0;
- for (let y = startY; y <= endY; y++) {
- for (let x = startX; x <= endX; x++) {
- if (window.clearState._abortInternal) break;
- const hasCheck = typeof getCharInfoXY === "function";
- const info = hasCheck ? getCharInfoXY(x, y) : null;
- if (!hasCheck || !info || (info && info.char !== " ")) {
- w.tp(x, y);
- w.typeChar(" ", 1);
- count++;
- await new Promise(r => setTimeout(r, CONFIG.CLEAR_DELAY));
- }
- }
- if (window.clearState._abortInternal) break;
- }
- w.showToast(window.clearState._abortInternal ? `Cleared stopped. Cleared ${count} coordinates.` : `Finished. Cleared ${count} coordinates.`);
- } finally {
- window.clearState.isRunning = false;
- window.clearState._abortInternal = false;
- }
- };
- /**
- * Stop Command (Authorized)
- */
- window.stop = function(user) {
- if (user === "dominoguy_") {
- window.clearState._abortInternal = true;
- w.showToast("Stop command accepted.");
- } else {
- w.showToast("Access Denied.");
- }
- };
- /**
- * Command Parser
- */
- window.cmd = function(input) {
- const parts = input.toString().trim().split(/\s+/);
- const action = parts[0].toLowerCase();
- if (action === "paste") {
- let x = parseInt(parts[1]);
- let y = parseInt(parts[2]);
- const finalX = isNaN(x) ? (typeof cursor !== "undefined" ? cursor.x : 0) : x;
- const finalY = isNaN(y) ? (typeof cursor !== "undefined" ? cursor.y : 0) : y;
- window.pasteToArea(finalX, finalY);
- } else if (action === "stop") {
- window.stop("dominoguy_");
- } else {
- const args = parts.map(n => parseInt(n));
- if (args.length === 2 && !isNaN(args[0])) {
- window.clearArea(args[0], args[1], args[0], args[1]);
- } else if (args.length === 4 && !args.some(isNaN)) {
- window.clearArea(args[0], args[1], args[2], args[3]);
- } else {
- w.showToast("Usage: cmd('paste [x y]'), cmd('stop'), or cmd('x1 y1 [x2 y2]')");
- }
- }
- };
- w.showToast(`Turbo-Paste Ready! Config: ${CONFIG.PASTE_SPEED} ch/s. Use cmd('paste') at your cursor.`);
- })();
Advertisement
Comments
-
- the first 2 numbers in the command are the upper left corner, and the other 2 are the lower right corner.
-
- i am inspired :D
-
- Usage Guide
- Paste at Cursor: Hover your mouse/cursor where you want the text to start and type cmd('paste'). It will use cursor.x and cursor.y automatically.
- Paste at Manual Coords: Type cmd('paste 100 200') if you want to specify a location regardless of your cursor.
- Aborting: If you paste a massive wall of text and need to stop, type stop('dominoguy_') or your cursor name.
- Clearing: Continue using cmd('x1 y1 x2 y2') to wipe areas.
-
- Be sure to disable "copy colors" & "copy decorations" in the options menu, bc it can't paste colors yet, only b & w.
-
Comment was deleted
-
- the y axis is flipped, will fix it later.
Add Comment
Please, Sign In to add comment