// ==UserScript== // @name 网页标题修正为文章/章节标题 // @namespace https://viayoo.com/p0krg2 // @version 1.2.1 // @description 将网页标题修正为文章/章节标题,适用于小说、新闻、博客等内容页面 // @author DeepSeek & Grok // @license MIT // @match *://*/* // @run-at document-end // @grant none // ==/UserScript== (function() { 'use strict'; function updateTitle() { // ==================== 章节标题选择器(按优先级排列)==================== const selectors = [ // 最高优先级:特定ID选择器 '#r-nav-chapter-title', 'h1#artibodyTitle', 'h1#chaptertitle', '#chapter_title', '#chaptername', '#chapterTitle', '#novel_title', '#book-title', '#title', '#chapterName', '#BookTitle', '#nr_title', '#lbChapterName', '#chapter_name', '#ch_title', '#read_title', '#bookname', '#novelname', '#titletext', '#chapternamebox', '#chapterNameBox', '#readTitle', '#article-title', '#post-title', '#entry-title', '#page-title', // 次高优先级:特定结构下的h1 'article h1', 'section h1', 'header h1', '.article-header h1', '.post-header h1', '.content-header h1', '.blog-post h1', '.forum-thread h1', '.thread-header h1', '.novel-chapter h1', '.txt h1', '[class*="content"] h1', '[contenteditable="true"] h1', // 中等优先级:特定类名的h1 'h1.m-art-title', 'h1.bookname', 'h1.headline', 'h1.page-d-name', 'h1.title', 'h1.post-title', 'h1.entry-title', 'h1.article-title', 'h1.chapter-title', // 中等优先级:特定类名 '.chapter-title', '.chapter_name', '.book-title', '.read-title', '.read_title', '.m-art-title', '.post-title', '.entry-title', '.style_h1', '.title_box', '.chapter_tit', '.hd_title', '.body-title', '.newstitle', '.tit', '.title', '.chapter-name', '.novel-title', '.story-title', '.chap-title', '.episode-title', '.section-title', '.book-chapter-title', '.fiction-title', '.webnovel-title', '.lightnovel-chapter', '.fanfic-chapter', '.qidian-chapter', '.jjwxc-title', '.zongheng-chapter', '.ciweimao-title', '.sfacg-chapter', '.chapter-title-en', '.episode-name', '.comic-chapter', '.manga-title', '.fanfiction-title', '.archive-title', '.work-chapter', '.series-episode', '.wattpad-chapter', '.royalroad-title', '.scribblehub-chapter', '.tapas-episode', '.webtoon-title', '.manhwa-chapter', '.novelupdates-title', '.boxnovel-chapter', '.wuxiaworld-title', '.gravitytales-chapter', '.volarenovels-title', '.lnmtl-chapter', '.md-title', '.hexo-title', '.typecho-title', '.ghost-header h1', '.medium-title', '.substack-title', '.newsletter-title', '.devto-title', '.hashnode-title', '.blogger-title', '.tumblr-post h1', '.wp-title', '.joomla-article h1', '.drupal-node-title', '.single-post-title', '.page-title', '.header-title', '.main-title', '.top-title', '.featured-title', '.intro-title', '.summary-title', '.post-heading', '.topic-title', '.question-title', '.answer-title', '.discourse-title', '.reddit-post-title', '.quora-question', '.stackoverflow-title', '.bbs-title', '.douban-topic', '.zhihu-question', '.baidu-tieba-title', '.v2ex-topic', '.nodebb-title', '.phpbb-thread', '.mybb-title', '.smf-topic', '.ipb-title', '.mobile-title', '.amp-title', '.responsive-heading', '.app-chapter', '.reader-mode-title', '.dark-mode-title', '.light-mode-title', '.fullscreen-title', '.popup-title', '.overlay-title', '.main-heading', '.primary-title', '.secondary-title', '.top-heading', '.content-title', '.body-title', '.text-title', '.large-title', '.bold-title', '.italic-title', '.underline-title', '.centered-title', '.left-title', '.right-title', '.full-width-title', // 特殊样式选择器 'h2[style="user-select: text;"]', 'h3[style="user-select: text;"]', 'h3.j_chapterName', // 属性选择器 '[itemprop="headline"]', '[itemprop="name"]', '[role="heading"]', '[data-title]', '[data-chapter-title]', '[data-role="title"]', '[data-type="chapter"]', '[data-name="title"]', '[aria-label*="title"]', // 组合选择器 'h2.title', 'h3.heading', 'h2.big.o', 'h3.post-title.entry-title', // 模糊匹配 'h1[class*="title"]', 'h1[class*="chapter"]', 'h1[class*="name"]', 'h1[class*="head"]', 'h1[id*="title"]', 'h2[class*="title"]', 'h2[id*="title"]', 'h3[class*="title"]', 'h3[id*="title"]', '[class*="title"]', '[class*="heading"]', '[class*="chapter"]', '[class*="episode"]', '[class*="section"]', '[class*="novel"]', '[class*="book"]', '[class*="story"]', '[class*="post"]', '[class*="article"]', '[id*="title"]', '[id*="chapter"]', '[id*="episode"]', '[id*="heading"]', '[class*="chapter"][class*="title"]', '[class*="title"][class*="chapter"]', // 通用元素选择器 'div.title', 'span.title', // 最低优先级:纯标签选择器 'h1', 'h2', 'h3' ]; // ===================================================================== for (const selector of selectors) { const titleElement = document.querySelector(selector); if (titleElement && titleElement.textContent.trim()) { const newTitle = titleElement.textContent.trim(); if (newTitle !== document.title) { document.title = newTitle; // console.log(`[网站标题修正] 使用选择器 "${selector}" 更新网站标题: ${newTitle}`); } return; } } // console.log('[网站标题修正] 未找到标题元素'); } updateTitle(); new MutationObserver((mutations) => { for (const mutation of mutations) { if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { updateTitle(); break; } } }).observe(document.body, { childList: true, subtree: true }); })();