Right-to-Left Paragraph Fixer

Fixes mixed-direction paragraphs on old.reddit.com by adding the dir="rtl" attribute

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Right-to-Left Paragraph Fixer
// @namespace    tampermonkey
// @version      1.0
// @description  Fixes mixed-direction paragraphs on old.reddit.com by adding the dir="rtl" attribute
// @match        https://old.reddit.com/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  // Identify paragraphs based on their text content
  const paragraphs = document.querySelectorAll('div.md');

  // Check if the paragraph contains mixed direction text patterns
  for (const paragraph of paragraphs) {
    if (
      paragraph.textContent.match(/[\u0590-\u07FF]|[\u200E-\u200F]|[\u202A-\u202E]|[\uFB51-\uFD3F]|[\uFD3F-\uFD8F]/g) &&
      paragraph.textContent.match(/[\u0000-\u007F]|\u0080-\u04FF]|[\u0500-\u058F]|[\u0700-\u07FF]|[\u0900-\u0D7F]|[\u1200-\u137F]|[\u1400-\u197F]|[\u2000-\u206F]|[\u2070-\u2BFF]|[\u2C00-\u2D7F]|[\u2E00-\u2FFF]|[\u3000-\u30FF]|[\u3400-\u4D7F]|[\u4E00-\u9FFF]|[\uA000-\uA4FF]|[\uA600-\uA9FF]|[\uAC00-\uD7FF]|[\uD800-\uDB7F]|[\uDB80-\uDBFF]|[\uDC00-\uDFFF]|[\uE000-\uE8FF]|[\uEE00-\uEEFF]|[\uEF00-\uFE0F]|[\uFE10-\uFE19]|[\uFE20-\uFE2F]|[\uFE30-\uFE4F]|[\uFE50-\uFE6F]|[\uFE70-\uFEFF]|[\uFF00-\uFFEF]/g)
    ) {
      // Add the dir="rtl" attribute to the paragraph
      paragraph.setAttribute('dir', 'rtl');
    }
  }
})();