DictVoice

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

As of 2015-10-20 14:08:32 UTC. See the latest version.

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

var init = function(){
	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();
}