From af84552e321661fe0bdbed15c62c956431b8cbb2 Mon Sep 17 00:00:00 2001 From: Zhora Shalyapin Date: Mon, 10 Mar 2025 09:53:54 +0000 Subject: [PATCH] fix fullscreen button & add it to the main list --- main.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/main.js b/main.js index 0148e5f..0bfc138 100644 --- a/main.js +++ b/main.js @@ -7,6 +7,9 @@ // @match https://rst.runcity.org/*/cp_mgmt* // @icon https://www.google.com/s2/favicons?sz=64&domain=runcity.org // @grant none +// @require https://code.jquery.com/jquery-3.7.1.min.js +// @require https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js +// @require https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js // ==/UserScript== (function () { @@ -115,6 +118,8 @@ document.head.appendChild(script) } + const sleep = ms => new Promise(res => setTimeout(res, ms)); + function isEditCpPage() { let params = new URLSearchParams(document.location.search) return params.get("action") === "edit" @@ -751,6 +756,15 @@ } + function addFullscreenButton() { + $(async () => { + while (L.Control.Fullscreen === undefined) { + await sleep(500) + } + map.addControl(new L.Control.Fullscreen()) + }) + } + let styles = ` .large-menu { position: sticky; @@ -1148,19 +1162,18 @@ return } + addJs('https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js') + addCss('https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/leaflet.fullscreen.css') + + addFullscreenButton() + if (!isEditCpPage()) { return } /* action=edit HEAD */ - addJs("https://code.jquery.com/jquery-3.7.1.min.js") - addJs("https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js") - addJs("https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js") - addJs('https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js') - addCss("https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css") - addCss('https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/leaflet.fullscreen.css') addCss("https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css") /* NEW DEFALUT VALUES */ @@ -1427,9 +1440,6 @@ contentWrapper.appendChild(document.querySelector("form")) contentWrapper.appendChild(document.querySelector("#map-wrapper")) content.appendChild(contentWrapper) - $(() => { - map.addControl(new L.Control.Fullscreen()) - }) let panToCenter = document.createElement("button") panToCenter.type = "button"