forked from mdn/webextensions-examples
/
common-log-helpers.js
44 lines (34 loc) · 1.01 KB
/
common-log-helpers.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
// Log text and images utilities.
const dbLogsEl = document.querySelector("#indexed-logs");
document.querySelector("#clear-logs").onclick = () => {
while (dbLogsEl.firstChild) {
dbLogsEl.removeChild(dbLogsEl.firstChild);
}
};
function dbLogHTMLElement(el) {
dbLogsEl.appendChild(el);
// Scroll to the bottom automatically.
dbLogsEl.scrollTop = dbLogsEl.scrollHeight;
}
function dbLog(...args) {
dbLogHTMLElement(document.createTextNode('\n' + args.join(" ")));
}
function logIDBFileLink({prefixText, fileIDBKey, suffixText, onClickHandler }) {
if (prefixText) {
dbLogHTMLElement(document.createTextNode(prefixText));
}
const linkEl = document.createElement("a");
linkEl.setAttribute("href", "#");
linkEl.textContent = fileIDBKey;
if (typeof onClickHandler == "function") {
linkEl.onclick = () => {
onClickHandler(fileIDBKey);
};
}
dbLogHTMLElement(linkEl);
if (suffixText) {
dbLogHTMLElement(document.createTextNode(suffixText));
}
}
function logImage(imageUrl) {
}