Basic functionality

This commit is contained in:
Yoitsumi 2016-03-30 20:06:06 +02:00
parent 209bfeb500
commit 8429f2c113
6 changed files with 64 additions and 24 deletions

BIN
data/icon16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 B

BIN
data/icon32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 B

BIN
data/icon64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

5
data/inserter.js Normal file
View File

@ -0,0 +1,5 @@
self.port.on('insert', data => {
var elem = document.createElement('div')
elem.textContent = data
document.body.appendChild(elem)
})

View File

@ -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()
}
}
})
//<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)
}

View File

@ -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);