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 --- content/contactFinder.js | 312 +++++++++++++++++++------------------- content/externalLicenseChecker.js | 24 +-- 2 files changed, 167 insertions(+), 169 deletions(-) (limited to 'content') diff --git a/content/contactFinder.js b/content/contactFinder.js index 22bf2fc..6b6cc44 100644 --- a/content/contactFinder.js +++ b/content/contactFinder.js @@ -25,7 +25,7 @@ // - add a comma after the closing bracket of the key "background" // - Copy and paste this after it: /* - "content_scripts": [{ + "content_scripts": [{ "matches": [""], "js": ["/content/contactFinder.js"], "css": ["/content/contactFinder.css"] @@ -64,64 +64,64 @@ var reIdentiCa = /identi\.ca\/(?!notice\/)[a-z0-9]*/i; * and by degree of certainty. */ var contactStr = { - 'da': { - 'certain': [ - '^[\\s]*Kontakt os[\\s]*$', - '^[\\s]*Email Os[\\s]*$', - '^[\\s]*Kontakt[\\s]*$' - ], - 'probable': ['^[\\s]Kontakt', '^[\\s]*Email'], - 'uncertain': [ - '^[\\s]*Om Us', - '^[\\s]*Om', - 'Hvem vi er' - ] - }, - 'en': { - 'certain': [ - '^[\\s]*Contact Us[\\s]*$', - '^[\\s]*Email Us[\\s]*$', - '^[\\s]*Contact[\\s]*$', - '^[\\s]*Feedback[\\s]*$', - '^[\\s]*Web.?site Feedback[\\s]*$' - ], - 'probable': ['^[\\s]Contact', '^[\\s]*Email'], - 'uncertain': [ - '^[\\s]*About Us', - '^[\\s]*About', - 'Who we are', - 'Who I am', - 'Company Info', - 'Customer Service' - ] - }, - 'es': { - 'certain': [ - '^[\\s]*contáctenos[\\s]*$', - '^[\\s]*Email[\\s]*$' - ], - 'probable': ['^[\\s]contáctenos', '^[\\s]*Email'], - 'uncertain': [ - 'Acerca de nosotros' - ] - }, - 'fr': { - 'certain': [ - '^[\\s]*Contactez nous[\\s]*$', - '^[\\s]*(Nous )?contacter[\\s]*$', - '^[\\s]*Email[\\s]*$', - '^[\\s]*Contact[\\s]*$', - '^[\\s]*Commentaires[\\s]*$' - ], - 'probable': ['^[\\s]Contact', '^[\\s]*Email'], - 'uncertain': [ - '^[\\s]*(A|À) propos', - 'Qui nous sommes', - 'Qui suis(-| )?je', - 'Info', - 'Service Client(e|è)le' - ] - } + 'da': { + 'certain': [ + '^[\\s]*Kontakt os[\\s]*$', + '^[\\s]*Email Os[\\s]*$', + '^[\\s]*Kontakt[\\s]*$' + ], + 'probable': ['^[\\s]Kontakt', '^[\\s]*Email'], + 'uncertain': [ + '^[\\s]*Om Us', + '^[\\s]*Om', + 'Hvem vi er' + ] + }, + 'en': { + 'certain': [ + '^[\\s]*Contact Us[\\s]*$', + '^[\\s]*Email Us[\\s]*$', + '^[\\s]*Contact[\\s]*$', + '^[\\s]*Feedback[\\s]*$', + '^[\\s]*Web.?site Feedback[\\s]*$' + ], + 'probable': ['^[\\s]Contact', '^[\\s]*Email'], + 'uncertain': [ + '^[\\s]*About Us', + '^[\\s]*About', + 'Who we are', + 'Who I am', + 'Company Info', + 'Customer Service' + ] + }, + 'es': { + 'certain': [ + '^[\\s]*contáctenos[\\s]*$', + '^[\\s]*Email[\\s]*$' + ], + 'probable': ['^[\\s]contáctenos', '^[\\s]*Email'], + 'uncertain': [ + 'Acerca de nosotros' + ] + }, + 'fr': { + 'certain': [ + '^[\\s]*Contactez nous[\\s]*$', + '^[\\s]*(Nous )?contacter[\\s]*$', + '^[\\s]*Email[\\s]*$', + '^[\\s]*Contact[\\s]*$', + '^[\\s]*Commentaires[\\s]*$' + ], + 'probable': ['^[\\s]Contact', '^[\\s]*Email'], + 'uncertain': [ + '^[\\s]*(A|À) propos', + 'Qui nous sommes', + 'Qui suis(-| )?je', + 'Info', + 'Service Client(e|è)le' + ] + } }; var usaPhoneNumber = new RegExp(/(?:\+ ?1 ?)?\(?[2-9]{1}[0-9]{2}\)?(?:\-|\.| )?[0-9]{3}(?:\-|\.| )[0-9]{4}(?:[^0-9])/mg); @@ -134,14 +134,14 @@ var prefs; /** * returns input with all elements not of type string removed */ -function remove_not_str(a){ - var new_a = []; - for(var i in a){ - if(typeof(a[i]) == "string"){ - new_a.push(a[i]) - } - } - return new_a; +function remove_not_str(a) { + var new_a = []; + for (var i in a) { + if (typeof (a[i]) == "string") { + new_a.push(a[i]) + } + } + return new_a; } /** * Tests all links on the page for regexes under a certain certainty level. @@ -151,87 +151,87 @@ function remove_not_str(a){ * * certainty_lvl can be "certain" > "probable" > "uncertain" */ -function attempt(certainty_lvl, first=true){ - // There needs to be some kind of max so that people can't troll by for example leaving a comment with a bunch of emails - // to cause LibreJS users to slow down. - var fail_flag = true; - var flag; - var matches = []; - var result = []; - var str_under_test = ""; - for(var i in document.links){ - if( typeof(document.links[i].innerText) != "string" || typeof(document.links[i].href) != "string"){ - continue; - } - str_under_test = document.links[i].innerText + " " + document.links[i].href; - flag = true; - for(var j in contactStr){ - for(var k in contactStr[j][certainty_lvl]){ - if(flag){ - result = []; - result = str_under_test.match(new RegExp(contactStr[j][certainty_lvl][k],"g")); - result = remove_not_str(result); - if(result !== undefined && typeof(result[0]) == "string" ){ - if(first){ - return {"fail":false,"result":document.links[i]}; - } else{ - //console.log(document.links[i].href + " matched " + contactStr[j][certainty_lvl][k]); - matches.push(document.links[i]); - fail_flag = false; - flag = false; - } - } - } - } - } - } - return {"fail":fail_flag,"result":matches}; +function attempt(certainty_lvl, first = true) { + // There needs to be some kind of max so that people can't troll by for example leaving a comment with a bunch of emails + // to cause LibreJS users to slow down. + var fail_flag = true; + var flag; + var matches = []; + var result = []; + var str_under_test = ""; + for (var i in document.links) { + if (typeof (document.links[i].innerText) != "string" || typeof (document.links[i].href) != "string") { + continue; + } + str_under_test = document.links[i].innerText + " " + document.links[i].href; + flag = true; + for (var j in contactStr) { + for (var k in contactStr[j][certainty_lvl]) { + if (flag) { + result = []; + result = str_under_test.match(new RegExp(contactStr[j][certainty_lvl][k], "g")); + result = remove_not_str(result); + if (result !== undefined && typeof (result[0]) == "string") { + if (first) { + return { "fail": false, "result": document.links[i] }; + } else { + //console.log(document.links[i].href + " matched " + contactStr[j][certainty_lvl][k]); + matches.push(document.links[i]); + fail_flag = false; + flag = false; + } + } + } + } + } + } + return { "fail": fail_flag, "result": matches }; } /** * "LibreJS detects contact pages, email addresses that are likely to be owned by the * maintainer of the site, Twitter and identi.ca links, and phone numbers." */ -function find_contacts(){ - var all = document.documentElement.innerText; - var phone_num = []; - var twitlinks = []; - var identi = []; - var contact_pages = []; - var res = attempt("certain"); - var flag = true; - var type = ""; - if(res["fail"] == false){ - type = "certain"; - res = res["result"]; - flag = false; - } - if(flag){ - res = attempt("probable"); - if(res["fail"] == false){ - type = "probable"; - res = res["result"]; - flag = false; - } - } - if(flag){ - res = attempt("uncertain"); - if(res["fail"] == false){ - type = "uncertain"; - res = res["result"]; - flag = false; - } - } - if(flag){ - return res; - } - return [type,res]; +function find_contacts() { + var all = document.documentElement.innerText; + var phone_num = []; + var twitlinks = []; + var identi = []; + var contact_pages = []; + var res = attempt("certain"); + var flag = true; + var type = ""; + if (res["fail"] == false) { + type = "certain"; + res = res["result"]; + flag = false; + } + if (flag) { + res = attempt("probable"); + if (res["fail"] == false) { + type = "probable"; + res = res["result"]; + flag = false; + } + } + if (flag) { + res = attempt("uncertain"); + if (res["fail"] == false) { + type = "uncertain"; + res = res["result"]; + flag = false; + } + } + if (flag) { + return res; + } + return [type, res]; } function createWidget(id, tag, parent = document.body) { let widget = document.getElementById(id); - if (widget) widget.remove(); + if (widget) widget.remove(); widget = parent.appendChild(document.createElement(tag)); widget.id = id; return widget; @@ -272,7 +272,7 @@ function main() { debug("initFrame"); let res = find_contacts(); let contentDoc = frame.contentWindow.document; - let {body} = contentDoc; + let { body } = contentDoc; body.id = "_LibreJS_dialog"; body.innerHTML = `

LibreJS Complaint

`; contentDoc.documentElement.appendChild(contentDoc.createElement("base")).target = "_top"; @@ -281,35 +281,33 @@ function main() { let addHTML = s => content.insertAdjacentHTML("beforeend", s); if ("fail" in res) { content.classList.toggle("_LibreJS_fail", true) - addHTML("
Could not guess any contact page for this site.
"); - } else { + addHTML("
Could not guess any contact page for this site.
"); + } else { addHTML("

Contact info guessed for this site

"); - if(typeof(res[1]) === "string") { + if (typeof (res[1]) === "string") { let a = contentDoc.createElement("a"); a.href = a.textContent = res[1]; content.appendChild(a); - } else if (typeof(res[1]) === "object"){ - addHTML(`${res[0]}: ${res[1].outerHTML}`); - } - } + } else if (typeof (res[1]) === "object") { + addHTML(`${res[0]}: ${res[1].outerHTML}`); + } + } - let emails = document.documentElement.textContent.match(email_regex); - if (emails && (emails = Array.filter(emails, e => !!e)).length) { + let emails = document.documentElement.textContent.match(email_regex); + if (emails && (emails = Array.filter(emails, e => !!e)).length) { addHTML("
Possible email addresses:
"); let list = contentDoc.createElement("ul"); - for (let i = 0, max = Math.min(emails.length, 10); i < max; i++) { + for (let i = 0, max = Math.min(emails.length, 10); i < max; i++) { let recipient = emails[i]; let a = contentDoc.createElement("a"); - a.href = `mailto:${recipient}?subject${ - encodeURIComponent(prefs["pref_subject"]) - }&body=${ - encodeURIComponent(prefs["pref_body"]) + a.href = `mailto:${recipient}?subject${encodeURIComponent(prefs["pref_subject"]) + }&body=${encodeURIComponent(prefs["pref_body"]) }`; a.textContent = recipient; list.appendChild(contentDoc.createElement("li")).appendChild(a); - } + } content.appendChild(list); - } + } Array.forEach(contentDoc.querySelectorAll(".close, a"), makeCloser); debug("frame initialized"); } @@ -318,9 +316,9 @@ function main() { frame.addEventListener("load", e => { debug("frame loaded"); - myPort = browser.runtime.connect({name: "contact_finder"}).onMessage.addListener(m => { - prefs = m; - initFrame(); + myPort = browser.runtime.connect({ name: "contact_finder" }).onMessage.addListener(m => { + prefs = m; + initFrame(); }); }); } diff --git a/content/externalLicenseChecker.js b/content/externalLicenseChecker.js index 982ce04..600a501 100644 --- a/content/externalLicenseChecker.js +++ b/content/externalLicenseChecker.js @@ -24,15 +24,15 @@ let fetchWebLabels = async args => { // see https://www.gnu.org/software/librejs/free-your-javascript.html#step3 - let {map, cache} = args; + let { map, cache } = args; let link = document.querySelector(`link[rel="jslicense"], link[data-jslicense="1"], a[rel="jslicense"], a[data-jslicense="1"]`); let baseURL = link ? link.href : cache.webLabels && new URL(cache.webLabels.href, document.baseURI); if (baseURL) try { let response = await fetch(baseURL); if (!response.ok) throw `${response.status} ${response.statusText}`; let doc = new DOMParser().parseFromString( - await response.text(), - "text/html" + await response.text(), + "text/html" ); let base = doc.querySelector("base"); if (base) { @@ -49,9 +49,9 @@ let script = firstLink(cols[0]); let licenseLinks = allLinks(cols[1]); let sources = cols[2] ? allLinks(cols[2]) : []; - map.set(script.url, {script, licenseLinks, sources}); + map.set(script.url, { script, licenseLinks, sources }); } catch (e) { - console.error("LibreJS: error parsing Web Labels at %s, row %s", baseURL, row.innerHTML, e); + console.error("LibreJS: error parsing Web Labels at %s, row %s", baseURL, row.innerHTML, e); } } } catch (e) { @@ -62,22 +62,22 @@ let fetchLicenseInfo = async cache => { let map = new Map(); - let args = {map, cache}; + let args = { map, cache }; // in the fetchXxx methods we add to a map whatever license(s) // URLs and source code references we can find in various formats // (WebLabels is currently the only implementation), keyed by script URLs. await Promise.all([ - fetchWebLabels(args), - // fetchXmlSpdx(args), - // fetchTxtSpdx(args), - // ... + fetchWebLabels(args), + // fetchXmlSpdx(args), + // fetchTxtSpdx(args), + // ... ]); return map; } let handlers = { async checkLicensedScript(m) { - let {url, cache} = m; + let { url, cache } = m; if (!licensedScripts) licensedScripts = await fetchLicenseInfo(cache); return licensedScripts.get(url) || licensedScripts.get(url.replace(/\?.*/, '')); } @@ -86,7 +86,7 @@ browser.runtime.onMessage.addListener(async m => { if (m.action in handlers) try { debug("Received message", m); - let result = await handlers[m.action](m); + let result = await handlers[m.action](m); return result; } catch (e) { console.error(e); -- cgit v1.2.3