Greasy Fork 支持简体中文。

OpenStreetMap Changeset Viewer Integration v.MM

2023-12-06 @ 20:10:15 (OSM, OpenStreetMaps)

  1. // ==UserScript==
  2. // @name OpenStreetMap Changeset Viewer Integration v.MM
  3. // @namespace Violentmonkey Scripts
  4. // @match https://www.openstreetmap.org/*
  5. // @match https://osm.mapki.com/*
  6. // @match https://overpass-api.de/achavi/*
  7. // @match https://rene78.github.io/latest-changes/*
  8. // @grant none
  9. // @version 1.1.2
  10. // @license GNU Affero General Public License v3.0
  11. // @author Marek-M
  12. // @description 2023-12-06 @ 20:10:15 (OSM, OpenStreetMaps)
  13. // @updateURL
  14. // @downloadURL
  15. // ==/UserScript==
  16.  
  17. (() => {
  18. 'use strict'
  19.  
  20. const pattern = /^https?:\/\/(www\.)?(osm\.org|openstreetmap\.org)\/(changeset)\/(\d+)$/g
  21. // const pattern2 = /^(Zestaw zmian: )(\d+)$/g
  22. const addHistoryButtons = linkElement => {
  23. if (linkElement.getAttribute('data-history-button')) return
  24. const matched = linkElement.href.match(pattern)
  25. if (!matched) return
  26. const [_, __, ___, type, id] = matched[0].split('/')
  27.  
  28. // historyLinksArray - each element should have 3 elements: [textContent, title, historyLink]
  29. const textContent = 0, title = 1, historyLink = 2
  30. const historyLinksArray =
  31. [
  32. ['A', `Check in Achavi - changeset no. ${id}` , `https://overpass-api.de/achavi/?changeset=${id}` ],
  33. ['V', `Check Changeset with Comparison Visualization - changeset no. ${id}` , `https://resultmaps.neis-one.org/osm-change-viz?c=${id}` ],
  34. ['C', `Check in OSMCha - changeset no. ${id}` , `https://osmcha.org/changesets/${id}` ],
  35. ['H', `OSM History Viewer - changeset no. ${id}` , `https://osmhv.openstreetmap.de/changeset.jsp?id=${id}` ]
  36. ]
  37.  
  38. historyLinksArray.forEach
  39. (
  40. (historyLinkArrayElement) =>
  41. {
  42. const button = document.createElement('a')
  43. button.textContent = historyLinkArrayElement[textContent]
  44. button.title = historyLinkArrayElement[title]
  45. button.href = historyLinkArrayElement[historyLink]
  46. button.alt = button.title
  47. button.target = '_blank'
  48. button.style.paddingLeft = '0.45ch'
  49. button.style.paddingRight = '0.20ch'
  50. button.style.position = 'relative'
  51. button.style.top = '-0.5ch'
  52. button.style.display = 'inline-block'
  53. button.style.transform = 'scale(1.1)'
  54. button.style.fontSize = '70%'
  55. button.addEventListener('click', event => {event.stopPropagation()})
  56. linkElement.insertAdjacentElement('beforeend', button)
  57. }
  58. ) // forEach
  59. linkElement.setAttribute('data-history-button', 'true')
  60. }
  61.  
  62. const scanLinks = () => {
  63. const links = document.querySelectorAll('a')
  64. links.forEach(addHistoryButtons)
  65. }
  66.  
  67. const observer = new MutationObserver(scanLinks)
  68. observer.observe(document.body, {
  69. childList: true,
  70. subtree: true
  71. })
  72. scanLinks()
  73. })()
  74.