From ae25ad78906179e1448ff7d97957810e2be40206 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 7 Apr 2022 12:17:38 +1000 Subject: nop whitespace formatting change. - ran eglot-format using typescript-language-server on all js files in the repo except those under /hash_script/ - verify only whitespace changed: git diff --word-diff-regex=. 62d6a71 62d6a71~1 --- bg/ExternalLicenses.js | 18 ++++++++--------- bg/ListManager.js | 52 ++++++++++++++++++++++++------------------------- bg/ResponseMetaData.js | 6 +++--- bg/ResponseProcessor.js | 32 +++++++++++++++--------------- 4 files changed, 54 insertions(+), 54 deletions(-) (limited to 'bg') diff --git a/bg/ExternalLicenses.js b/bg/ExternalLicenses.js index 758b92d..0e09b6d 100644 --- a/bg/ExternalLicenses.js +++ b/bg/ExternalLicenses.js @@ -28,10 +28,10 @@ let licensesByLabel = new Map(); let licensesByUrl = new Map(); { - let {licenses} = require("../license_definitions"); + let { licenses } = require("../license_definitions"); let mapByLabel = (label, license) => licensesByLabel.set(label.toUpperCase(), license); for (let [id, l] of Object.entries(licenses)) { - let {identifier, canonicalUrl, licenseName} = l; + let { identifier, canonicalUrl, licenseName } = l; if (identifier) { mapByLabel(identifier, l); } else { @@ -59,7 +59,7 @@ var ExternalLicenses = { }, async check(script) { - let {url, tabId, frameId, documentUrl} = script; + let { url, tabId, frameId, documentUrl } = script; let tabCache = cachedHrefs.get(tabId); let frameCache = tabCache && tabCache.get(frameId); let cache = frameCache && frameCache.get(documentUrl); @@ -67,7 +67,7 @@ var ExternalLicenses = { action: "checkLicensedScript", url, cache, - }, {frameId}); + }, { frameId }); if (!(scriptInfo && scriptInfo.licenseLinks.length)) { return null; @@ -76,8 +76,8 @@ var ExternalLicenses = { scriptInfo.toString = function() { let licenseIds = [...this.licenses].map(l => l.identifier).sort().join(", "); return licenseIds - ? `Free license${this.licenses.size > 1 ? "s" : ""} (${licenseIds})` - : "Unknown license(s)"; + ? `Free license${this.licenses.size > 1 ? "s" : ""} (${licenseIds})` + : "Unknown license(s)"; } let match = (map, key) => { if (map.has(key)) { @@ -87,7 +87,7 @@ var ExternalLicenses = { return false; }; - for (let {label, url} of scriptInfo.licenseLinks) { + for (let { label, url } of scriptInfo.licenseLinks) { match(licensesByLabel, label = label.trim().toUpperCase()) || match(licensesByUrl, url) || match(licensesByLabel, label.replace(/^GNU-|-(?:OR-LATER|ONLY)$/, '')); @@ -105,7 +105,7 @@ var ExternalLicenses = { */ optimizeDocument(doc, cachePointer) { let cache = {}; - let {tabId, frameId, documentUrl} = cachePointer; + let { tabId, frameId, documentUrl } = cachePointer; let frameCache = cachedHrefs.get(tabId); if (!frameCache) { cachedHrefs.set(tabId, frameCache = new Map()); @@ -115,7 +115,7 @@ var ExternalLicenses = { let link = doc.querySelector(`link[rel="jslicense"], link[data-jslicense="1"], a[rel="jslicense"], a[data-jslicense="1"]`); if (link) { let href = link.getAttribute("href"); - cache.webLabels = {href}; + cache.webLabels = { href }; let move = () => !!doc.head.insertBefore(link, doc.head.firstChild); if (link.parentNode === doc.head) { for (let node = link; node = node.previousElementSibling;) { diff --git a/bg/ListManager.js b/bg/ListManager.js index 745e599..f712356 100644 --- a/bg/ListManager.js +++ b/bg/ListManager.js @@ -23,11 +23,11 @@ A class to manage whitelist/blacklist operations */ -let {ListStore} = require("../common/Storage"); +let { ListStore } = require("../common/Storage"); class ListManager { constructor(whitelist, blacklist, builtInHashes) { - this.lists = {whitelist, blacklist}; + this.lists = { whitelist, blacklist }; this.builtInHashes = new Set(builtInHashes); } @@ -49,13 +49,13 @@ class ListManager { Returns "blacklisted", "whitelisted" or defValue */ getStatus(key, defValue = "unknown") { - let {blacklist, whitelist} = this.lists; + let { blacklist, whitelist } = this.lists; let inline = ListStore.inlineItem(key); if (inline) { return blacklist.contains(inline) ? "blacklisted" : whitelist.contains(inline) ? "whitelisted" - : defValue; + : defValue; } let match = key.match(/\(([^)]+)\)(?=[^()]*$)/); @@ -65,38 +65,38 @@ class ListManager { return (blacklist.contains(url) || ListManager.siteMatch(site, blacklist) ? "blacklisted" : whitelist.contains(url) || ListManager.siteMatch(site, whitelist) - ? "whitelisted" : defValue + ? "whitelisted" : defValue ); } - let [hashItem, srcHash] = match; // (hash), hash - return blacklist.contains(hashItem) ? "blacklisted" - : this.builtInHashes.has(srcHash) || whitelist.contains(hashItem) + let [hashItem, srcHash] = match; // (hash), hash + return blacklist.contains(hashItem) ? "blacklisted" + : this.builtInHashes.has(srcHash) || whitelist.contains(hashItem) ? "whitelisted" - : defValue; - } + : defValue; + } - /* - Matches by whole site ("http://some.domain.com/*") supporting also - wildcarded subdomains ("https://*.domain.com/*"). - */ - static siteMatch(url, list) { - let site = ListStore.siteItem(url); + /* + Matches by whole site ("http://some.domain.com/*") supporting also + wildcarded subdomains ("https://*.domain.com/*"). + */ + static siteMatch(url, list) { + let site = ListStore.siteItem(url); + if (list.contains(site)) { + return site; + } + site = site.replace(/^([\w-]+:\/\/)?(\w)/, "$1*.$2"); + for (; ;) { if (list.contains(site)) { return site; } - site = site.replace(/^([\w-]+:\/\/)?(\w)/, "$1*.$2"); - for (;;) { - if (list.contains(site)) { - return site; - } - let oldKey = site; - site = site.replace(/(?:\*\.)*\w+(?=\.)/, "*"); - if (site === oldKey) { - return null; - } + let oldKey = site; + site = site.replace(/(?:\*\.)*\w+(?=\.)/, "*"); + if (site === oldKey) { + return null; } } + } } module.exports = { ListManager }; diff --git a/bg/ResponseMetaData.js b/bg/ResponseMetaData.js index 0f768fe..4570120 100644 --- a/bg/ResponseMetaData.js +++ b/bg/ResponseMetaData.js @@ -26,15 +26,15 @@ */ const BOM = [0xEF, 0xBB, 0xBF]; -const DECODER_PARAMS = {stream: true}; +const DECODER_PARAMS = { stream: true }; class ResponseMetaData { constructor(request) { - let {responseHeaders} = request; + let { responseHeaders } = request; this.headers = {}; for (let h of responseHeaders) { if (/^\s*Content-(Type|Disposition)\s*$/i.test(h.name)) { - let propertyName = h.name.split("-")[1].trim(); + let propertyName = h.name.split("-")[1].trim(); propertyName = `content${propertyName.charAt(0).toUpperCase()}${propertyName.substring(1).toLowerCase()}`; this[propertyName] = h.value; this.headers[propertyName] = h; diff --git a/bg/ResponseProcessor.js b/bg/ResponseProcessor.js index 2c613c9..078f38a 100644 --- a/bg/ResponseProcessor.js +++ b/bg/ResponseProcessor.js @@ -24,7 +24,7 @@ only the "interesting" HTML and script requests and leaving the other alone */ -let {ResponseMetaData} = require("./ResponseMetaData"); +let { ResponseMetaData } = require("./ResponseMetaData"); let listeners = new WeakMap(); let webRequestEvent = browser.webRequest.onHeadersReceived; @@ -34,13 +34,13 @@ class ResponseProcessor { static install(handler, types = ["main_frame", "sub_frame", "script"]) { if (listeners.has(handler)) return false; let listener = - async request => await new ResponseTextFilter(request).process(handler); + async request => await new ResponseTextFilter(request).process(handler); listeners.set(handler, listener); webRequestEvent.addListener( - listener, - {urls: [""], types}, - ["blocking", "responseHeaders"] - ); + listener, + { urls: [""], types }, + ["blocking", "responseHeaders"] + ); return true; } @@ -54,15 +54,15 @@ class ResponseProcessor { Object.assign(ResponseProcessor, { // control flow values to be returned by handler.pre() callbacks - ACCEPT: {}, - REJECT: {cancel: true}, - CONTINUE: null + ACCEPT: {}, + REJECT: { cancel: true }, + CONTINUE: null }); class ResponseTextFilter { constructor(request) { this.request = request; - let {type, statusCode} = request; + let { type, statusCode } = request; let md = this.metaData = new ResponseMetaData(request); this.canProcess = // we want to process html documents and scripts only (statusCode < 300 || statusCode >= 400) && // skip redirections @@ -72,8 +72,8 @@ class ResponseTextFilter { async process(handler) { if (!this.canProcess) return ResponseProcessor.ACCEPT; - let {metaData, request} = this; - let response = {request, metaData}; // we keep it around allowing callbacks to store state + let { metaData, request } = this; + let response = { request, metaData }; // we keep it around allowing callbacks to store state if (typeof handler.pre === "function") { let res = await handler.pre(response); if (res) return res; @@ -81,7 +81,7 @@ class ResponseTextFilter { if (typeof handler !== "function") return ResponseProcessor.ACCEPT; } - let {requestId, responseHeaders} = request; + let { requestId, responseHeaders } = request; let filter = browser.webRequest.filterResponseData(requestId); let buffer = []; @@ -103,10 +103,10 @@ class ResponseTextFilter { console.debug("Warning: zeroes in bytestream, probable cached encoding mismatch.", request); if (request.type === "script") { console.debug("It's a script, trying to refetch it."); - response.text = await (await fetch(request.url, {cache: "reload", credentials: "include"})).text(); + response.text = await (await fetch(request.url, { cache: "reload", credentials: "include" })).text(); } else { console.debug("It's a %s, trying to decode it as UTF-16.", request.type); - response.text = new TextDecoder("utf-16be").decode(allBytes, {stream: true}); + response.text = new TextDecoder("utf-16be").decode(allBytes, { stream: true }); } } else { response.text = metaData.decode(allBytes); @@ -114,7 +114,7 @@ class ResponseTextFilter { let editedText = null; try { editedText = await handler(response); - } catch(e) { + } catch (e) { console.error(e); } if (editedText !== null) { -- cgit v1.2.3