Rllmuk Put Edit Link Under Your Own Posts

Replace the Quote link under your own posts with an Edit link

当前为 2021-03-31 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Rllmuk Put Edit Link Under Your Own Posts
// @description Replace the Quote link under your own posts with an Edit link
// @namespace   https://github.com/insin/greasemonkey/
// @version     3
// @match       https://rllmukforum.com/index.php?/topic/*
// @match       https://www.rllmukforum.com/index.php?/topic/*
// ==/UserScript==

void function TopicPage() {
  let $loggedInUserLink = document.querySelector('#elUserNav a.ipsUserPhoto')
  if (!$loggedInUserLink) {
    return
  }

  const POST_SELECTOR = 'article.ipsComment'
  const USER_ID_RE = /profile\/(\d+)/

  let currentUserId = USER_ID_RE.exec($loggedInUserLink.href)[1]

  function processPost($post) {
    let $userLink = $post.querySelector('.cAuthorPane_author a')
    let userId = USER_ID_RE.exec($userLink.href)[1]
    if (userId !== currentUserId) {
      return
    }
    let $quoteLink = $post.querySelector('a[data-action="quoteComment"]')
    let $editLink = $post.querySelector('a[data-action="editComment"]')
    $quoteLink.replaceWith($editLink.cloneNode(true))
  }

  function processPosts(context = document) {
    context.querySelectorAll(POST_SELECTOR).forEach(processPost)
  }

  // Process initial posts
  processPosts()

  // Watch for posts being replaced when paging
  new MutationObserver(mutations =>
    mutations.forEach(mutation => {
      if (mutation.oldValue == 'true') {
        processPosts()
      }
    })
  ).observe(document.querySelector('div.cTopic'), {
    attributes: true,
    attributeFilter: ['animating'],
    attributeOldValue: true,
  })

  // Watch for new posts being loaded into the current page
  new MutationObserver(mutations => {
    mutations.forEach(mutation =>
      mutation.addedNodes.forEach($addedNode => {
        if ($addedNode.matches(POST_SELECTOR)) {
          processPost($addedNode)
        }
      })
    )
  }).observe(document.querySelector('#elPostFeed > form'), {
    childList: true,
  })
}()