Skip to content

Instantly share code, notes, and snippets.

@anekos
Created June 8, 2010 15:22
Show Gist options
  • Select an option

  • Save anekos/430179 to your computer and use it in GitHub Desktop.

Select an option

Save anekos/430179 to your computer and use it in GitHub Desktop.
クリップボードのテキストを監視して自動で翻訳 - 要 multi_requester.js & google-translator.js
(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