Last active
November 19, 2024 13:14
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==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()); | |
| } | |
| } | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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