Greasy Fork is available in English.
代码剪贴板净化,解决复制代码旁边出现序号的问题
当前为
// ==UserScript==
// @name 代码剪贴板净化
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 代码剪贴板净化,解决复制代码旁边出现序号的问题
// @author Stu-Van
// @match *://*.zhihu.com/*
// @match *://*.jianshu.com/*
// @match *://*.csdn.net/*
// @match *://*.nowcoder.com/*
// @match *://*.juejin.im/*
// @match *://*.juejin.cn/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function clearText() {
var clipPromise = navigator.clipboard.readText();
var aa = [];
clipPromise.then(function (clipText) {
var lines = clipText.split("\n");
var num = lines.length.toString().length;
for (var index = 0; index < lines.length; index++) {
var element = lines[index];
var indexof = element.indexOf((index + 1));
if (indexof != -1) {
aa[index] = element.substring(num, element.length);
}else{
aa[index]=element;
}
}
}).then(function (data) {
writecontent(aa.join("\n"))
});
}
function writecontent(aa){
navigator.clipboard.writeText(aa).then(() => {
console.log('复制成功')
}).catch(() => {
const e = document.createElement('textarea')
document.body.appendChild(e)
e.innerHTML = aa;
e.select();
if (document.execCommand('copy')) {
document.execCommand('copy');
}
document.body.removeChild(e)
console.log('复制成功')
})
}
document.addEventListener('copy',clearText)
})();