复制特定文本以复制javascript中的其他文本
我想让它看起来像是当我复制某样东西时,我会在剪贴板上得到另一些东西复制特定文本以复制javascript中的其他文本,javascript,Javascript,我想让它看起来像是当我复制某样东西时,我会在剪贴板上得到另一些东西 document.addEventListener('copy', function(e){ if(e.clipboardData.getData('Text').toString()==="@Trolluminati") e.clipboardData.setData ("Text", "<@325608201175433216>"); e.preventDefault(); }); documen
document.addEventListener('copy', function(e){
if(e.clipboardData.getData('Text').toString()==="@Trolluminati")
e.clipboardData.setData ("Text", "<@325608201175433216>");
e.preventDefault();
});
document.addEventListener('copy',函数(e){
if(例如clipboardData.getData('Text').toString()==“@Trolluminati”)
e、 clipboardData.setData(“文本”,“文本”);
e、 预防默认值();
});
Idk,如何使其将此特定文本的最后一个副本更改为另一个副本
现在,它只保留相同的复制文本,不进行更改。以下是一些可能有用的代码
if (document.queryCommandSupported('copy')) {
var textArea = document.createElement("textarea");
textArea.style.position = 'fixed';
textArea.style.top = '0';
textArea.style.left = '0';
textArea.style.width = '2em';
textArea.style.height = '2em';
textArea.style.padding = '0';
textArea.style.border = 'none';
textArea.style.outline = 'none';
textArea.style.boxShadow = 'none';
textArea.style.background = 'transparent';
textArea.value = INSERT WHATEVER YOU WANT TO COPY HERE
document.body.appendChild(textArea);
textArea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
document.body.removeChild(textArea);
}
document.addEventListener('copy',函数(e){
控制台日志(0);
如果(window.getSelection().toString().trim()=“@Trolluminati”)
e、 clipboardData.setData(“文本”,“文本”);
其他的
e、 clipboardData.setData(“Text”,window.getSelection().toString().trim());
e、 预防默认值();
});代码>文档。添加的列表器('copy',函数(e){
var selectedText=window.getSelection().toString();
如果(selectedText=='@Trolluminati'){
e、 预防默认值();
clipboardData=e.clipboardData | | window.clipboardData | | e.originalEvent.clipboardData;
setData('text','');
}
});
我已经创建了下一个代码。它在Chrome中对我有效
document.addEventListener('copy', function (event) {
event.preventDefault();
var copytext = window.getSelection() + '<@325608201175433216>';
if (event.clipboardData) {
event.clipboardData.setData('Text', copytext);
}
});
document.addEventListener('copy',函数(事件){
event.preventDefault();
var copytext=window.getSelection()+“”;
if(event.clipboardData){
event.clipboardData.setData('Text',copytext);
}
});
我的意思是,我想用鼠标选择文本(不是输入的文本),当我复制特定文本时,在这种情况下,“@Trolluminati”剪贴板将添加”“这是一种创建隐藏文本区域的方法,您可以从幕后复制。。试着用你想要的任何东西来替换插件。我用的是chrome,如果这有助于找出为什么插件不太好用的话,仍然保留原来的插件text@AmirBeraha那么我觉得你的问题还有很多你没有表现出来的地方,你的问题也在其他地方。好吧,我只想在复制的时候(使用ctrl c)在@troluminati上,它将允许粘贴(使用ctrl v)可能我忘了提到这一点,哎呀
document.addEventListener('copy', function (event) {
event.preventDefault();
var copytext = window.getSelection() + '<@325608201175433216>';
if (event.clipboardData) {
event.clipboardData.setData('Text', copytext);
}
});