OSM Hide Relation Centroid Circle

Hides the orange circle that appears at the centroid of selected relations (e.g. municipality/county borders) on openstreetmap.org

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         OSM Hide Relation Centroid Circle
// @name:sv      OSM – Dölj relations-centroidcirkel
// @namespace    https://greasyfork.org/users/1168708-rotski
// @version      1.0.1
// @description  Hides the orange circle that appears at the centroid of selected relations (e.g. municipality/county borders) on openstreetmap.org
// @description:sv Döljer den orange cirkeln som visas vid centroiden av valda relationer (t.ex. kommun- och länsgränser) på openstreetmap.org
// @author       Rotski + Claude
// @match        https://www.openstreetmap.org/*
// @icon         https://www.openstreetmap.org/favicon.ico
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';

  var DEFAULT_COLOR = '#FF6200';
  var currentColor = GM_getValue('borderColor', DEFAULT_COLOR);

  function applyStyles() {
    document.querySelectorAll('.leaflet-interactive').forEach(function (el) {
      var stroke = el.getAttribute('stroke') || '';
      var fill = el.getAttribute('fill') || '';
      var d = el.getAttribute('d') || '';
      if (!d) return;
      if (fill === '#FF6200') {
        el.style.display = 'none';
      } else if (stroke === '#FF6200') {
        el.style.stroke = currentColor;
        el.style.fill = 'none';
      }
    });
  }

  // UI
  var ui = document.createElement('div');
  ui.style.cssText = [
    'position:fixed',
    'bottom:20px',
    'right:20px',
    'z-index:99999',
    'background:#fff',
    'border:1px solid #ccc',
    'border-radius:8px',
    'padding:10px 14px',
    'font:13px/1.4 sans-serif',
    'box-shadow:0 2px 8px rgba(0,0,0,0.2)',
    'display:flex',
    'align-items:center',
    'gap:8px'
  ].join(';');

  var label = document.createElement('span');
  label.textContent = 'Gränsfärg:';

  var picker = document.createElement('input');
  picker.type = 'color';
  picker.value = currentColor;
  picker.style.cssText = 'width:36px;height:28px;border:none;padding:0;cursor:pointer;background:none';

  var resetBtn = document.createElement('button');
  resetBtn.textContent = 'Återställ';
  resetBtn.style.cssText = 'font:12px sans-serif;padding:4px 8px;cursor:pointer;border:1px solid #ccc;border-radius:4px;background:#f5f5f5';

  picker.addEventListener('input', function () {
    currentColor = picker.value;
    GM_setValue('borderColor', currentColor);
    applyStyles();
  });

  resetBtn.addEventListener('click', function () {
    currentColor = DEFAULT_COLOR;
    picker.value = DEFAULT_COLOR;
    GM_setValue('borderColor', DEFAULT_COLOR);
    applyStyles();
  });

  ui.appendChild(label);
  ui.appendChild(picker);
  ui.appendChild(resetBtn);
  document.body.appendChild(ui);

  new MutationObserver(applyStyles).observe(document.documentElement, {
    childList: true,
    subtree: true
  });

  applyStyles();
  setTimeout(applyStyles, 500);
  setTimeout(applyStyles, 1500);
})();