Skip to content

Commit bc588d9

Browse files
committed
Added a caching & sorting for "By category" table
1 parent 46c7710 commit bc588d9

File tree

4 files changed

+47
-24
lines changed

4 files changed

+47
-24
lines changed

background.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,43 @@ function cacheHistory() {
175175

176176
setTimeout(function() {
177177
cache(start, end);
178-
}, 200);
178+
}, 100);
179179
} else {
180180
for (var key in WEBSITES) {
181181
var item = WEBSITES[key];
182182

183+
for (var category in CATEGORIES) {
184+
for (var website in CATEGORIES[category]) {
185+
if (key.indexOf(website) !== -1) {
186+
CATEGORIES[category][website] += item.d;
187+
}
188+
}
189+
}
190+
183191
ALL.BY_DOMAIN.push([key, item.d]);
184192
}
185193

194+
for (var category in CATEGORIES) {
195+
var array = [0, category, []];
196+
197+
for (var website in CATEGORIES[category]) {
198+
array[0] += CATEGORIES[category][website];
199+
200+
array[2].push([CATEGORIES[category][website], website]);
201+
}
202+
203+
array[2] = sort(array[2], 0);
204+
205+
ALL.BY_CATEGORY.push(array);
206+
}
207+
186208
for (var key in ALL.BY_PARAM_PRE) {
187209
var item = ALL.BY_PARAM_PRE[key];
188210

189211
ALL.BY_PARAM.push([item, key]);
190212
}
191213

214+
ALL.BY_CATEGORY = sort(ALL.BY_CATEGORY, 0);
192215
TOP.BY_DOMAIN = sort(ALL.BY_DOMAIN, 1).slice(0, 100);
193216
TOP.BY_PAGE = sort(ALL.BY_PAGE, 0).slice(0, 100);
194217
TOP.BY_PARAM = sort(ALL.BY_PARAM, 0).slice(0, 100);
@@ -214,6 +237,7 @@ function cacheHistory() {
214237
l1: TOP.l1,
215238
l2: TOP.l2
216239
},
240+
by_category: ALL.BY_CATEGORY,
217241
for_search: SEARCH,
218242
cached: true
219243
}, function() {

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@
155155
<main>
156156
<div class="table" data-table-index="4">
157157
<div class="table__head">
158-
<div>Visits</div>
158+
<div data-column-index="0" data-order-by="desc">Visits</div>
159159
<div></div>
160-
<div>Name</div>
160+
<div data-column-index="1">Name</div>
161161
</div>
162162
<div class="table__body"></div>
163163
<div class="table__footer"></div>

manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
"background": {
1010
"scripts": [
11+
"data/categories.js",
1112
"data/search-params.js",
1213
"background.js"
1314
]

script.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ function renderTable(index, array) {
500500
});
501501
});
502502

503-
a.href = 'https://' + array[i][2];
503+
a.href = array[i][2];
504504
a.innerText = array[i][2];
505505

506506
td3.appendChild(a);
@@ -673,14 +673,10 @@ function renderTable(index, array) {
673673
visits = 0;
674674

675675
button.innerText = '+';
676-
button.data = CATEGORIES[array[i][1]];
676+
button.data = array[i][2];
677677

678-
for (var key in button.data) {
679-
visits += button.data[key];
680-
}
681-
682-
td1.title = visits;
683-
td1.innerText = visits;
678+
td1.title = array[i][0];
679+
td1.innerText = array[i][0];
684680

685681
button.addEventListener('click', function() {
686682
var parent = this.parentNode.parentNode.parentNode,
@@ -692,19 +688,19 @@ function renderTable(index, array) {
692688

693689
table.className = 'table--inner';
694690

695-
for (var key in this.data) {
691+
for (var i = 0, l = this.data.length; i < l; i++) {
696692
var tr = document.createElement('div'),
697693
td1 = document.createElement('div'),
698694
td3 = document.createElement('div'),
699695
a = document.createElement('a');
700696

701-
td1.title = this.data[key];
702-
td1.innerText = this.data[key];
697+
td1.title = this.data[i][0];
698+
td1.innerText = this.data[i][0];
703699

704-
a.href = 'https://' + key;
705-
a.innerText = key;
700+
a.href = this.data[i][1];
701+
a.innerText = this.data[i][1];
706702

707-
td3.style.backgroundImage = 'url(https://' + key + '/favicon.ico)';
703+
td3.style.backgroundImage = 'url(chrome://favicon/' + this.data[i][1] + ')';
708704

709705
td3.appendChild(a);
710706

@@ -722,7 +718,7 @@ function renderTable(index, array) {
722718
var table = document.createElement('div');
723719

724720
table.className = 'table--inner';
725-
table.link = 'https://' + item.children[2].children[0].innerText;
721+
table.link = item.children[2].children[0].innerText;
726722

727723
renderFirstTableItem(item.tree, table);
728724

@@ -1049,7 +1045,7 @@ window.addEventListener('load', function() {
10491045
TOP_SITES_length = Object.keys(TOP_SITES).length;
10501046

10511047
parseBookmarks(function() {
1052-
chrome.storage.local.get(['top', 'tags', 'for_search'], function(items) {
1048+
chrome.storage.local.get(['top', 'tags', 'for_search', 'by_category'], function(items) {
10531049
TAGS = items.tags || {};
10541050
SEARCH = items.for_search || [];
10551051

@@ -1059,8 +1055,9 @@ window.addEventListener('load', function() {
10591055
TABLE[1].data.length = items.top.l1;
10601056
TABLE[2].data.table = items.top[2];
10611057
TABLE[2].data.length = items.top.l2;
1058+
TABLE[4].data.table = items.by_category;
10621059

1063-
for (var key in CATEGORIES) {
1060+
/*for (var key in CATEGORIES) {
10641061
for (var link in CATEGORIES[key]) {
10651062
for (var i = 0, l = TABLE[0].data.table.length; i < l; i++) {
10661063
if (TABLE[0].data.table[i][0].indexOf(link) !== -1) {
@@ -1072,7 +1069,7 @@ window.addEventListener('load', function() {
10721069
10731070
for (var key in CATEGORIES) {
10741071
TABLE[4].data.table.push([0, key]);
1075-
}
1072+
}*/
10761073

10771074
for (var i = 0, l = TABLE[1].data.table.length; i < l; i++) {
10781075
if (BOOKMARKS['https://' + TABLE[1].data.table[i][2]]) {
@@ -1126,7 +1123,7 @@ window.addEventListener('load', function() {
11261123
}
11271124

11281125
parseBookmarks(function() {
1129-
chrome.storage.local.get(['top', 'tags', 'for_search'], function(items) {
1126+
chrome.storage.local.get(['top', 'tags', 'for_search', 'by_category'], function(items) {
11301127
TAGS = items.tags || {};
11311128
SEARCH = items.for_search || [];
11321129

@@ -1136,8 +1133,9 @@ window.addEventListener('load', function() {
11361133
TABLE[1].data.length = items.top.l1;
11371134
TABLE[2].data.table = items.top[2];
11381135
TABLE[2].data.length = items.top.l2;
1136+
TABLE[4].data.table = items.by_category;
11391137

1140-
for (var key in CATEGORIES) {
1138+
/*for (var key in CATEGORIES) {
11411139
for (var link in CATEGORIES[key]) {
11421140
for (var i = 0, l = TABLE[0].data.table.length; i < l; i++) {
11431141
if (TABLE[0].data.table[i][0].indexOf(link) !== -1) {
@@ -1149,7 +1147,7 @@ window.addEventListener('load', function() {
11491147
11501148
for (var key in CATEGORIES) {
11511149
TABLE[4].data.table.push([0, key]);
1152-
}
1150+
}*/
11531151

11541152
for (var i = 0, l = TABLE[1].data.table.length; i < l; i++) {
11551153
if (BOOKMARKS['https://' + TABLE[1].data.table[i][2]]) {

0 commit comments

Comments
 (0)