Last active
January 29, 2023 05:18
-
-
Save Zaczero/f003b0e029b6a0f0fbbf99dfffe6cdba to your computer and use it in GitHub Desktop.
🗺️ Easily copy user's changeset IDs on OpenStreetMap
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 🗺️ Easily copy user's changeset IDs on OpenStreetMap | |
// @namespace Violentmonkey Scripts | |
// @match https://www.openstreetmap.org/user/*/history | |
// @grant none | |
// @version 1.0 | |
// @license GNU Affero General Public License v3.0 | |
// @author Zaczero | |
// @description 1/29/2023, 5:25:13 AM | |
// @updateURL https://gist.github.com/Zaczero/f003b0e029b6a0f0fbbf99dfffe6cdba/raw/osm-copy-changeset-ids.user.js | |
// @downloadURL https://gist.github.com/Zaczero/f003b0e029b6a0f0fbbf99dfffe6cdba/raw/osm-copy-changeset-ids.user.js | |
// ==/UserScript== | |
(() => { | |
'use strict' | |
const waitFor = selector => { | |
return new Promise(resolve => { | |
const queryStart = document.querySelector(selector) | |
if (queryStart) { | |
return resolve(queryStart) | |
} | |
const observer = new MutationObserver(mutations => { | |
const query = document.querySelector(selector) | |
if (query) { | |
observer.disconnect() | |
return resolve(query) | |
} | |
}) | |
observer.observe(document.body, { | |
childList: true, | |
subtree: true | |
}) | |
}) | |
} | |
waitFor('#sidebar_content').then(div => { | |
const dummy = document.createElement('div') | |
dummy.innerHTML = '<div class="text-center mt-2"><div class="btn btn-primary">Copy changeset IDs</div></div>' | |
const btn = dummy.firstChild.firstChild | |
div.appendChild(dummy.firstChild) | |
btn.addEventListener('click', () => { | |
const elements = document.querySelectorAll('.col > a.changeset_id') | |
const text = [...elements].map(el => el.textContent.trim().substring(1)).join(', ') | |
// Copy text to clipboard | |
navigator.clipboard.writeText(text).then(() => { | |
console.log(text) | |
}, err => { | |
console.error(err) | |
}) | |
}) | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment