diff options
author | tdro <tdro@noreply.example.com> | 2022-05-03 04:25:49 -0400 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2022-05-03 04:25:49 -0400 |
commit | e92dc018e28ba8d44f1c6cbc9fb0b779dec271e6 (patch) | |
tree | 3667043819ab91065019dfe3b4ff83ad625c2b49 /static/js/plumber.ts | |
download | canory-e92dc018e28ba8d44f1c6cbc9fb0b779dec271e6.tar.gz canory-e92dc018e28ba8d44f1c6cbc9fb0b779dec271e6.tar.bz2 canory-e92dc018e28ba8d44f1c6cbc9fb0b779dec271e6.zip |
config.yaml: Commission
Diffstat (limited to 'static/js/plumber.ts')
-rw-r--r-- | static/js/plumber.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/static/js/plumber.ts b/static/js/plumber.ts new file mode 100644 index 0000000..8e551fd --- /dev/null +++ b/static/js/plumber.ts @@ -0,0 +1,59 @@ +/** + * Plumber based on and inspired by + * Dictionary Access Copyright (C) 2006, Paul Lutus + * https://arachnoid.com/javascript/dictionary_access.js + * LICENSE: GPLv2+ + */ + +(function () { + const options = + "targetWindow,width=700,height=500,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes"; + + self.addEventListener("keydown", function (event) { + if (event.repeat && event.key === "d") { + selection(dictionary); + } + if (event.repeat && event.key === "s") { + selection(search); + } + if (event.repeat && event.key === "m") { + selection(manual); + } + }); + + function selection(execute) { + let phrase = "" + window.getSelection(); + phrase = phrase.replace(/[!.:?,;"]/g, ""); + phrase = phrase.replace(/^\s*(\S*?)\s*$/g, "$1"); + if (phrase && phrase > "" && phrase.length > 1) { + execute(phrase); + } + } + + function dictionary(word) { + window.open( + "https://www.merriam-webster.com/dictionary/" + + encodeURIComponent(word), + "Definitions", + options, + ); + } + + function search(phrase) { + window.open( + "https://lite.duckduckgo.com/lite/?q=" + + encodeURIComponent(phrase), + "Search", + options, + ); + } + + function manual(program) { + window.open( + "https://man.archlinux.org/search?q=" + + encodeURIComponent(program), + "Manual", + options, + ); + } +})(); |