百度地图 tpov 插件

一键将百度地图显示的公交线路导入 tpov_extract 脚本

  1. // ==UserScript==
  2. // @name 百度地图 tpov 插件
  3. // @namespace Violentmonkey Scripts
  4. // @match *://map.baidu.com/*
  5. // @match *://maps.baidu.com/*
  6. // @grant none
  7. // @version 1.0
  8. // @author CyrilSLi
  9. // @description 一键将百度地图显示的公交线路导入 tpov_extract 脚本
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. const tpovBtnId = "tpovExportBtn";
  14. const tpovBtn = document.createElement("div");
  15. tpovBtn.id = tpovBtnId;
  16. tpovBtn.style.display = "inline-block";
  17. tpovBtn.style.float = "left";
  18. tpovBtn.innerHTML = `
  19. <a class="ui3-city-change-inner" style="padding: 0px 12px !important; color: black !important; font-weight: bold !important;">tpov 导出</a>
  20. `;
  21. tpovBtn.addEventListener("click", (ev) => {
  22. const params = new URLSearchParams(window.location.search);
  23. const tpovExport = `python tpov_extract.py baidu tpov-${params.get("sug_forward")}-${params.get("wd2")}-${SECKEY} baidu_extract.json`;
  24. navigator.clipboard.writeText(tpovExport);
  25. alert("以拷贝 " + tpovExport);
  26. });
  27.  
  28. const observer = new MutationObserver((muts) => {
  29. const params = new URLSearchParams(window.location.search);
  30. if (params.has("wd2") && params.has("sug_forward")) {
  31. const ctrlWrap = document.getElementById("ui3_control_wrap");
  32. if (ctrlWrap && !ctrlWrap.contains(tpovBtn)) {
  33. const cityBtn = document.getElementById("ui3_city_change");
  34. cityBtn.parentNode.insertBefore(tpovBtn, cityBtn.nextSibling);
  35. }
  36. } else {
  37. tpovBtn.remove();
  38. }
  39. });
  40.  
  41. observer.observe(document.body, {
  42. attributes: false,
  43. childList: true,
  44. characterData: false,
  45. subtree:true
  46. });