OpenStreetMap Deep History integration v.MM

2023-12-06, 13:28:50 (OSM, OpenStreetMaps)

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