临时写的,没怎么测试过,你试一下看看有没有问题:
// ==UserScript==
// @name 百度地图自定义标记
// @description 允许修改百度地图的标记名称
// @namespace Sency
// @author Sency
// @version 1.0
// @match https://map.baidu.com/*
// @grant none
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
const platform = document.querySelector('#platform');
if (platform) {
const mutationObserver = window.MutationObserver || window.WebkitMutationObserver || window.MozMutationObserver;
const observer = new mutationObserver(mutations => {
for (let mutation of mutations) {
for (let node of mutation.addedNodes) {
if (node.className === 'BMap_bubble_pop') {
const titleInput = node.querySelector('#us_infoWnd_title');
if (titleInput) titleInput.disabled = false;
const ctrl = node.querySelector('#userSignCtrl>.ctrl');
const title = node.querySelector('.iw_poi_title');
if (ctrl && title && title.children.length) {
const edit = document.createElement('span');
edit.innerHTML = '<b style="background-position: -75px -136px;" title="修改名称"></b>';
edit.onclick = function() {
if (window.MapSignInst && window.MapSignInst.cinfo) {
const index = window.MapSignInst.cinfo.searchInfoWindow.content.index;
const info = window.MapSignInst.cinfo.arg.callee.mapSign.pointInfo.list[index];
const newTitle = prompt("输入名称:", info.title);
if (newTitle) {
info.title = newTitle;
title.title = newTitle;
title.children[1].innerText = newTitle;
}
}
};
ctrl.insertBefore(edit, ctrl.children[0]);
}
}
}
}
});
observer.observe(platform, {childList: true, subtree: true});
}
})();