User:Abbe98/inaturalist.js
Jump to navigation
Jump to search
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.
function getWidgetHTML(widgetURL) {
var summaryElement = document.createElement('summary');
var summaryText = document.createTextNode('iNaturalist');
summaryElement.appendChild(summaryText);
var iframeElement = document.createElement('iframe');
iframeElement.width = '100%';
iframeElement.height = '300';
iframeElement.src = widgetURL;
var detailsElement = document.createElement('details');
detailsElement.appendChild(summaryElement);
detailsElement.appendChild(iframeElement);
return detailsElement;
}
(function(mw, $) {
if (window.mw.config.values.wbEntityId) {
window.mw.hook('wikibase.entityPage.entityLoaded').add(function(entity) {
if (entity.claims.P7471) {
var iNaturalistID = entity.claims.P7471[0].mainsnak.datavalue.value;
var widgetURL = 'https://www.inaturalist.org/places/guide_widget/' + iNaturalistID + '?size=small';
document.querySelector('.wikibase-entitytermsview-heading').appendChild(getWidgetHTML(widgetURL));
}
});
}
})(mediaWiki, jQuery);