V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  amiwrong123  ›  全部回复第 38 页 / 共 38 页
回复总数  745
1 ... 29  30  31  32  33  34  35  36  37  38  
@caocong
```javascript
document.getElementById("source").onfocus = function(){
navigator.clipboard.readText().then(
clipText => {document.getElementById("source").value = clipText;})
setTimeout(()=> {
var a = document.getElementsByClassName('tlid-translation')[0];
var result = ''
//console.log(a.children.length);
for (var i = 0; i < a.children.length; i++){
//console.log(a.children[i].tagName);
if(a.children[i].tagName == 'SPAN' )
{//console.log(a.children[i].innerText);
result += a.children[i].innerText;
}else{
result += '\n';
}
}
navigator.clipboard.writeText(result)},2000);


};
```
原来大括号可以把语句框起来,这样就可以了。这样就解决了左边框有换行的情况。再次感谢啦。
@caocong
刚才我还在想怎么解决,对话,延时就好了。谢谢大佬。
但如果左边框有换行符,有边框 tlid-translation 里面的 children 不止一个,类似于:
<span title="" class="">遷移 Transition to the Audio </span>
<br>
<span title="" class="">遷移 Transition to the Audio </span>
这个好像不好弄,看语法好像没法写循环啊
@caocong
我在看一下,能不能把粘贴板的内容,替换为谷歌翻译的右边框的内容(翻译后的内容)。
@caocong
谢谢,好使了。但好使粘贴板里的内容如果是日文,好像有编码问题。我再百度百度吧。代码就是
```javascript
document.getElementById("source").onfocus = function(){
navigator.clipboard.readText().then(
clipText => {document.getElementById("source").value = clipText;})
}
```
还是说,我得在火狐的配置文件里面改什么吗? about:config 里面的 clipboard.autocopy 已经被我改成 true 了,但还是不好使。
1 ... 29  30  31  32  33  34  35  36  37  38  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1158 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 16ms · UTC 22:55 · PVG 06:55 · LAX 15:55 · JFK 18:55
Developed with CodeLauncher
♥ Do have faith in what you're doing.