diff options
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, + ); + } +})(); |