Skip to content

Instantly share code, notes, and snippets.

@TheFantasticWarrior
Last active November 19, 2024 13:14
Show Gist options
  • Save TheFantasticWarrior/a56b5c975818d9060ded8f8f3db07deb to your computer and use it in GitHub Desktop.
Save TheFantasticWarrior/a56b5c975818d9060ded8f8f3db07deb to your computer and use it in GitHub Desktop.
Japanese dictionary search from highlight, with bookmarklet and userscript depend on which is preferred
// ==UserScript==
// @name japanese search
// @namespace https://gist.github.com/TheFantasticWarrior/a56b5c975818d9060ded8f8f3db07deb
// @version 0.2
// @description Press Ctrl+J(Command+J on Mac) to search highlighted Japanese words with jisho.org or Ctrl+Shift+J for pronunciation on forvo.com
// @author TFW
// @include *
// @grant none
// ==/UserScript==
(function() {
'use strict';
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
document.addEventListener("keypress", checkKeyPressed, false);
function checkKeyPressed(e) {
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.keyCode == "106") {
window.open('https://forvo.com/search/'+getSelectionText());
} else if ((e.ctrlKey || e.metaKey) && e.keyCode == "106") {
window.open('https://jisho.org/search/'+getSelectionText());
}
}
})();
javascript:void(window.open('https://jisho.org/search/'+window.getSelection().toString()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment