Link OpenStreetMap changesets to 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
  3. // @description Turns every changeset into a link that leads to this useful OSM change inspector.
  4. // @namespace gf.qytechs.cn/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-idle
  11. // ==/UserScript==
  12.  
  13. /* swy: create an observer instance (in the *history* page) linked to the callback function as shown here:
  14. https://www.freecodecamp.org/forum/t/how-can-i-detect-or-trigger-an-event-when-text-in-p-tag-is-changed/270692/4 */
  15. new MutationObserver(function(mutationsList, observer)
  16. {
  17. for (var mutation of mutationsList)
  18. if (mutation.type == 'childList')
  19. console.log('[i] changesets frame refreshed, re-running the link-ifier: ', mutation);
  20.  
  21. for (var elem of document.querySelectorAll('div.changesets div.details'))
  22. elem.innerHTML = elem.innerHTML.replace(/#(\d+)/g, `#<a title='View revision $1 on achavi.' href=https://nrenner.github.io/achavi/?changeset=$1>$1</a>`)
  23. }).observe(document.querySelector('div#sidebar_content > div.changesets') || document.createElement('dummy'), { childList: true });
  24.  
  25. /* swy: and do the same thing in the *changeset* page, where as a title; in this case the element is static,
  26. so we don't need to wait for JS to grab it and it in there */
  27. (title = document.querySelector('div#sidebar_content > h2')) && (title.innerHTML = title.innerHTML.replace(/(\d+)/g, `<a title='View revision $1 on achavi.' href=https://nrenner.github.io/achavi/?changeset=$1>$1</a>`))
  28.  
  29.  
  30. /* swy: the guys at Greasemonkey are a bunch of incompetent folks, they break stuff all the time */
  31. function GM_addStyle(text) { document.documentElement.appendChild(((thing = document.createElement('style')).textContent = text) && thing); }
  32.  
  33. GM_addStyle(
  34. `
  35. div#sidebar_content > h2 a,
  36. div#sidebar_content > div.changesets > .details a
  37. {
  38. color: #243dae !important;
  39. }
  40. `);

QingJ © 2025

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