Skip to content

Commit

Permalink
minor code details
Browse files Browse the repository at this point in the history
  • Loading branch information
StigNygaard committed Jan 11, 2024
1 parent 54271c2 commit 94fa763
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion WebExtension/boarding/onboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h1>Congratulations!</h1>

<p class="introlink"><a href="https://www.rockland.dk/xIFr/start/" title="Introduction" target="_blank" rel="noopener" data-context="onboard">xIFr - Getting started</a></p>

<p>Also, make sure to make a visit to xIFr's <a href="#" class="settings"><em>Options Page</em></a> where you can
<p>Also, make sure to make a visit to xIFr's <a href="/options/options.html" class="settings"><em>Options Page</em></a> where you can
adjust some aspects of how xIFr looks and behaves. Look for the wheel
<img src="../icons/wheel-48.png" class="settings" alt="" /> in the metadata-popup to access the options.
My personal favorite settings are "Dark Theme" and the "Snap right" popup positioning.</p>
Expand Down
2 changes: 1 addition & 1 deletion WebExtension/boarding/upboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1>Congratulations!</h1>

<p class="introlink"><a href="https://www.rockland.dk/xIFr/start/" title="Introduction" target="_blank" rel="noopener" data-context="upboard">xIFr - Getting started</a></p>

<p>Also, make sure to make a visit to xIFr's <a href="#" class="settings"><em>Options Page</em></a> where you can
<p>Also, make sure to make a visit to xIFr's <a href="/options/options.html" class="settings"><em>Options Page</em></a> where you can
adjust some aspects of how xIFr looks and behaves. Look for the wheel
<img src="../icons/wheel-48.png" class="settings" alt="" /> in the metadata popup to access the options. My
personal favorite settings are "Dark Theme" and the "Snap right" popup positioning.</p>
Expand Down
52 changes: 26 additions & 26 deletions WebExtension/xmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function xmpClass() {
}

// Creators come in an ordered list. Get them all.
val = getXMPOrderedArray(dom, "http:https://purl.org/dc/elements/1.1/", "creator", "").filter( item => item && item.trim()); // filter skips empty values
val = getXMPOrderedArray(dom, "http:https://purl.org/dc/elements/1.1/", "creator", "").filter( item => item?.trim()); // filter skips empty values
if (val?.length) {
dataObj.Creator = val.join("; "); // todo: Make a Set and handle later like Software or Keywords?
// Might be used by Google Image Search
Expand Down Expand Up @@ -106,7 +106,7 @@ function xmpClass() {
if (urls) dataObj.CreatorURLs = urls;
}

val = getXMPOrderedArray(dom, "http:https://iptc.org/std/Iptc4xmpExt/2008-02-29/", "PersonInImage", "").filter( item => item && item.trim()); // filter skips empty values
val = getXMPOrderedArray(dom, "http:https://iptc.org/std/Iptc4xmpExt/2008-02-29/", "PersonInImage", "").filter( item => item?.trim()); // filter skips empty values
if (val?.length) {
dataObj.Depicted = new Set(val);
}
Expand Down Expand Up @@ -216,7 +216,7 @@ function xmpClass() {
}
}

val = getXMPOrderedArray(dom, "http:https://ns.adobe.com/xap/1.0/mm/", "History", "http:https://ns.adobe.com/xap/1.0/sType/ResourceEvent#", "softwareAgent").filter( item => item && item.trim()); // filter skips empty values
val = getXMPOrderedArray(dom, "http:https://ns.adobe.com/xap/1.0/mm/", "History", "http:https://ns.adobe.com/xap/1.0/sType/ResourceEvent#", "softwareAgent").filter( item => item?.trim()); // filter skips empty values
if (val?.length) {
if (!dataObj.Software) {
dataObj.Software = val[val.length - 1]; // [length-1] = Last is the last used ?
Expand Down Expand Up @@ -305,7 +305,7 @@ function xmpClass() {


// Subjects (keywords) comes in a list/set. Get them all.
val = getXMPOrderedArray(dom, "http:https://purl.org/dc/elements/1.1/", "subject", "").filter( item => item && item.trim()); // filter skips empty values
val = getXMPOrderedArray(dom, "http:https://purl.org/dc/elements/1.1/", "subject", "").filter( item => item?.trim()); // filter skips empty values
if (val?.length) {
dataObj.Keywords = new Set(val); // todo: If already set by iptc, make sure we have same or more keywords!
}
Expand Down Expand Up @@ -440,11 +440,11 @@ function xmpClass() {
}

val = getXMPValue(dom, "http:https://ns.adobe.com/exif/1.0/aux/", "IsMergedHDR");
if (val && val.match(/^true$/i)) {
if (val?.match(/^true$/i)) {
dataObj.MergedCaptures = "HDR";
}
val = getXMPValue(dom, "http:https://ns.adobe.com/exif/1.0/aux/", "IsMergedPanorama");
if (val && val.match(/^true$/i)) {
if (val?.match(/^true$/i)) {
if (dataObj.MergedCaptures) {
dataObj.MergedCaptures += " + Panorama"
} else {
Expand Down Expand Up @@ -500,7 +500,7 @@ function xmpClass() {

let fu;
const addfunc = [];
if (flashFired && flashFired.match(/^true$/i)) {
if (flashFired?.match(/^true$/i)) {
fu = stringBundle.getString("yes");

if (flashMode == 3) {
Expand All @@ -509,7 +509,7 @@ function xmpClass() {
addfunc.push(stringBundle.getString("enforced"));
}

if (redEyeMode && redEyeMode.match(/^true$/i)) {
if (redEyeMode?.match(/^true$/i)) {
addfunc.push(stringBundle.getString("redeye"));
}

Expand All @@ -520,7 +520,7 @@ function xmpClass() {
}
} else {
fu = stringBundle.getString("no");
if (flashFunction && flashFunction.match(/^true$/i)) {
if (flashFunction?.match(/^true$/i)) {
addfunc.push(stringBundle.getString("noflash"));
} else if (flashMode == 2) {
addfunc.push(stringBundle.getString("enforced"));
Expand Down Expand Up @@ -593,7 +593,7 @@ function xmpClass() {
if (val) {
try {
val = parseRational(val).toFixed(2);
if (val === 0) {
if (val == 0) {
dataObj.ExposureBias = stringBundle.getString("none");
} else
// add a + sign before positive values
Expand Down Expand Up @@ -779,8 +779,8 @@ function xmpClass() {
}
}

val = getXMPOrderedArray(dom, "http:https://ns.adobe.com/exif/1.0/", "ISOSpeedRatings").filter( item => item && item.trim()); // filter skips empty values
if (val && val.length) {
val = getXMPOrderedArray(dom, "http:https://ns.adobe.com/exif/1.0/", "ISOSpeedRatings").filter( item => item?.trim()); // filter skips empty values
if (val?.length) {
dataObj.ISOequivalent = val.join(", ");
}

Expand Down Expand Up @@ -1080,8 +1080,8 @@ function xmpClass() {
return el[0].firstChild.nodeValue;
}
const list = dom.getElementsByTagNameNS("http:https://www.w3.org/1999/02/22-rdf-syntax-ns#", "Description");
for (let i = 0; i < list.length; i++) {
const attr = list[i].getAttributeNS(ns, property);
for (const element of list) {
const attr = element.getAttributeNS(ns, property);
if (attr) {
return attr;
}
Expand All @@ -1099,22 +1099,22 @@ function xmpClass() {
// only be one)
for (let i = 0; i < propertyList.length && !val; i++) {
const entriesList = propertyList[0].getElementsByTagNameNS("http:https://www.w3.org/1999/02/22-rdf-syntax-ns#", "li");
for (let j = 0; j < entriesList.length; j++) {
for (const element of entriesList) {
// found a non empty entry with fitting language
if (entriesList[j].hasChildNodes() && langTest.test(entriesList[j].getAttribute("xml:lang"))) {
val = entriesList[j].firstChild.nodeValue;
if (element.hasChildNodes() && langTest.test(element.getAttribute("xml:lang"))) {
val = element.firstChild.nodeValue;
break;
}
}
}
// our language wasn't found or its entry was empty
for (let i = 0; i < propertyList.length && !val; i++) {
const entriesList = propertyList[0].getElementsByTagNameNS("http:https://www.w3.org/1999/02/22-rdf-syntax-ns#", "li");
for (let j = 0; j < entriesList.length; j++) {
for (const element of entriesList) {
// found a non empty entry with fitting language
if (entriesList[j].hasChildNodes() &&
entriesList[j].getAttribute("xml:lang") === "x-default") {
val = entriesList[j].firstChild.nodeValue;
if (element.hasChildNodes() &&
element.getAttribute("xml:lang") === "x-default") {
val = element.firstChild.nodeValue;
break;
}
}
Expand Down Expand Up @@ -1149,21 +1149,21 @@ function xmpClass() {
let el = dom.getElementsByTagNameNS(ns, property);
if (el.length) {
const list = el[0].getElementsByTagNameNS("http:https://www.w3.org/1999/02/22-rdf-syntax-ns#", "li");
for (let i = 0; i < list.length; i++) {
if (list[i].hasChildNodes()) {
for (const element of list) {
if (element.hasChildNodes()) {
let li;
const tmp = list[i].getElementsByTagNameNS(attrNS, attrName);
const tmp = element.getElementsByTagNameNS(attrNS, attrName);
if (tmp.length && tmp[0].hasChildNodes()) {
li = tmp[0].firstChild;
} else {
li = list[i].firstChild;
li = element.firstChild;
}
if (li.nodeType === Node.TEXT_NODE) {
valarray.push(li.nodeValue);
}
} else {
// supposedly one element with values as properties
const test = list[i].getAttributeNS(attrNS, attrName);
const test = element.getAttributeNS(attrNS, attrName);
if (test) {
valarray.push(test);
}
Expand Down

0 comments on commit 94fa763

Please sign in to comment.