Link OpenStreetMap changesets to achavi

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

目前为 2020-04-05 提交的版本。查看 最新版本

// ==UserScript==
// @name        Link OpenStreetMap changesets to achavi
// @description Turns every changeset into a link that leads to this useful OSM change inspector.
// @namespace   gf.qytechs.cn/users/4813-swyter
// @match       https://www.openstreetmap.org/user/*/history
// @match       https://www.openstreetmap.org/changeset/*
// @grant       none
// @version     2020.04.05
// @author      Swyter
// @run-at      document-idle
// ==/UserScript==

/* swy: create an observer instance (in the *history* page) linked to the callback function as shown here:
        https://www.freecodecamp.org/forum/t/how-can-i-detect-or-trigger-an-event-when-text-in-p-tag-is-changed/270692/4 */
new MutationObserver(function(mutationsList, observer)
{
  for (var mutation of mutationsList)
    if (mutation.type == 'childList')
      console.log('[i] changesets frame refreshed, re-running the link-ifier: ', mutation);

  for (var elem of document.querySelectorAll('div.changesets div.details'))
    elem.innerHTML = elem.innerHTML.replace(/#(\d+)/g, `#<a title='View revision $1 on achavi.' href=https://nrenner.github.io/achavi/?changeset=$1>$1</a>`)
  
}).observe(document.querySelector('div#sidebar_content > div.changesets') || document.createElement('dummy'), { childList: true });

/* swy: and do the same thing in the *changeset* page, where as a title; in this case the element is static,
        so we don't need to wait for JS to grab it and it in there */
(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>`))


/* swy: the guys at Greasemonkey are a bunch of incompetent folks, they break stuff all the time */
function GM_addStyle(text) { document.documentElement.appendChild(((thing = document.createElement('style')).textContent = text) && thing); }

GM_addStyle(
`
  div#sidebar_content > h2 a,
  div#sidebar_content > div.changesets > .details a
  {
    color: #243dae !important;
  }
`);

QingJ © 2025

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