DictVoice

选择单词 按下 ALT + S 稍等几秒即可朗读

As of 2015-10-20. See the latest version.

// ==UserScript==
// @name         DictVoice
// @namespace    http://www.fireawayh.info/about/
// @version      0.3
// @description  选择单词 按下 ALT + S 稍等几秒即可朗读
// @run-at      document-end
// @author       FireAwayH
// ==/UserScript==

var init = function(){
    console.log("DictVoiceStarting");
	var hideIframe = document.createElement("iframe");
	hideIframe.style.display = "none";
	hideIframe.id = "spellIt";
	document.body.appendChild(hideIframe);
	handeler();
}

var spellIt = function(){
	var word = window.getSelection().toString();
	if(!word.match(/ /)){
		var hideIframe = document.getElementById('spellIt');
		hideIframe.src = "https://dict.youdao.com/dictvoice?audio=" + word + "&type=1";
	}
}

var handeler = function(){
	document.addEventListener("keydown", function(event){
		if(event.altKey && event.keyCode == 83){
			spellIt();
		}
	}, false);
}

window.onload = function(){
	init();
}