// ==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 = `
0 / ${TIMES}
`; bar.style.cssText = 'position:fixed;top:50%;left:50%;transform:translate(-50%,-50%) scale(.92);min-width:300px;max-width:88vw;padding:24px 32px;background:rgba(255,255,255,.72);backdrop-filter:blur(20px) saturate(180%);-webkit-backdrop-filter:blur(20px) saturate(180%);border-radius:26px;border:1px solid rgba(255,255,255,.4);box-shadow:0 12px 32px rgba(0,0,0,.18),0 4px 12px rgba(0,0,0,.12);z-index:2147483647;pointer-events:none;text-align:center;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;opacity:0;transition:all .65s cubic-bezier(.22,1,.36,1)'; document.body.appendChild(bar); requestAnimationFrame(() => { bar.style.opacity = '1'; bar.style.transform = 'translate(-50%,-50%) scale(1)'; }); }; const progress = () => { if (!bar) createBar(); bar.firstElementChild.textContent = i + ' / ' + TIMES; bar.querySelector('#p').style.width = (i / TIMES * 100) + '%'; if (i >= TIMES) { const p = bar.querySelector('#p'); p.style.background = 'linear-gradient(90deg,#34C759,#32D74B)'; p.style.boxShadow = '0 0 24px rgba(52,199,89,.8)'; setTimeout(() => { bar.style.opacity = '0'; bar.style.transform = 'translate(-50%,-50%) scale(.92)'; setTimeout(() => bar?.remove(), 700); }, 900); } }; const run = () => { copy(rand100()); i++; progress(); }; const start = mode => { if (i > 0) return alert('请刷新页面后再操作'); i = 0; if (bar) bar.remove(); bar = null; progress(); if (mode === 'lightning') { while (i < TIMES) run(); } else { const id = setInterval(() => { if (i >= TIMES) clearInterval(id); else run(); }, 60); } }; GM_registerMenuCommand('光速复制 ' + TIMES + ' 次(瞬间完成)', () => start('lightning')); GM_registerMenuCommand('快速复制 ' + TIMES + ' 次(约' + sec + '秒)', () => start()); GM_registerMenuCommand('设置复制次数(当前 ' + TIMES + ' 次)', () => { const n = prompt('请输入要连续复制的次数(1~50000)', TIMES); if (n && /^\d+$/.test(n) && +n >= 1 && +n <= 50000) { GM_setValue('copyTimes', +n); location.reload(); } }); })();