Skip to content

Commit 381fd6b

Browse files
committed
add list of site to popup
1 parent 91ba0cc commit 381fd6b

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
<meta charset="utf-8">
55
<title>WebActivity Time Tracker</title>
66
<link href="style/webact.css" rel="stylesheet"/>
7+
<script src="scripts/webact.js"></script>
78
</head>
89
<body>
9-
<p>test</p>
10+
<div id="resultTable">
11+
</div>
1012
</body>
1113
</html>

manifest.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"scripts": ["scripts/background.js"],
2424
"persistent": false
2525
},
26-
2726
"browser_action": {
2827
"default_popup": "index.html",
2928
"default_title": "WebActivity Time Tracker",

scripts/background.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,33 @@
1-
chrome.browserAction.onClicked.addListener(function () {
2-
});
1+
window.onload = function () {
2+
window.timer = new WebTimer();
3+
chrome.tabs.onActivated.addListener(function (info) {
4+
chrome.tabs.get(info.tabId, function (tab) {
5+
window.timer.addTab(tab);
6+
});
7+
});
8+
};
9+
10+
var WebTimer = function () { };
11+
12+
WebTimer.prototype = {
13+
tabs: [],
14+
activeTab: {},
15+
16+
addTab: function (tab) {
17+
if (this.isValidPage(tab) === true) {
18+
if (tab.id && (tab.id != 0)) {
19+
this.tabs = this.tabs || [];
20+
this.tabs.push(tab.url);
21+
this.activeTab = tab.url;
22+
}
23+
}
24+
},
25+
26+
isValidPage: function (tab) {
27+
if (!tab || !tab.url || (tab.url.indexOf('http:') == -1 && tab.url.indexOf('https:') == -1)
28+
|| tab.url.indexOf('chrome://') !== -1
29+
|| tab.url.indexOf('chrome-extension://') !== -1)
30+
return false;
31+
return true;
32+
}
33+
};

scripts/webact.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
window.onload = function () {
2+
var table = document.getElementById('resultTable');
3+
var tabs = chrome.extension.getBackgroundPage().timer.tabs;
4+
for (var i = 0; i < tabs.length; i++) {
5+
var p = document.createElement('p');
6+
p.innerText = tabs[i];
7+
table.appendChild(p);
8+
}
9+
};

0 commit comments

Comments
 (0)