Link OpenStreetMap changesets to achavi / Open on achavi

Turns every changeset into a link that leads to this useful OSM change inspector.

  1. // ==UserScript==
  2. // @name Link OpenStreetMap changesets to achavi / Open on achavi
  3. // @description Turns every changeset into a link that leads to this useful OSM change inspector.
  4. // @name:es Enlazar los cambios de OpenStreetMap con achavi / Abrir en achavi
  5. // @description:es Convierte cada página con cambios («changeset») en un enlace que se puede abrir con este práctico inspector/comparador de versiones para OSM.
  6. // @namespace gf.qytechs.cn/users/4813-swyter
  7. // @match https://www.openstreetmap.org/user/*/history
  8. // @match https://www.openstreetmap.org/changeset/*
  9. // @match https://www.openstreetmap.org/history
  10. // @grant none
  11. // @version 2021.11.11.1
  12. // @author Swyter
  13. // @license Unlicense
  14. // @run-at document-start
  15. // @icon https://upload.wikimedia.org/wikipedia/commons/b/b0/Openstreetmap_logo.svg
  16. // ==/UserScript==
  17.  
  18. /* swy: create an observer instance (in the *history* page) linked to the callback function as shown here:
  19. https://www.freecodecamp.org/forum/t/how-can-i-detect-or-trigger-an-event-when-text-in-p-tag-is-changed/270692/4 */
  20. mo = new MutationObserver(function(mutationsList, observer)
  21. {
  22. for (var mutation of mutationsList)
  23. if (mutation.type == 'childList')
  24. console.log('[i] changesets frame refreshed, re-running the link-ifier: ', mutation);
  25.  
  26. __relinkifier();
  27. });
  28.  
  29. function __relinkifier()
  30. {
  31. console.log('[i] relinkifier()', document.querySelectorAll('div.changesets > ol.changesets > li[id^=changeset_] div.col, div#sidebar_content h2'));
  32. /* swy: this is the meat of the function; we also add an 'ach' attribute to simplify our CSS rules */
  33. for (var elem of document.querySelectorAll('div.changesets > ol.changesets > li[id^=changeset_] div.col, div#sidebar_content h2'))
  34. elem.innerHTML = elem.innerHTML.replace(/(\d\d\d\d+)/g, `<a title='View revision $1 on achavi.' ach href=https://nrenner.github.io/achavi/?changeset=$1>$1</a>`);
  35. /* swy: and do the same thing in the *changeset* page, where as a title; in this case the element is static,
  36. so we don't need to wait for JS to grab it and it in there */
  37. mo.observe(document.querySelector('div#sidebar_content') || document.createElement('dummy'), { childList: true });
  38. mo.observe(document.querySelector('div.changesets') || document.createElement('dummy'), { childList: true });
  39. mo.observe(document.querySelector('div#sidebar_loader') || document.createElement('dummy'), { childList: true });
  40. }
  41.  
  42. window.addEventListener('DOMContentLoaded', function()
  43. {
  44. __relinkifier(); /* swy: this runs once, when the page is ready; it also sets up the observers */
  45. });
  46.  
  47. /* --- */
  48.  
  49. /* swy: the guys at Greasemonkey are a bunch of incompetent folks, they break stuff all the time */
  50. function GM_addStyle(text) { document.documentElement.appendChild(((thing = document.createElement('style')).textContent = text) && thing); }
  51.  
  52. GM_addStyle(`
  53. div#sidebar_content > h2 a[ach],
  54. div#sidebar_content > div.changesets .details a[ach]
  55. {
  56. color: #192d86 !important; /* swy: make the overriden links dark blue, so they aren't that bright */
  57. }
  58. `);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址