Rllmuk Put Edit Link Under Your Own Posts

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

目前为 2021-07-17 提交的版本。查看 最新版本

  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 4
  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"], a[href$="&do=edit"]')
  29. console.log({$quoteLink, $editLink})
  30. $quoteLink.replaceWith($editLink.cloneNode(true))
  31. }
  32.  
  33. function processPosts(context = document) {
  34. context.querySelectorAll(POST_SELECTOR).forEach(processPost)
  35. }
  36.  
  37. // Process initial posts
  38. processPosts()
  39.  
  40. // Watch for posts being replaced when paging
  41. new MutationObserver(mutations =>
  42. mutations.forEach(mutation => {
  43. if (mutation.oldValue == 'true') {
  44. processPosts()
  45. }
  46. })
  47. ).observe(document.querySelector('div.cTopic'), {
  48. attributes: true,
  49. attributeFilter: ['animating'],
  50. attributeOldValue: true,
  51. })
  52.  
  53. // Watch for new posts being loaded into the current page
  54. new MutationObserver(mutations => {
  55. mutations.forEach(mutation =>
  56. mutation.addedNodes.forEach($addedNode => {
  57. if ($addedNode.matches(POST_SELECTOR)) {
  58. processPost($addedNode)
  59. }
  60. })
  61. )
  62. }).observe(document.querySelector('#elPostFeed > form'), {
  63. childList: true,
  64. })
  65. }()