您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Overrides the "Show My Location" button to provide location from IP geolocation
- // ==UserScript==
- // @name OpenStreetMap IP Geolocation
- // @namespace Violentmonkey Scripts
- // @match *://www.openstreetmap.org/*
- // @grant GM.xmlhttpRequest
- // @connect ip-api.com
- // @version 1.4
- // @author CyrilSLi
- // @description Overrides the "Show My Location" button to provide location from IP geolocation
- // @license MIT
- // @require https://update.gf.qytechs.cn/scripts/533461/1574689/Get%20OpenStreetMap%20Leaflet%20object.js
- // ==/UserScript==
- window.addEventListener("load", () => {
- if (!unsafeWindow.userscriptMap) {
- return;
- }
- GM.xmlhttpRequest({
- method: "GET",
- url: "http://ip-api.com/json/",
- onload: function(response) {
- ipJSON = JSON.parse(response.responseText);
- geoButton = document.getElementsByClassName("control-locate")[0].children[0];
- geoButton.parentNode.replaceChild(geoButton.cloneNode(true), geoButton);
- tooltips = document.getElementsByClassName("tooltip-inner");
- while(tooltips[0]) {
- container = tooltips[0].parentNode;
- container.parentNode.removeChild(container);
- }
- geoButton = document.getElementsByClassName("control-locate")[0].children[0];
- geoButton.addEventListener("click", ev => {
- unsafeWindow.userscriptMap.setView([ipJSON["lat"], ipJSON["lon"]], 12);
- });
- keyButton = document.getElementsByClassName("control-legend")[0].children[0];
- keyButton.click();
- keyButton.click();
- }
- });
- });
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址