This repository has been archived by the owner on Sep 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
executable file
·67 lines (67 loc) · 1.69 KB
/
worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var lAddr = {
};
log = function (txt) {
// console.log(txt);
postMessage(txt);
}
onmessage = function (e) {
switch (e.data.cmd) {
case 'calculate':
calculateDuplicates(e.data.body);
break;
case 'stop':
log('Stopped from inside');
close();
break
}
}
calculateDuplicates = function (root)
{
lAddr = {
};
log('Started ...');
uniq = getDuplicateCount(root);
log('Done!');
result = '';
count = 0;
dup = 0;
result += '<table>';
for (var i in lAddr) {
result += '<tr><td>' + lAddr[i] + '</td><td class="addr"><a href="' + i + '" target="blank">' + i + '</a></td></tr>';
if (lAddr[i] > 1) {
dup += lAddr[i];
}
count++;
}
result += '</table>'
result += 'Total: ' + count + ' unique bookmarks and ' + dup + ' duplicates<br>';
postMessage({
'result': result,
'file': JSON.stringify(uniq)
});
}
getDuplicateCount = function (node)
{
var copy = JSON.parse(JSON.stringify(node));
if (node != null) {
if (typeof node.children !== 'undefined') {
copy.children = [
];
node.children.forEach(function (item, i) {
result = getDuplicateCount(item);
if (result !== false) {
copy.children[i] = result;
}
})
}
if (typeof node.uri !== 'undefined')
{
if (typeof lAddr[node.uri] == 'undefined') {
lAddr[node.uri] = 0;
}
lAddr[node.uri]++;
return (lAddr[node.uri] > 1) ? false : node;
}
}
return copy;
}