aboutsummaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorRuben Rodriguez <ruben@gnu.org>2018-09-26 20:41:22 +0000
committerRuben Rodriguez <ruben@gnu.org>2018-09-26 20:41:22 +0000
commit564f2eb266bda6c947aae303a449406e7d40f190 (patch)
treeb4f78cd57e515e61ded4eebbd3ef8befbe4241af /content
parent08f01213cc2e3929bfd0ae55514b2e3bd2e5d6f3 (diff)
parent6c7f05852fbcb64f9f18e2220fd3bf1f6c5ae710 (diff)
Merge #21 `Match WebLabels by label rather than by canonical URL.`
Diffstat (limited to 'content')
-rw-r--r--content/externalLicenseChecker.js29
1 files changed, 17 insertions, 12 deletions
diff --git a/content/externalLicenseChecker.js b/content/externalLicenseChecker.js
index be09ef1..181e3f9 100644
--- a/content/externalLicenseChecker.js
+++ b/content/externalLicenseChecker.js
@@ -21,7 +21,7 @@
"use strict";
{
let licensedScripts = null;
-
+
let fetchWebLabels = async args => {
// see https://www.gnu.org/software/librejs/free-your-javascript.html#step3
let {map, cache} = args;
@@ -40,26 +40,31 @@
} else {
doc.head.appendChild(doc.createElement("base")).href = baseURL;
}
- let firstURL = parent => parent.querySelector("a").href;
- let allURLs = parent => Array.map(parent.querySelectorAll("a"), a => a.href);
- for (let row of doc.querySelectorAll("table#jslicense-labels1 tr")) {
- let cols = row.querySelectorAll("td");
- let scriptURL = firstURL(cols[0]);
- let licenseURLs = allURLs(cols[1]);
- let sourceURLs = cols[2] ? allURLs(cols[2]) : [];
- map.set(scriptURL, {scriptURL, licenseURLs, sourceURLs});
+ let link = a => ({ url: a.href, label: a.textContent });
+ let firstLink = parent => link(parent.querySelector("a"));
+ let allLinks = parent => Array.map(parent.querySelectorAll("a"), link);
+ for (let row of doc.querySelectorAll("table#jslicense-labels1 > tbody > tr")) {
+ try {
+ let cols = row.querySelectorAll("td");
+ let script = firstLink(cols[0]);
+ let licenseLinks = allLinks(cols[1]);
+ let sources = cols[2] ? allLinks(cols[2]) : [];
+ map.set(script.url, {script, licenseLinks, sources});
+ } catch (e) {
+ console.error("LibreJS: error parsing Web Labels at %s, row %s", baseURL, row.innerHTML, e);
+ }
}
} catch (e) {
console.error("Error fetching Web Labels at %o", link, e);
}
return map;
}
-
+
let fetchLicenseInfo = async cache => {
let map = new Map();
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
+ // 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),
@@ -69,7 +74,7 @@
]);
return map;
}
-
+
let handlers = {
async checkLicensedScript(m) {
let {url, cache} = m;