Created
June 8, 2010 15:22
-
-
Save anekos/430179 to your computer and use it in GitHub Desktop.
クリップボードのテキストを監視して自動で翻訳 - 要 multi_requester.js & google-translator.js
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
| (function () { | |
| let handle; | |
| let start = function () { | |
| function get () | |
| liberator.modules.util.readFromClipboard().replace(/\n/g, ' ').trim(); | |
| if (handle) | |
| return; | |
| liberator.log('start: clipboard translater'); | |
| let prev = get(); | |
| handle = setInterval( | |
| function () { | |
| let current = get(); | |
| if (!current) | |
| return; | |
| if (prev == current) | |
| return; | |
| if (/(\S+\s){4}/(current)) { | |
| liberator.execute('gtrans ' + current); | |
| } else { | |
| liberator.execute('mr alc ' + current.replace(/[,.\s]+$/, '')); | |
| } | |
| liberator.echo(current); | |
| prev = current; | |
| }, | |
| 500 | |
| ); | |
| }; | |
| let stop = function () { | |
| if (!handle) | |
| return; | |
| liberator.log('stop: clipboard translater'); | |
| clearInterval(handle); | |
| handle = null; | |
| }; | |
| options.add( | |
| ['clipboardtranslater'], | |
| 'description', | |
| 'boolean', | |
| false, | |
| { | |
| setter: function (value) ((value ? start : stop)(), handle), | |
| getter: function () handle, | |
| } | |
| ); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment