// ==UserScript== // @name Via阅读模式标题修正 // @namespace https://viayoo.com/p0krg2 // @version 3.3 // @description 修正Via阅读模式标题识别 // @author DeepSeek & Grok // @license MIT // @match *://*/* // @run-at document-end // @grant none // ==/UserScript== (function() { 'use strict'; if (window.viaReaderTitleOptimized) return; window.viaReaderTitleOptimized = true; let lastProcessedTitle = ''; function optimizeTitle() { // ==================== 核心:章节标题选择器(扩充至150+) ==================== // 优先级排序:先精准匹配(如小说站点专属),后通用(如h1变体),再属性/模糊匹配 const selectors = [ // 1. 主流中文小说网站(起点、晋江、纵横、刺猬猫、SF等,约30个) 'h1.chapter-title', '.chapter-title', '.chapter_name', '#chapterTitle', '.book-chapter h1', '.read-content h1', '.article-title', '.chapterName', '.chapter-name', '.txt h1', '.bookname', '[class*="chapter"][class*="title"]', '[class*="title"][class*="chapter"]', '.novel-title', '.read-title', '.story-title', '.heading-title', '.chap-title', '.episode-title', '.section-title', '.book-chapter-title', '.novel-chapter h1', '.fiction-title', '.webnovel-title', '.lightnovel-chapter', '.fanfic-chapter', '.qidian-chapter', '.jjwxc-title', '.zongheng-chapter', '.ciweimao-title', '.sfacg-chapter', // 2. 国际/英文小说&漫画站点(Webtoon、AO3、Wattpad、RoyalRoad等,约20个) '.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', // 3. 博客&CMS系统(WordPress、Typecho、Hexo、Ghost、Medium等,约30个) 'h1.entry-title', '.entry-title', '.post-title', '#post-title', '.article-header h1', '.blog-post h1', '.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', '.content-header h1', '.post-header h1', '.single-post-title', '.page-title', '.header-title', '.main-title', '.top-title', '.featured-title', '.intro-title', '.summary-title', // 4. 论坛&社区(Reddit、Discourse、StackOverflow、Quora等变体,约20个) '.post-heading', '.topic-title', '.question-title', '.answer-title', '.forum-thread h1', '.discourse-title', '.reddit-post-title', '.quora-question', '.stackoverflow-title', '.thread-header h1', '.bbs-title', '.douban-topic', '.zhihu-question', '.baidu-tieba-title', '.v2ex-topic', '.nodebb-title', '.phpbb-thread', '.mybb-title', '.smf-topic', '.ipb-title', // 5. 通用高权重标题(h1/h2/h3变体,适用于大多数站点,约20个) 'h1', 'h2.title', 'h3.heading', '.title', '#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', // 6. 属性&模糊选择器(兜底,针对动态/自定义class,约30个) '[data-title]', '[data-chapter-title]', '[itemprop="headline"]', '[itemprop="name"]', '[role="heading"]', '[aria-label*="title"]', '[class*="title"]', '[class*="heading"]', '[class*="chapter"]', '[class*="episode"]', '[class*="section"]', '[class*="novel"]', '[class*="book"]', '[class*="story"]', '[class*="post"]', '[class*="article"]', '[class*="content"] h1', 'header h1', 'article h1', 'section h1', 'div.title', 'span.title', '[id*="title"]', '[id*="chapter"]', '[id*="episode"]', '[id*="heading"]', '[data-role="title"]', '[data-type="chapter"]', '[data-name="title"]', '[contenteditable="true"] h1', // 编辑器变体 // 7. 额外扩展(移动端/AMP/特殊布局,约10个,防遗漏) '.mobile-title', '.amp-title', '.responsive-heading', '.app-chapter', '.reader-mode-title', '.dark-mode-title', '.light-mode-title', '.fullscreen-title', '.popup-title', '.overlay-title' ]; // ===================================================================== let chapterTitle = ''; let usedSelector = ''; for (const selector of selectors) { const titleEl = document.querySelector(selector); if (titleEl && titleEl.textContent.trim()) { chapterTitle = titleEl.textContent.trim(); usedSelector = selector; break; } } if (!chapterTitle) return; if (chapterTitle === lastProcessedTitle) return; // console.log(`[Via章节标题修正] 使用选择器 "${usedSelector}" 找到章节标题: "${chapterTitle}"`); const setOgmMeta = (property) => { let meta = document.querySelector(`meta[property="${property}"]`); if (!meta) { meta = document.createElement('meta'); meta.setAttribute('property', property); document.head.appendChild(meta); } meta.setAttribute('content', chapterTitle); }; setOgmMeta('og:title'); setOgmMeta('twitter:title'); lastProcessedTitle = chapterTitle; // console.log('[Via阅读模式标题修正] 已设置 og:title & twitter:title 标签'); } optimizeTitle(); new MutationObserver((mutations) => { for (const mutation of mutations) { if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { optimizeTitle(); break; } } }).observe(document.body, { childList: true, subtree: true }); })();