Link OpenStreetMap changesets to achavi / Open on achavi

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

当前为 2020-04-05 提交的版本,查看 最新版本

  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. // @namespace greasyfork.org/users/4813-swyter
  5. // @match https://www.openstreetmap.org/user/*/history
  6. // @match https://www.openstreetmap.org/changeset/*
  7. // @grant none
  8. // @version 2020.04.05
  9. // @author Swyter
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. function __relinkifier()
  14. {
  15. console.log('[i] relinkifier()', document.querySelectorAll('div.changesets div.details'));
  16. for (var elem of document.querySelectorAll('div.changesets div.details'))
  17. elem.innerHTML = elem.innerHTML.replace(/#(\d+)/g, `#<a title='View revision $1 on achavi.' ach href=https://nrenner.github.io/achavi/?changeset=$1>$1</a>`);
  18. /* swy: and do the same thing in the *changeset* page, where as a title; in this case the element is static,
  19. so we don't need to wait for JS to grab it and it in there */
  20. (title = document.querySelector('div#sidebar_content > h2')) &&
  21. (title.innerHTML = title.innerHTML.replace(/(\d+)/g, `<a title='View revision $1 on achavi.' ach href=https://nrenner.github.io/achavi/?changeset=$1>$1</a>`));
  22. }
  23.  
  24. window.addEventListener('DOMContentLoaded', function()
  25. {
  26. /* swy: create an observer instance (in the *history* page) linked to the callback function as shown here:
  27. https://www.freecodecamp.org/forum/t/how-can-i-detect-or-trigger-an-event-when-text-in-p-tag-is-changed/270692/4 */
  28. new MutationObserver(function(mutationsList, observer)
  29. {
  30. for (var mutation of mutationsList)
  31. if (mutation.type == 'childList')
  32. console.log('[i] changesets frame refreshed, re-running the link-ifier: ', mutation);
  33.  
  34. __relinkifier();
  35. }).observe(document.querySelector('div#sidebar_content') || document.createElement('dummy'), { childList: true, subtree: true });
  36. __relinkifier();
  37. });
  38.  
  39. /* --- */
  40.  
  41. /* swy: the guys at Greasemonkey are a bunch of incompetent folks, they break stuff all the time */
  42. function GM_addStyle(text) { document.documentElement.appendChild(((thing = document.createElement('style')).textContent = text) && thing); }
  43.  
  44. GM_addStyle(`
  45. div#sidebar_content > h2 a[ach],
  46. div#sidebar_content > div.changesets .details a[ach]
  47. {
  48. color: #192d86 !important;
  49. }
  50. `);