遇到句号就添加换行

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);

})();