// ==UserScript== // @name 随机写入100个不同字符到剪切板 // @namespace https://viayoo.com/6a4j69 // @version 0.5 // @description 纯粹自用脚本,MIUI剪切板写入字符超过2w+后,底栏的无法显示剪切板内容,只有不断写入,超过限定剪切板数量,才能显示新的剪切板。 // @author Via // @match *://*/* // @grant GM_setClipboard // @grant GM_registerMenuCommand // @grant GM_getValue // @grant GM_setValue // @run-at document-idle // ==/UserScript== (() => { 'use strict'; const POOL = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789~!@#$%^&*_-+=<>?"; const TIMES = GM_getValue('copyTimes', 100); const sec = (TIMES * 60 / 1000).toFixed(1); let i = 0, bar = null; const rand100 = () => { const rnd = Math.random(); let arr = POOL.split(''); for (let x = arr.length - 1; x > 0; x--) { const j = Math.floor(Math.random() * (x + 1)); [arr[x], arr[j]] = [arr[j], arr[x]]; } if (rnd < 0.7) { const len = 10 + Math.floor(Math.random() * 141); return arr.slice(0, len).join(''); } else if (rnd < 0.9) { const p1 = arr.slice(0, 3 + Math.random() * 10 | 0).join(''); const p2 = arr.slice(15, 18 + Math.random() * 12 | 0).join(''); const p3 = arr.slice(30, 32 + Math.random() * 8 | 0).join(''); return p1 + p2 + p3; } else { let result = ''; const segs = 3 + Math.floor(Math.random() * 5); let start = 0; for (let s = 0; s < segs; s++) { const len = 1 + Math.floor(Math.random() * 20); result += arr.slice(start, start + len).join(''); start += len + 5; if (start >= arr.length) start = 0; } const chaos = Math.random() < 0.4 ? ' \n ' : Math.random() < 0.3 ? '\t' : ' '; return result.split('').join(Math.random() < 0.3 ? chaos : ''); } }; const copy = t => { if (typeof GM_setClipboard === 'function') GM_setClipboard(t); else if (navigator.clipboard?.writeText) navigator.clipboard.writeText(t); else { const e = document.createElement('textarea'); e.value = t; e.style.cssText = 'position:fixed;opacity:0'; document.body.appendChild(e); e.select(); document.execCommand('copy'); e.remove(); } }; const createBar = () => { bar = document.createElement('div'); bar.innerHTML = `