Created
May 2, 2017 23:40
-
-
Save sheodox/b54a91023254fe0b979e3ca4f093d7cf to your computer and use it in GitHub Desktop.
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 Jisho Hotkeys | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description Hotkeys for some actions on jisho.org | |
// @author sheodox | |
// @match http://jisho.org/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function handle(code) { | |
const searchField = document.querySelector('#keyword'), | |
firstResult = document.querySelector('.concept_light-representation .text').textContent.trim(); | |
switch (code) { | |
case 83: //s | |
searchField.focus(); | |
searchField.select(); | |
break; | |
case 67: //c | |
//copy | |
searchField.select(); | |
document.execCommand('copy'); | |
break; | |
case 87: //w | |
//open search for first word on dictionary.goo.ne.jp | |
window.open('http://dictionary.goo.ne.jp/srch/all/' + encodeURIComponent(firstResult) + '/m0u/'); | |
break; | |
default: | |
return false; | |
} | |
return true; | |
} | |
document.body.addEventListener('keydown', e => { | |
if (e.target.tagName.toLowerCase() !== 'input') { | |
if (handle(e.which)) { | |
e.preventDefault(); | |
} | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment