遇到句号就添加换行

在网页正文中的句号后面添加</br>实现换行

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         遇到句号就添加换行
// @namespace    http://tampermonkey.net/
// @version      1.0
// @license      MIT
// @description  在网页正文中的句号后面添加</br>实现换行
// @author       阿虚同学
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Helper function to add line breaks after Chinese periods
    function addLineBreaks(node) {
        if (node.nodeType === Node.TEXT_NODE) {
            let text = node.nodeValue;
            let newText = text.replace(/。/g, '。</br>');
            let newNode = document.createElement('span');
            newNode.innerHTML = newText;
            node.parentNode.replaceChild(newNode, node);
        } else if (node.nodeType === Node.ELEMENT_NODE) {
            for (let child of node.childNodes) {
                addLineBreaks(child);
            }
        }
    }

    // Target the main content area of the webpage
    let contentArea = document.body; // You might want to target a specific element instead of the whole body

    // Apply the line breaks recursively
    addLineBreaks(contentArea);

})();