Skip to content

Commit

Permalink
Initial project setup
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyrne01 committed Oct 26, 2014
1 parent 1bcdc36 commit 88b9b7e
Show file tree
Hide file tree
Showing 14 changed files with 865 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>tab-data-firefox</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions data/html/view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<label>Global count: </label><input type="text" id="globalCount" disabled="true" size="5"></input><br/>
<label>Session count: </label><input type="text" id="sessionCount" disabled="true" size="5"></input><br/>
<label>Current count: </label><input type="text" id="currentCount" disabled="true" size="5"></input>
</body>
</html>
Binary file added data/images/tabs-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/tabs-64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions data/js/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
self.port.on("stats", function (stats) {
var parsedStats = JSON.parse(stats);

document.getElementById("globalCount").value = parsedStats.globalCount;
document.getElementById("sessionCount").value = parsedStats.sessionCount;
document.getElementById("currentCount").value = parsedStats.currentCount;
});
6 changes: 6 additions & 0 deletions lib/Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var data = require("sdk/self").data;

exports.get = function(content) {

return data.url(content);
}
33 changes: 33 additions & 0 deletions lib/Panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var Panel = require("sdk/panel"),
Tab = require("./Tab"),
Data = require("./Data"),
Button = require("./ToggleButton"),
panel;

exports.init = function() {

panel = Panel.Panel({
width: 225,
height: 100,
contentURL: Data.get("html/view.html"),
contentScriptFile: Data.get("js/controller.js"),
onShow: function() {

var stats = JSON.stringify({
globalCount: Tab.getGlobalCount(),
sessionCount: Tab.getSessionCount(),
currentCount: Tab.getCurrentCount()
});

panel.port.emit("stats", stats);
},
onHide: function() {
Button.get().state('window', {checked: false});
}
});
};

exports.get = function() {

return panel;
};
21 changes: 21 additions & 0 deletions lib/SimpleStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var ss = require("sdk/simple-storage");

exports.init = function(){
ss.storage.globalCount = [];
}

function getGlobalCount(){
return ss.storage.globalCount;
}

exports.getGlobalCount = function(){
return getGlobalCount();
}

function setGlobalCount(globalCount){
ss.storage.globalCount = globalCount;
}

exports.setGlobalCount = function(globalCount){
setGlobalCount(globalCount);
}
52 changes: 52 additions & 0 deletions lib/Tab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var tabs = require("sdk/tabs"),
ss = require("./SimpleStorage"),
sessionCount = 0,
currentCount = 0;

exports.init = function(){

if (typeof ss.getGlobalCount() === 'undefined'){
ss.setGlobalCount(0);
}

for each (var tab in tabs){

ss.setGlobalCount(ss.getGlobalCount() + 1, new Date().getTime());
sessionCount++;
currentCount++;
}


// Listen for tab openings.
tabs.on('open', function onOpen(tab) {

ss.setGlobalCount(ss.getGlobalCount() + 1, new Date().getTime());
sessionCount++;
currentCount++;
console.log('Global: ' + ss.getGlobalCount());
console.log('Session: ' + sessionCount);
console.log('Current: ' + currentCount);
});

//Listen for tab closes.
tabs.on('close', function onOpen(tab) {

currentCount--;
console.log('Global: ' + ss.getGlobalCount());
console.log('Session: ' + sessionCount);
console.log('Current: ' + currentCount);
});
}


exports.getGlobalCount = function(){
return ss.getGlobalCount();
}

exports.getSessionCount = function(){
return sessionCount;
}

exports.getCurrentCount = function(){
return currentCount;
}
26 changes: 26 additions & 0 deletions lib/ToggleButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var { ToggleButton } = require("sdk/ui/button/toggle"),
Data = require("./Data"),
Panel = require("./Panel"),
button;

exports.init = function() {

button = ToggleButton({
id: "tab-data-widget",
label: 'Tab Data',
icon: Data.get("images/tabs-64.png"),
onChange: handleChange
});
}

exports.get = function() {
return button;
}

function handleChange(state) {
if (state.checked) {
Panel.get().show({
position: button
});
}
}
3 changes: 3 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require("./Tab").init();
require("./ToggleButton").init();
require("./Panel").init();
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "tab-data-addon",
"title": "Tab Data",
"id": "jid1-4ogjq7MUzAiCOw",
"description": "Provides user with tab related stats/data",
"author": "Robert Byrne",
"license": "GNU GPL v3",
"version": "0.1",
"permissions": {"private-browsing": true}
}
12 changes: 12 additions & 0 deletions test/test-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var main = require("./main");

exports["test main"] = function(assert) {
assert.pass("Unit test running!");
};

exports["test main async"] = function(assert, done) {
assert.pass("async Unit test running!");
done();
};

require("sdk/test").run(exports);

0 comments on commit 88b9b7e

Please sign in to comment.