Rllmuk Put Edit Link Under Your Own Posts

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

目前为 2021-03-31 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Rllmuk Put Edit Link Under Your Own Posts
  3. // @description Replace the Quote link under your own posts with an Edit link
  4. // @namespace https://github.com/insin/greasemonkey/
  5. // @version 3
  6. // @match https://rllmukforum.com/index.php?/topic/*
  7. // @match https://www.rllmukforum.com/index.php?/topic/*
  8. // ==/UserScript==
  9.  
  10. void function TopicPage() {
  11. let $loggedInUserLink = document.querySelector('#elUserNav a.ipsUserPhoto')
  12. if (!$loggedInUserLink) {
  13. return
  14. }
  15.  
  16. const POST_SELECTOR = 'article.ipsComment'
  17. const USER_ID_RE = /profile\/(\d+)/
  18.  
  19. let currentUserId = USER_ID_RE.exec($loggedInUserLink.href)[1]
  20.  
  21. function processPost($post) {
  22. let $userLink = $post.querySelector('.cAuthorPane_author a')
  23. let userId = USER_ID_RE.exec($userLink.href)[1]
  24. if (userId !== currentUserId) {
  25. return
  26. }
  27. let $quoteLink = $post.querySelector('a[data-action="quoteComment"]')
  28. let $editLink = $post.querySelector('a[data-action="editComment"]')
  29. $quoteLink.replaceWith($editLink.cloneNode(true))
  30. }
  31.  
  32. function processPosts(context = document) {
  33. context.querySelectorAll(POST_SELECTOR).forEach(processPost)
  34. }
  35.  
  36. // Process initial posts
  37. processPosts()
  38.  
  39. // Watch for posts being replaced when paging
  40. new MutationObserver(mutations =>
  41. mutations.forEach(mutation => {
  42. if (mutation.oldValue == 'true') {
  43. processPosts()
  44. }
  45. })
  46. ).observe(document.querySelector('div.cTopic'), {
  47. attributes: true,
  48. attributeFilter: ['animating'],
  49. attributeOldValue: true,
  50. })
  51.  
  52. // Watch for new posts being loaded into the current page
  53. new MutationObserver(mutations => {
  54. mutations.forEach(mutation =>
  55. mutation.addedNodes.forEach($addedNode => {
  56. if ($addedNode.matches(POST_SELECTOR)) {
  57. processPost($addedNode)
  58. }
  59. })
  60. )
  61. }).observe(document.querySelector('#elPostFeed > form'), {
  62. childList: true,
  63. })
  64. }()