JavaScript自动复制网页中6位数字,在书签栏可以使用
以下是一个JavaScript代码,可以在网页中自动复制6位数字到剪贴板中:
javascript:(function(){ var matches = document.body.innerText.match(/\b\d{6}\b/g); if (matches && matches.length > 0) { var input = document.createElement('input'); input.style.position = 'fixed'; input.style.opacity = 0; document.body.appendChild(input); input.value = matches[0]; input.select(); document.execCommand('copy'); document.body.removeChild(input); } else { alert('没有找到6位数字!'); } })();
要将其添加到书签栏,请按照以下步骤操作:
-
在浏览器中创建一个新书签。
-
在“名称”字段中输入任何您想要的名称(例如“复制6位数字”)。
-
在“网址”字段中输入上面的JavaScript代码。
-
单击“保存”以保存书签。
现在,当您在浏览网页时,只需单击此书签,它将在网页中查找任何6位数字,并将其复制到剪贴板中。如果找不到任何6位数字,则会显示一条警告消息。
原文地址: https://www.cveoy.top/t/topic/u86 著作权归作者所有。请勿转载和采集!