/* {{{ Copyright (c) 2008, anekos. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ################################################################################### # http://sourceforge.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license # # に参考になる日本語訳がありますが、有効なのは上記英文となります。 # ################################################################################### }}} */ // PLUGIN_INFO {{{ let PLUGIN_INFO = translaten 自動一括翻訳 Automatically translate by clipboard changes クリップボードの変更を監視して、一括翻訳サービスに流し込む 1.0 anekos new BSD License (Please read the source code comments of this plugin) 修正BSDライセンス (ソースコードのコメントを参照してください) 2.0pre 2.0pre || set translaten ||< ]]> || set translaten ||< で、有効化した後に、クリップボードに変化があれば、その内容を 'http://7go.biz/translation/' に流し込んで翻訳します。 == Link == http://vimperator.g.hatena.ne.jp/nokturnalmortum/20090104/1231070505 ]]> ; // }}} (function () { const URL = 'http://7go.biz/translation/'; function TranslaTen () { this.handle; this.running = false; } function inTheSite () (~buffer.URL.indexOf(URL)) TranslaTen.prototype = { get clipboard () util.readFromClipboard(), open: function () { if (inTheSite()) return; if (buffer.URL == 'about:blank') return liberator.open(URL, liberator.CURRENT_TAB); for (let [number, browser] in Iterator(tabs.browsers)) { if (~browser.contentDocument.location.href.indexOf(URL)) return liberator.modules.tabs.select(number, false); } liberator.open(URL, liberator.NEW_TAB); }, stop: function () { if (this.handle) { clearInterval(this.handle); this.handle = null; } this.running = false; }, run: function () { let self = this; if (this.running) return; this.running = true; this.prev = this.clipboard; this.open(); this.handle = setInterval( function () { let now = self.clipboard; if (now == self.prev) return; self.prev = now; self.open(); let f = function () { self.elements.textarea.value = now; self.elements.submit.click(); }; if (inTheSite()) { f(); } else { let handle = setInterval( function () { if (inTheSite() && buffer.loaded) { clearInterval(handle); f(); } }, 200 ); } }, 100 ); }, elements: { get submit () content.document.getElementsByTagName('INPUT')[0], get textarea () content.document.getElementsByTagName('TEXTAREA')[0] } }; let translaten = new TranslaTen(); options.add( ['translaten'], 'Automatically translate by clipboard changes', 'boolean', false, { setter: function (value) { if (value) translaten.run(); else translaten.stop(); } } ); })(); // vim:sw=2 ts=2 et si fdm=marker: >64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204