Basic functionality
This commit is contained in:
parent
209bfeb500
commit
8429f2c113
Binary file not shown.
|
After Width: | Height: | Size: 309 B |
Binary file not shown.
|
After Width: | Height: | Size: 423 B |
Binary file not shown.
|
After Width: | Height: | Size: 610 B |
|
|
@ -0,0 +1,5 @@
|
||||||
|
self.port.on('insert', data => {
|
||||||
|
var elem = document.createElement('div')
|
||||||
|
elem.textContent = data
|
||||||
|
document.body.appendChild(elem)
|
||||||
|
})
|
||||||
65
index.js
65
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.
|
var button = ToggleButton({
|
||||||
// to see how to test this function, look at test/test-index.js
|
id: "clipboard-inserter-btn",
|
||||||
function dummy(text, callback) {
|
label: "Toggle Clipboard Cnserter",
|
||||||
callback(text);
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
//<div>Icons made by <a href="http://www.flaticon.com/authors/google" title="Google">Google</a> from <a href="http://www.flaticon.com" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a></div>
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1 @@
|
||||||
var main = require("../");
|
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);
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue