User:Bovlb/osm.js

From Wikidata
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.
//based on User:Abbe98/osm.js

mw.loader.using(['jquery.ui'], function() {
  if (mw.config.get('wgNamespaceNumber') !== 0 || !mw.config.exists('wbEntityId')) {
    return;
  }
  var item = window.mw.config.values.wgRelevantPageName;
  var query = 'https://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%3B%0A%28%0A%20%20node%5B"wikidata"%3D"' + item + '"%5D%3B%0A%20%20way%5B"wikidata"%3D"' + item + '"%5D%3B%0A%20%20relation%5B"wikidata"%3D"' + item + '"%5D%3B%0A%29%3B%0Aout%20body%3B%0A>%3B%0Aout%20skel%20qt%3B';
  $.ajax({
    url: query,
  }).done(function(result) {
    if (result.elements[0]) {
      var id = result.elements[0].id;
      var type = result.elements[0].type;

      var linkElement = '<li class="osm"><a href="https://www.openstreetmap.org/' + type + '/' + id + '">OpenStreetMap Element</a></li>';

      var navList = document.getElementById('p-tb').lastElementChild.firstElementChild;
      navList.innerHTML += linkElement;
    }
  });
});