Skip to content

Instantly share code, notes, and snippets.

@iamliuzy
Last active June 27, 2025 12:47
Show Gist options
  • Save iamliuzy/f47f006e49302a01835cbb26c9855a6b to your computer and use it in GitHub Desktop.
Save iamliuzy/f47f006e49302a01835cbb26c9855a6b to your computer and use it in GitHub Desktop.
Amap static route steps generator (Tanpermonkey script) (Chinese only, currently no I18N)
// ==UserScript==
// @name StaticNav
// @namespace http://iamliuzy.github.io
// @version 0.1
// @description
// @author iamliuzy
// @match https://www.amap.com/dir*
// @icon https://www.google.com/s2/favicons?sz=64&domain=amap.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
window.onload = function() {
var getRouteBtn = document.getElementById("layerbox_item")
.getElementsByClassName("show-list")[0]
.appendChild(document.createElement("button"));
getRouteBtn.setAttribute("onclick", "javascript:void(0)");
getRouteBtn.innerText = "提取路线信息";
getRouteBtn.setAttribute("id", "getRouteBtn");
document.getElementById("getRouteBtn").onclick = function() {
var box = document.getElementById("planlist_wrap");
console.log("---------");
console.log(box);
var detailedPlans = box.getElementsByTagName("dl");
var planSteps = document.createElement("div");
planSteps.setAttribute("id", "planSteps");
for (var i = 0; i < detailedPlans.length; i++) {
var plan = detailedPlans[i];
if (plan.style.display === "block") {
planSteps.innerHTML = plan.innerHTML;
for (var j = 0; j < planSteps.children.length; j++) {
var step = planSteps.children[j];
if (step.tagName === "DT" && step.classList.contains("route")) {
step.remove();
}
}
break;
}
}
console.log(planSteps.innerHTML);
if (planSteps.innerHTML === "") {
alert("请先在左侧路线中选择一个展开,再点击按钮。");
return;
}
let nw = window.open("", "路线信息", "title='路线信息'");
nw.document.body.innerHTML = planSteps.innerHTML;
var style = nw.document.createElement("style");
style.innerHTML = `
@media (prefers-color-scheme: dark) {
body {
background-color: #121212;
color: #ffffff;
}
dt {
color: #fefefe;
}
dd {
color: #b0b0b0;
}
button {
background-color: #333333;
color: #ffffff;
}
}
`;
nw.document.head.appendChild(style);
nw.document.title = "路线信息";
var exportFileBtn = nw.document.createElement("button");
exportFileBtn.innerText = "导出为 HTML 文件";
exportFileBtn.onclick = function() {
var blob = new Blob([nw.document.documentElement.innerHTML], {type: "text/html"});
var url = URL.createObjectURL(blob);
var a = nw.document.createElement("a");
a.href = url;
a.download = "route_info.html";
a.click();
URL.revokeObjectURL(url);
};
nw.document.body.appendChild(exportFileBtn);
};
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment