Shanbay display

try to take over the world!

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Shanbay display
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  try to take over the world!
// @author       You
// @match        https://web.shanbay.com/wordsweb/*
// @grant        none
// ==/UserScript==

// 在小结界面隐藏结果,按enter显示
(function () {
    'use strict';

    // 得到总结页的中文解释并切换显示
    var toggleTable = function () {
        var item = document.querySelectorAll('td.StudySummaryItem_content__3j9YG');

        for (let i = 0; i < item.length; i++) {
            if(item[i].style.display === "none"){
                item[i].style.display = "block";
            } else {
                item[i].style.display = "none";
            }

        }
    };




    // get the list of wrong item and repeatly pronounce it;
    var i = 0;
    var pronounce = function(){
        var wrongItems = document.querySelectorAll('.wrong');
        if (wrongItems.length != 0){
            if(i>=wrongItems.length ){
                i=0;
            }
            wrongItems[i].querySelector('img').click();
            i=i+1;
        }

        // 为了单手操作, 复写p快捷键,单词背诵页的朗读
        var voice = document.querySelectorAll('.index_audio__2-vMp')
        if (voice.length !=0){
            voice[1].querySelector('img').click()
        }
        // 单词详情页的朗读,且不影响table页
        var voice2= document.querySelectorAll('.VocabPronounce_mlr10__3TCZu')
        if (voice2.length !=0){
            voice2[1].querySelector('img').click()
        }

    }

    // 复写9快捷键
    var delete9 = function(){
        var deletei = document.querySelectorAll('.index_simpleOption__2_XNF')
        deletei[0].click()
    }

    // 得到例句, 并循环发音
    var j = 0 ;
    var pronounceExam = function(){
        var examItems = document.querySelectorAll('.BayTrans_example__1kVZI');
        if (examItems.length != 0){
            // 防止刚进入时j过大,导致越界
            if(j>=examItems.length){
                j = 0;
            }
            examItems[j].querySelector('img').click();
            j=j+1;
        }
    }

    //添加键盘事件
    document.body.addEventListener('keydown',event => {
        switch (event.key){
            case 'Enter':
                toggleTable();
                // toggiecndf();
                break;
            case 'p':
                // pronounce the word in summary table
                pronounce();
                break;
            case 'r':
                // pronounce the word in summary table.
                pronounce();
                break;
            case 'e':
                // pronunce the example.
                pronounceExam();
                break;
            case '5':
                //delete
                delete9();
                break;
        }
    }
    )
    //当DOM树改变时触发,适合处理异步网页
    // 隐藏中文总结
    document.body.addEventListener("DOMSubtreeModified",function(){
        // var cndf = document.querySelector('.cndf>span');
        // if(cndf){
        // cndf.style.display = "none";
        // }
        var item = document.querySelectorAll('td.StudySummaryItem_content__3j9YG');
        for (let i = 0; i < item.length; i++) {
            item[i].style.display = "none";
        }
    },false)

})();