//
UserScript// @name Paste Optimizer (Smooth)
// @namespace
https://example.com/// @version 1.2
// @description Makes paste processing smoother by batching character updates without UI lag
// @author You
// @match *://tw.2s4.me/*
// @run-at document-start
// @grant none
//
/UserScript(() => {
const _setTimeout = window.setTimeout;
const _splice = Array.prototype.splice;
//
- Non-blocking scheduler -
function runBatched(fn, args, repeat) {
let count = 0;
const step = () => {
if (count >= repeat) return;
fn(…args);
count++;
// Let browser render between batches
if (count < repeat) {
(window.requestIdleCallback || queueMicrotask)(step);
}
};
step();
}
//
- Override setTimeout -
window.setTimeout = function (fn, delay, …args) {
if (typeof fn
= "function" && args.length = 2) {
// Run in small asynchronous batches for smoother paste
runBatched(fn, args, 10);
return;
}
return _setTimeout(fn, delay, …args);
};
//
- Override Array.splice -
Array.prototype.splice = function (start, deleteCount, …items) {
if (start
= 0 && deleteCount = 50) {
// Smaller batches to avoid lockups
runBatched(() => _splice.call(this, start, deleteCount, …items), [], 5);
return this;
}
return _splice.call(this, start, deleteCount, …items);
};
})();