User:Isaac (WMF)/citation finder.js

// Code largely borrowed from: https://en.wikipedia.org/wiki/User:TayIorRobinson/wikigender.js // and https://en.wikipedia.org/wiki/User:SuperHamster/CiteUnseen.js

const CITATION_API = "https://citation-linking.wmcloud.org/api/check-citations?";

// article but not Main Page if (mw.config.get('wgNamespaceNumber') == 0 && mw.config.get('wgWikibaseItemId') != 'Q5296') { let lang = mw.config.get("wgDBname").replace("wiki",""); if (lang == "en") { let pageid = mw.config.get("wgArticleId"); let baseurl = CITATION_API + "lang=" + lang + "&page_id=" + pageid; let refs = document.querySelectorAll('li[id^=cite_note]'); for (let i = 0; i < refs.length; i++) { let citation_url = baseurl + "&citation_id=" + refs.item(i).id.substring(10); processIcon(refs.item(i), citation_url); }	} }

function processIcon(refNode, api_url) { let linkNode = document.createElement("a"); linkNode.href = api_url; linkNode.title = "See where else this citation is used";

let imgNode = document.createElement("img"); imgNode.alt = "Search icon"; imgNode.src = "https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/OOjs_UI_indicator_search-ltr.svg/17px-OOjs_UI_indicator_search-ltr.svg.png"; imgNode.decoding = "async"; imgNode.height = 17; imgNode.width = 17; imgNode.paddingRight = 5; linkNode.appendChild(imgNode); refNode.appendChild(linkNode); }