Last active
March 5, 2020 10:41
-
-
Save floscher/93663dc9ba9299c31b4aae392018587c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Achavi-Link on OSM.org | |
// @namespace de.schaeferban | |
// @include https://openstreetmap.org/user/*/history* | |
// @include https://www.openstreetmap.org/user/*/history* | |
// @include http://openstreetmap.org/user/*/history* | |
// @include http://www.openstreetmap.org/user/*/history* | |
// @include https://openstreetmap.org/changeset/* | |
// @include https://www.openstreetmap.org/changeset/* | |
// @include http://openstreetmap.org/changeset/* | |
// @include http://www.openstreetmap.org/changeset/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
function getAchaviLink(changesetId) { | |
var achaviLink = document.createElement('a'); | |
achaviLink.setAttribute('href', 'https://overpass-api.de/achavi?changeset=' + changesetId); | |
achaviLink.setAttribute('target', '_blank'); | |
achaviLink.setAttribute('class', 'button'); | |
achaviLink.setAttribute('style', 'min-width:0;min-height:0;padding:.5em;margin:.25em;line-height:1'); | |
achaviLink.appendChild(document.createTextNode("Achavi")); | |
return achaviLink; | |
} | |
window.onload = function() { | |
console.log('Changeset list for user') | |
var changesets = document.querySelectorAll('div.changesets ol li'); | |
for (var i = 0; i < changesets.length; i++) { | |
if(changesets[i].getAttribute('id').match(/^changeset_[1-9][0-9]*/)) { | |
changesets[i].appendChild(getAchaviLink(changesets[i].getAttribute('id').substring(10))); | |
} | |
} | |
var browseSection = document.querySelector('div.browse-section'); | |
var changesetLink = document.querySelector('div.secondary-actions + div.secondary-actions a'); | |
if (browseSection !== null && changesetLink !== null) { | |
console.log('Changeset details page'); | |
if (changesetLink.getAttribute('href').match(/^\/api\/0\.6\/changeset\/[1-9][0-9]*/)) { | |
browseSection.appendChild(getAchaviLink(changesetLink.getAttribute('href').substring(19))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment