Enhanced 5ch reply link

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

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

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

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

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

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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()

}())