aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <hi@ypei.me>2022-07-29 12:07:23 +1000
committerYuchen Pei <hi@ypei.me>2022-07-29 12:07:23 +1000
commita6d433a604cecbfc75859855e375057f1de332c0 (patch)
tree8a2ea8b272c23889b95ee14b9f2724e65db1aa75
parent2401ca4d60e56b2160b1163c056b94a5642dd7b2 (diff)
cleainig externallicenses done
-rw-r--r--bg/ExternalLicenses.js25
1 files changed, 12 insertions, 13 deletions
diff --git a/bg/ExternalLicenses.js b/bg/ExternalLicenses.js
index 16ea52f..e37510a 100644
--- a/bg/ExternalLicenses.js
+++ b/bg/ExternalLicenses.js
@@ -86,34 +86,33 @@ const ExternalLicenses = {
* Returns true if the document has been actually modified, false otherwise.
*/
optimizeDocument(doc, cachePointer) {
- let cache = {};
- let { tabId, frameId, documentUrl } = cachePointer;
- let frameCache = cachedHrefs.get(tabId);
- if (!frameCache) {
- cachedHrefs.set(tabId, frameCache = new Map());
- }
+ const cache = {};
+ const { tabId, frameId, documentUrl } = cachePointer;
+ const frameCache = cachedHrefs.get(tabId) || new Map();
+ cachedHrefs.set(tabId, frameCache);
frameCache.set(frameId, new Map([[documentUrl, cache]]));
- let link = doc.querySelector('link[rel="jslicense"], link[data-jslicense="1"], a[rel="jslicense"], a[data-jslicense="1"]');
+ const link = doc.querySelector('link[rel="jslicense"], link[data-jslicense="1"], a[rel="jslicense"], a[data-jslicense="1"]');
if (link) {
- let href = link.getAttribute('href');
+ const href = link.getAttribute('href');
cache.webLabels = { href };
- let move = () => !!doc.head.insertBefore(link, doc.head.firstChild);
+ const move = (link) => !!doc.head.insertBefore(link, doc.head.firstChild);
if (link.parentNode === doc.head) {
+ // TODO: eliminate let
let node = link.previousElementSibling;
for (; node; node = node.previousElementSibling) {
if (node.tagName.toUpperCase() === 'SCRIPT') {
- return move();
+ return move(link);
}
}
} else { // the reference is only in the body
if (link.tagName.toUpperCase() === 'A') {
- let newLink = doc.createElement('link');
+ const newLink = doc.createElement('link');
newLink.rel = 'jslicense';
newLink.setAttribute('href', href);
- link = newLink;
+ return move(newLink);
}
- return move();
+ return move(link);
}
}