Enhanced 5ch reply link

Click reply link will jump to the reply position instead of jumping to the new page

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         Enhanced 5ch reply link
// @namespace    https://greasyfork.org/users/57176
// @match        https://*.5ch.net/*/read.cgi/**
// @icon         https://egg.5ch.net/favicon.ico
// @grant        none
// @version      1.0.2
// @author       peng-devs
// @description  Click reply link will jump to the reply position instead of jumping to the new page
// @license      MIT
// ==/UserScript==

(function() {
  'strict'

  const NAME = 'enchance-5ch-reply-link'

  function main() {
    console.log(`[${NAME}] initializing...`)

    let location = window.location.toString()
    const index = location.lastIndexOf('#')
    if (index > 0) {
      location = location.substring(0, index)
    }

    const replacer = improve_reply_link(location)
    document.querySelectorAll('.post .reply_link').forEach(replacer)

    const thread = document.querySelector('div.thread')
    if (thread) {
      new MutationObserver(list => {
        document.querySelectorAll('.post .back-links a').forEach(replacer)
      }).observe(thread, { subtree: true, childList: true })
    }

    console.log(`[${NAME}] loaded`)
  }

  function improve_reply_link(base_url) {
    return async (a) => {
      const id = a.innerText?.trim().replace('>>', '')
      if (!id) return

      a.href = `${base_url}#${id}`
      a.removeAttribute('rel')
      a.removeAttribute('target')
    }
  }

  main()

}())