油猴脚本

去除PDF复制时产生的回车

Posted by Liber Sun on July 30, 2019

油猴脚本大法好丫

pdf复制去回车脚本 记录下我写的一个油猴脚本

(function() {
    var txt = "";
    var id = "";
    var transButtonId=""
    var host = window.location.host;
    if( host == "fanyi.baidu.com" )
    {
       id = "baidu_translate_input";
        transButtonId="translate-button";
    }
    if( host == "fanyi.youdao.com" )
    {
       id = "inputOriginal";
        transButtonId="transMachine";
    }
    if( host == "translate.google.cn" || host == "translate.google.com" )
    {
       id = "source";
       //谷歌翻译好像没有按钮
    }


    var button = document.createElement('button');
    button.setAttribute('style','position:fixed;top:300px;left:30px;');
    button.textContent="Change";
    button.onclick=function(){
          txt = document.getElementById(id).value;
        for (var i=0;i<txt.length;i++)
        {
            if(txt.indexOf("\n"))txt = txt.replace("\n"," ");
        }
        document.getElementById(id).value = txt;

        transButtonId!==""?document.getElementById(transButtonId).click():console.log("谷歌大法好啊");

    }
    document.body.appendChild(button);
})();