即可把所選取字串丟至Google字典查詢
P.S.連input、textarea都通吃了
javascript: (function () {
function getInputText() {
var it = document.getElementsByTagName('input');
for (var i = 0; i < it.length; i++) {
if (it[i].type == 'text') {
var startPos = it[i].selectionStart;
var endPos = it[i].selectionEnd;
if (startPos == endPos) {
return 0;
}
return it[i].value.substring(startPos, endPos);
}
}
return 0;
}
function getTextarea() {
var ta = document.getElementsByTagName('textarea');
for (var j = 0; j < ta.length; j++) {
if (ta[j].selectionStart != ta[j].selectionEnd) return ta[j].value.substring(ta[j].selectionStart, ta[j].selectionEnd);
}
return 0;
}
var s = document.getSelection();
if (s.length == 0) s = getInputText();
if (s == 0) s = getTextarea();
if (s == 0) s = prompt('Enter a vocabulary.', '');
if (s.length != 0) window.open('http://www.google.com.tw/dictionary?aq=f&langpair=en|zh-TW&q=' + s + '&hl=zh-TW');
})()
Google字典