Greasy Fork

Greasy Fork is available in English.

有道詞典自動發音

有道词典自动发音

当前为 2020-07-30 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         有道詞典自動發音
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  有道词典自动发音
// @author       You
// @match        *://dict.youdao.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var nav = document.getElementById("nav");
    var action;

    var noPronounce = document.createElement("input")
    noPronounce.type = "radio";
    noPronounce.name = "radio";
    noPronounce.id = "nopronounce";
    noPronounce.onclick = function(){
        action = 0;
        localStorage.setItem("Action", 0);
    };
    nav.insertBefore(noPronounce,nav.childNodes[-1]);

    var noPronounceLabel = document.createElement("label")
    noPronounceLabel.innerHTML = "不發音";
    nav.insertBefore(noPronounceLabel,nav.childNodes[-1]);


    var BritishPronounce = document.createElement("input")
    BritishPronounce.type = "radio";
    BritishPronounce.name = "radio";
    BritishPronounce.id = "british";
    BritishPronounce.onclick = function(){
        action = 1;
        localStorage.setItem("Action", 1);
    };
    nav.insertBefore(BritishPronounce,nav.childNodes[-1]);

    var BritishPronounceLabel = document.createElement("label")
    BritishPronounceLabel.innerHTML = "發英音";
    nav.insertBefore(BritishPronounceLabel,nav.childNodes[-1]);


    var AmericanPronounce = document.createElement("input")
    AmericanPronounce.type = "radio";
    AmericanPronounce.name = "radio";
    AmericanPronounce.id = "american";
    AmericanPronounce.onclick = function(){
        action = 2;
        localStorage.setItem("Action", 2);
    };
    nav.insertBefore(AmericanPronounce,nav.childNodes[-1]);

    var AmericanPronounceLabel = document.createElement("label")
    AmericanPronounceLabel.innerHTML = "發英音";
    nav.insertBefore(AmericanPronounceLabel,nav.childNodes[-1]);

    var voice233 = document.getElementsByClassName('sp dictvoice voice-js log-js');

    var nopronounce = document.getElementById("nopronounce");
    var british = document.getElementById("british");
    var american = document.getElementById("american");

    var newItem=document.createElement("audio");
    var demo = document.getElementsByClassName("s-btn")[0];
    demo.insertBefore(newItem,demo.childNodes[0]);


    for(let i=0; i<=voice233.length-1; i++){
        voice233[i].onclick = function(){
            document.getElementsByTagName('audio')[0].src = 'http://dict.youdao.com/dictvoice?audio=' + voice233[i].dataset.rel;
            document.getElementsByTagName('audio')[0].currentTime = 0;
            document.getElementsByTagName('audio')[0].play();
        }
    }



    if(localStorage.getItem("Action")){
        action = localStorage.getItem("Action");
        console.log(action);
        if(action == 1){
            british.checked = true;
            voice233[0].onclick();

        }
        else if(action == 0){
            nopronounce.checked = true;
        }
        else if(action == 2){
            american.checked = true;
            voice233[1].onclick();
        }

    }else{
        action = 0;
        nopronounce.checked = true;
    }





})();