V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
V2EX  ›  amiwrong123  ›  全部回复第 47 页 / 共 47 页
回复总数  925
1 ... 38  39  40  41  42  43  44  45  46  47  
@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 ... 38  39  40  41  42  43  44  45  46  47  
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2515 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 14ms · UTC 00:37 · PVG 08:37 · LAX 17:37 · JFK 20:37
♥ Do have faith in what you're doing.