/
page.js
91 lines (73 loc) · 2.25 KB
/
page.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
(function(window, document) {
'use strict';
function htmlEscape(str) {
var map = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
return ('' + str).replace(/[&<>"']/g, function(match) {
return map[match];
});
}
function download(str, fileName) {
var file = new Blob([str]);
var a = document.createElement('a');
a.href = window.URL.createObjectURL(file);
a.download = fileName;
a.style.display = 'none';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
function loadTemplate(callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', chrome.runtime.getURL('template.html'), true);
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
callback(xhr.responseText);
}
};
xhr.send();
}
chrome.management.getAll(function(extensions) {
var enabled = '';
var disabled = '';
var commentEnabled = '';
var commentDisabled = '';
var baseUrl = 'https://chrome.google.com/webstore/detail/';
extensions.sort(function(a, b) {
return a.name.localeCompare(b.name);
});
extensions.forEach(function(extension) {
var html = '';
var comment = '';
var url = baseUrl + extension.id;
html += ' ';
html += '<li>';
html += '<a href="' + url + '" target="_blank" ';
html += 'title="' + htmlEscape(extension.description) + '">';
html += htmlEscape(extension.name) + '</a>';
html += '</li>\n';
comment += extension.name + '\n';
comment += url + '\n\n';
if (extension.enabled) {
enabled += html;
commentEnabled += comment;
}
else {
disabled += html;
commentDisabled += comment;
}
});
loadTemplate(function(template) {
template = template.replace('{ENABLED}', enabled.trim())
.replace('{DISABLED}', disabled.trim())
.replace('{COMMENT_ENABLED}', commentEnabled.trim())
.replace('{COMMENT_DISABLED}', commentDisabled.trim());
download(template, 'extensions.html');
});
});
})(window, document);