您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Merge seemingly incomplete paragraphs with the one to its next.
当前为
// ==UserScript== // @name Fix Broken Paragraphs // @namespace http://tampermonkey.net/ // @version 3 // @description Merge seemingly incomplete paragraphs with the one to its next. // @match *://ranobes.top/* // @icon https://www.google.com/s2/favicons?sz=64&domain=ranobes.top // @license MIT // @grant none // ==/UserScript== (function () { 'use strict'; function ellipsize(s) { return s.substring(0, 24).trim().replace(/[^\w\s\d]+$/, "") + "..."; } let section = document.querySelector(".story #arrticle"); if (!section) { return; } function log(text) { console.log(`Fix Broken Paragraphs: ${text}`); } let is_broken = false; let nodes = Array.from(section.querySelectorAll("p")); // `nodes` contain `p` and `#text` nodes. // Every ranobes chapter content section has a paragraph not in a `p` node but as a `#text` node. // As of 12-2024. section.childNodes.forEach(child => { if (child.nodeType === Node.TEXT_NODE) { nodes.push(child); } }) for (let i = 0; i < nodes.length; i++) { const node = nodes[i]; const text = node.textContent.trim(); // Consider those below this length as heading if (node && text.length > 32 && !/([?!.](|\s*["\)])|[\*\>\-}\]])$/.test(text)) { const nextNode = nodes[i + 1]; if (nextNode) { log(`\`${ellipsize(node.textContent)}\` seems broken; merging with \`${ellipsize(nextNode.textContent)}\``); const nextText = nextNode.textContent.trim(); node.textContent += ' ' + nextText.charAt(0).toLowerCase() + nextText.slice(1); nextNode.remove(); nodes.splice(i + 1, 1); i--; is_broken = true; } } } if (!is_broken) { log("There's nothing to fix..."); } })();