Greasy Fork

来自缓存

Greasy Fork is available in English.

多邻国diy开发

多邻国做题配合划词翻译显示翻译文本

当前为 2024-04-25 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        多邻国diy开发
// @description 多邻国做题配合划词翻译显示翻译文本
// @match       https://www.duolingo.com/*
// @require     https://code.jquery.com/jquery-3.4.1.js
// @version 1.3.6.1
// @namespace http://greasyfork.icu/users/157318
// ==/UserScript==


function isLesson() {
    return /https:\/\/www.duolingo.com\/(lesson|practice|skill.*)/.test(window.location.href);
}
// 添加css
  function addStyle(css) {
    var style = document.createElement('style');
    style.innerHTML = css;
    document.head.appendChild(style);
  }




function fy(){
    var mydiv=$("#myDiv");
    if (mydiv.length==1){
        $("#myDiv").remove();
        return;
    }
    var fanyi=$("._2-F7v");//一个词一个词的$("div[dir=ltr]")中的第二个div
    //alert($("title").text());
    var strone="";
    if (fanyi.length==1){//一个一个词拼句子
        for(var i=0;i<fanyi.find("div").length;i++){
            //品句子
            strone=strone+fanyi.find("div").eq(i).text()+" ";
        }
        fanyi.append("<div id='myDiv' style='font-size: 0px;margin-left: 30%;'>"+strone+"</div>");
        //$("#myDiv").focus();
        window.getSelection().selectAllChildren(document.getElementById("myDiv"));
        $("#__hcfy__")[0].shadowRoot.querySelector(".bp5-button").click();
        window.getSelection().removeAllRanges();
        console.log(strone);
        return;
    }
    var tiankong=$("div[dir=ltr]");
    if (tiankong.length>0){//填空题品句子
        var tiankongstr=tiankong[0].innerText.replaceAll("\n","");
        tiankong.append("<div id='myDiv' style='font-size: 0px;margin-left: 30%;'>"+tiankongstr+"</div>");
        //$("#myDiv").focus();
        window.getSelection().selectAllChildren(document.getElementById("myDiv"));
        $("#__hcfy__")[0].shadowRoot.querySelector(".bp5-button").click();
        window.getSelection().removeAllRanges();
        console.log(tiankongstr);
        return;
    }
    tiankong=$("label[dir=ltr]");//填空单词句子,有input
    if (tiankong.length==1){//填空
        tiankongstr=tiankong[0].textContent.replaceAll("\n","");
        tiankongstr=tiankongstr.replaceAll("_","");
        tiankong.append("<div id='myDiv' style='font-size: 0px;;margin-left: 30%;'>"+tiankongstr+"</div>");
        //$("#myDiv").focus();
        window.getSelection().selectAllChildren(document.getElementById("myDiv"));
        $("#__hcfy__")[0].shadowRoot.querySelector(".bp5-button").click();
        window.getSelection().removeAllRanges();
        console.log(tiankongstr);
        return;
    }

}
function addfy(){
    if ($("#benty4").length==0){

        $("._3v4ux").append("<button id='benty4' style='float:right;'>翻译</button>");
        $("._1fxa4._1Mopf").eq(0).css("overflow","auto");
        $("#benty4").click(function(){fy();});

    }
}

$(function(){//页面加载完成执行

     addStyle('html, * {-webkit-user-select:text!important; -moz-user-select:text!important;}');

    setTimeout(() => {
        addfy();
    }, 5000);
    $("body").click(function(){addfy();});

});


window.addEventListener("keydown", function(e) {
    var key = e.key.toLowerCase();

    if (isLesson()) {

        if ($("#benty4").length==0){
            addfy();
        }
        if (key == "f2") {
            fy();
        }
        if (key == "f8") {
            $("span[dir=ltr]").eq(0).find("button").click();


            var isFocus=$("textarea").is(":focus");
            if(true==isFocus){
                console.log('有focus');
                var ev = $.Event('keypress');
                ev.which = 74; // Carriage-return (Enter)
                $('textarea').trigger(ev);
            }else{
                $("textarea").focus();
                console.log('没有focus');
            }/**/
        }
        if (key == "f9") {
            $("span[dir=ltr]").eq(1).find("button").click();
        }/*
        if (key == "escape") {
            $(".yWRY8._3yAjN").eq(0).click();
        }
        // discussion shortcut
        if (key == "d") {
            $("span:contains(Discuss)").click();
        }

        // report shortcut
        if (key == "r") {
            $("span:contains(Report)").click();
        }

        // keyboard toggle
        if (key == "b" && e.ctrlKey) {
            e.preventDefault();
            $("button[data-test=player-toggle-keyboard]").click();
        }*/

    }
});