// ==UserScript== // @name 随机写入100个不同字符到剪切板 // @namespace https://viayoo.com/6a4j69 // @version 1.0 // @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; let generatedStrings = []; let currentIndex = 0; let collisionCount = 0; let performanceLog = []; const generateAllUniqueStrings = (count) => { console.log(`开始预生成 ${count} 个唯一字符串...`); const startTime = performance.now(); const strings = new Set(); const baseChars = POOL.split(''); while (strings.size < count) { const rnd = Math.random(); let arr = [...baseChars]; 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]]; } let str; if (rnd < 0.7) { const len = 10 + Math.floor(Math.random() * 141); str = 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(''); str = 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' : ' '; str = result.split('').join(Math.random() < 0.3 ? chaos : ''); } if (strings.has(str)) { collisionCount++; const uniqueSuffix = '_' + Date.now() + '_' + performance.now().toString(36).replace('.', '') + Math.random().toString(36).substr(2, 4); str = str.substring(0, Math.max(10, str.length - 10)) + uniqueSuffix; } strings.add(str); if (strings.size % 100 === 0 || strings.size === count) { console.log(`已生成 ${strings.size}/${count} 个字符串,碰撞 ${collisionCount} 次`); } } const endTime = performance.now(); console.log(`预生成完成!耗时 ${(endTime - startTime).toFixed(2)}ms`); console.log(`总碰撞次数: ${collisionCount}`); console.log(`唯一性验证: ${strings.size === count ? '✓ 100% 不重复' : '✗ 存在重复'}`); return Array.from(strings); }; const copy = t => { const copyStart = performance.now(); let method = ''; if (typeof GM_setClipboard === 'function') { GM_setClipboard(t); method = 'GM_setClipboard'; } else if (navigator.clipboard?.writeText) { navigator.clipboard.writeText(t); method = 'navigator.clipboard'; } 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(); method = 'execCommand'; } const copyTime = performance.now() - copyStart; performanceLog.push({index: i, time: copyTime, method}); if (i % 10 === 0) { console.log(`第 ${i} 次复制,方法: ${method},耗时: ${copyTime.toFixed(2)}ms`); } }; const createBar = () => { bar = document.createElement('div'); bar.innerHTML = `