KML Title Updater

Update page title for KML pages

  1. // ==UserScript==
  2. // @name KML Title Updater
  3. // @namespace https://gf.qytechs.cn/
  4. // @version 1.0
  5. // @description Update page title for KML pages
  6. // @author Ethkuil
  7. // @match https://kml.corp.kuaishou.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function updatePageTitle() {
  16. const currentUrl = window.location.href;
  17.  
  18. // 匹配#/后的第一段
  19. const match = currentUrl.match(/#\/([^/]+)/);
  20.  
  21. if (!match) return;
  22.  
  23. const firstSegment = match[1];
  24. if (firstSegment === 'personal' || firstSegment === 'project') {
  25. // 提取页面主题信息
  26. const pageContentElement = document.evaluate(
  27. '//*[@id="__kml_page_content__"]/div[1]/div/div',
  28. document,
  29. null,
  30. XPathResult.FIRST_ORDERED_NODE_TYPE,
  31. null
  32. ).singleNodeValue;
  33. const pageContentText = pageContentElement ? pageContentElement.textContent.trim() : '';
  34.  
  35. // 自定义标题
  36. const newTitle = `:: ${pageContentText}`;
  37. document.title = newTitle;
  38. }
  39.  
  40. }
  41.  
  42. // 监听URL变化
  43. let lastUrl = window.location.href;
  44.  
  45. // 创建一个观察器来检测URL变化
  46. const observer = new MutationObserver(() => {
  47. const currentUrl = window.location.href;
  48. if (currentUrl !== lastUrl) {
  49. lastUrl = currentUrl;
  50. // 给DOM一些时间加载
  51. setTimeout(updatePageTitle, 500);
  52. }
  53. });
  54. observer.observe(document, { subtree: true, childList: true });
  55.  
  56. // 初始执行一次
  57. setTimeout(updatePageTitle, 1000);
  58. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址