Link OpenStreetMap changesets to achavi / Open on achavi

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

目前为 2021-11-12 提交的版本。查看 最新版本

  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. // @grant none
  10. // @version 2021.11.11
  11. // @author Swyter
  12. // @license Unlicense
  13. // @run-at document-start
  14. // @icon https://upload.wikimedia.org/wikipedia/commons/b/b0/Openstreetmap_logo.svg
  15. // ==/UserScript==
  16.  
  17. /* swy: create an observer instance (in the *history* page) linked to the callback function as shown here:
  18. https://www.freecodecamp.org/forum/t/how-can-i-detect-or-trigger-an-event-when-text-in-p-tag-is-changed/270692/4 */
  19. mo = new MutationObserver(function(mutationsList, observer)
  20. {
  21. for (var mutation of mutationsList)
  22. if (mutation.type == 'childList')
  23. console.log('[i] changesets frame refreshed, re-running the link-ifier: ', mutation);
  24.  
  25. __relinkifier();
  26. });
  27.  
  28. function __relinkifier()
  29. {
  30. console.log('[i] relinkifier()', document.querySelectorAll('div.changesets > ol.changesets > li[id^=changeset_] div.col, div#sidebar_content h2'));
  31. /* swy: this is the meat of the function; we also add an 'ach' attribute to simplify our CSS rules */
  32. for (var elem of document.querySelectorAll('div.changesets > ol.changesets > li[id^=changeset_] div.col, div#sidebar_content h2'))
  33. 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>`);
  34. /* swy: and do the same thing in the *changeset* page, where as a title; in this case the element is static,
  35. so we don't need to wait for JS to grab it and it in there */
  36. mo.observe(document.querySelector('div#sidebar_content') || document.createElement('dummy'), { childList: true });
  37. mo.observe(document.querySelector('div.changesets') || document.createElement('dummy'), { childList: true });
  38. mo.observe(document.querySelector('div#sidebar_loader') || document.createElement('dummy'), { childList: true });
  39. }
  40.  
  41. window.addEventListener('DOMContentLoaded', function()
  42. {
  43. __relinkifier(); /* swy: this runs once, when the page is ready; it also sets up the observers */
  44. });
  45.  
  46. /* --- */
  47.  
  48. /* swy: the guys at Greasemonkey are a bunch of incompetent folks, they break stuff all the time */
  49. function GM_addStyle(text) { document.documentElement.appendChild(((thing = document.createElement('style')).textContent = text) && thing); }
  50.  
  51. GM_addStyle(`
  52. div#sidebar_content > h2 a[ach],
  53. div#sidebar_content > div.changesets .details a[ach]
  54. {
  55. color: #192d86 !important; /* swy: make the overriden links dark blue, so they aren't that bright */
  56. }
  57. `);

QingJ © 2025

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