User:So9q/fatcat-link.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/*
* Simple script to add a link to the fatcat! database in the Tools section on items.
* Forked from https://www.wikidata.org/wiki/User:Fnielsen/scholia-link.js by Fnielsen.
*/
( function ( mw, $ ) {
if (mw.config.get( 'wgNamespaceNumber' ) != 0) {
return;
} else {
mw.hook("wikibase.entityPage.entityLoaded").add( function ( e ) {
for (key in e["claims"]){
// We only care about DOI
if (key == "P356") {
if (e["claims"]["P356"].len > 1) {
console.log("crossref-link.js: Error got more than 1 DOI")
}
else{
for (key in e["claims"]["P356"][0]["mainsnak"]["datavalue"]){
console.log( key + ": " + e["claims"]["P356"][0]["mainsnak"]["datavalue"][key]);
}
let doi = e["claims"]["P356"][0]["mainsnak"]["datavalue"]["value"]
// Add portlet link for item
mw.util.addPortletLink(
'p-tb',
'//api.fatcat.wiki/v0/release/lookup?doi=' + doi,
'Lookup DOI in fatcat!',
't-fatcat',
'Try finding this Wikidata item in the fatcat! JSON API using the DOI'
);
}
}
}
});
}
}( mediaWiki, jQuery ) );