From 8429f2c113911d084749f7432dea0e7cbcf5ab80 Mon Sep 17 00:00:00 2001 From: Yoitsumi Date: Wed, 30 Mar 2016 20:06:06 +0200 Subject: [PATCH] Basic functionality --- data/icon16.png | Bin 0 -> 309 bytes data/icon32.png | Bin 0 -> 423 bytes data/icon64.png | Bin 0 -> 610 bytes data/inserter.js | 5 ++++ index.js | 65 ++++++++++++++++++++++++++++++++++++++++----- test/test-index.js | 18 ------------- 6 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 data/icon16.png create mode 100644 data/icon32.png create mode 100644 data/icon64.png create mode 100644 data/inserter.js diff --git a/data/icon16.png b/data/icon16.png new file mode 100644 index 0000000000000000000000000000000000000000..06ff843c23fb830692e24301d936f6413781a0b0 GIT binary patch literal 309 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf2?- zR1judbxnLdkRe&(8c`CQpH@mmtT}V`<;yxP|+q&7sn8b z-nW+xyOh?;F-N-W{yc`GIz(KR@}&q)5#R247HWStN1^z8~({1k}~Pp{6I{HJ8QZlPPV*vgvl zU8T{c={l2N@LbEt+P72d#pac>*j}r+$@OfPuAU#k`{MR)HqSnbf8Sa8>mR0m;9-lE xpJSl8l*cr{UTy2MaSaG(GH literal 0 HcmV?d00001 diff --git a/data/icon32.png b/data/icon32.png new file mode 100644 index 0000000000000000000000000000000000000000..80285d7e48b765a79bc745c460bbc6283b0011e2 GIT binary patch literal 423 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dy%*9TgAsieWw;%dH0CG7CJR*yM z^eGT#%w`tZ1Y}5-xJHx&=ckpFCl;kLl$V$5W#(lUCnpx9>g5-u&wghk1yqy};1lBd z|Nnm=lXjqiBlQT-bor7XzhDLyR(4)KF$rl61CNBVmcB&?&R@88_xX!A?>>C{{`;?m zPVhUR(mqcY#}Etuw`b3aH7N+RJ=Cl}5E39L?7jc@es5deNV$^Bi>99EI=6?%<-XC? zZCZ<+HyvLz{h^AGzNvw)!`bZ_vdeEB+#Gc4`^}eE*rir?t@w3k%l-EsOxoo6Tn#_0 zT2^`Bqdt>?i=|nS5_89YwvV~Wd`%Z5=N!yGxb<+weZxh&3sx04{EYR?+<17}NuxQ8 Xq5Cw?XSOF;f`Z7?)z4*}Q$iB}w@HCm literal 0 HcmV?d00001 diff --git a/data/icon64.png b/data/icon64.png new file mode 100644 index 0000000000000000000000000000000000000000..5caee9f298953a1cbca0347182b54cafa4793833 GIT binary patch literal 610 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!n2Vh}LpV4%Za?&Y0OWEOctjR6 zFfdL5Va9u0IXOT<$r9IylHmNblJdl&REF~Ma=pyF?Be9af>gcyqV(DCY@~pSCI|S0 zxc>kDAIKb3KwDJz4$wgcB|(0{3{0$?ynLe4GIFXK2F9k=aS17@A4`V6(?8h0&G*=>XdCY*v$q_*rm1z~bnwR-xzq2f4U2@b zqlI=PsSCZ9yka1%JTYRo%8&F$^Hm2g3uHJj2~B8VQBh#z^l)I3Z4CVv@zzAM{)EoW zO2%ZpQwyg(Yg(%G;@GmkJ67L2{UGO>J^w26+cVc0-!0oVuPkmad%F(%q@_DwM1o@1 M)78&qol`;+0IKM~#sB~S literal 0 HcmV?d00001 diff --git a/data/inserter.js b/data/inserter.js new file mode 100644 index 0000000..3bded2a --- /dev/null +++ b/data/inserter.js @@ -0,0 +1,5 @@ +self.port.on('insert', data => { + var elem = document.createElement('div') + elem.textContent = data + document.body.appendChild(elem) +}) diff --git a/index.js b/index.js index 6995d96..9c9c94d 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,62 @@ -var self = require("sdk/self"); +var self = require('sdk/self'); +var clipboard = require('sdk/clipboard') +var buttons = require('sdk/ui/button/action'); +var tabs = require('sdk/tabs'); +var { ToggleButton } = require('sdk/ui/button/toggle') +var timers = require('sdk/timers') -// a dummy function, to show how tests work. -// to see how to test this function, look at test/test-index.js -function dummy(text, callback) { - callback(text); +var button = ToggleButton({ + id: "clipboard-inserter-btn", + label: "Toggle Clipboard Cnserter", + icon: { + 16: "./icon16.png", + 32: "./icon32.png", + 64: "./icon64.png" + }, + onChange: function(state) { + this.state('window', null) + let { checked } = this.state('tab') + checked = !checked + this.state('tab', { checked }) + if(checked) { + enableMonitor() + } else { + disableMonitor() + } + } +}) +//
Icons made by Google from www.flaticon.com is licensed by CC 3.0 BY
+ +function enableMonitor() { + console.log("Enabling clipboard monitor") + tabs.activeTab.clinClipboardMonitor = new ClipboardMonitor() } -exports.dummy = dummy; +function disableMonitor() { + console.log("Disabling clipboard monitor") + var monitor = tabs.activeTab.clinClipboardMonitor + if(monitor) { + timers.clearInterval(monitor.intervalID) + delete tabs.activeTab.clinClipboardMonitor + } else { + console.error("Trying to disable clipboard monitor on tab without active ClipboardMonitor!") + } +} + +function ClipboardMonitor() { + + var lastContent = '' + + this.worker = tabs.activeTab.attach({ contentScriptFile: self.data.url('inserter.js') }) + + this.intervalID = timers.setInterval(() => { + if(clipboard.currentFlavors.indexOf('text') != -1) { + var currentContent = clipboard.get('text/unicode') + if(lastContent !== currentContent) { + this.worker.port.emit('insert', currentContent) + lastContent = currentContent + } + } + }, 100) + +} diff --git a/test/test-index.js b/test/test-index.js index b3ad6e8..34c319b 100644 --- a/test/test-index.js +++ b/test/test-index.js @@ -1,19 +1 @@ var main = require("../"); - -exports["test main"] = function(assert) { - assert.pass("Unit test running!"); -}; - -exports["test main async"] = function(assert, done) { - assert.pass("async Unit test running!"); - done(); -}; - -exports["test dummy"] = function(assert, done) { - main.dummy("foo", function(text) { - assert.ok((text === "foo"), "Is the text actually 'foo'"); - done(); - }); -}; - -require("sdk/test").run(exports);