diff --git a/js/sidebarController.js b/js/sidebarController.js index 60784c0..5497dec 100644 --- a/js/sidebarController.js +++ b/js/sidebarController.js @@ -112,13 +112,30 @@ function updateMetaTable(entity, changeset) { document.getElementById('meta-table').innerHTML = html; } +const urlRegex = /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/i; +const qidRegex = /^Q\d+$/; +const wikipediaRegex = /^(.+):(.+)$/; +const nwisRegex = /^\d{8,15}$/; + function updateTagsTable(tags) { let html = ""; html += `KeyValue`; let keys = Object.keys(tags).sort(); for (let i in keys) { let key = keys[i]; - html += `${key}${tags[key]}`; + let value = tags[key]; + let element = value; + if (urlRegex.test(value)) { + element = `${value}`; + } else if ((key === 'wikidata' || key.endsWith(':wikidata')) && qidRegex.test(value)) { + element = `${value}`; + } else if ((key === 'wikipedia' || key.endsWith(':wikipedia')) && wikipediaRegex.test(value)) { + let results = wikipediaRegex.exec(value); + element = `${value}`; + } else if (key === 'ref' && tags.man_made === 'monitoring_station' && tags.operator === "United States Geological Survey" && nwisRegex.test(value)) { + element = `${value}`; + } + html += `${key}${element}`; } document.getElementById('tag-table').innerHTML = html; }