SH Permalinks for Comments

Convert the timestamps on ScribbleHub chapter comments into permalinks to make sharing comments easier.

目前为 2020-08-16 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name SH Permalinks for Comments
  3. // @namespace ultrabenosaurus.ScribbleHub
  4. // @version 0.2
  5. // @description Convert the timestamps on ScribbleHub chapter comments into permalinks to make sharing comments easier.
  6. // @author Ultrabenosaurus
  7. // @source https://greasyfork.org/en/users/437117-ultrabenosaurus?sort=name
  8. // @match https://www.scribblehub.com/read/*/chapter/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. var SHcomments = document.querySelectorAll('div#comments div.comment_list_main li[id^="comment-"][class^="cmt_li_chp"]');
  16. if( SHcomments.length > 0 ) {
  17. UBaddCommentPermalinks(SHcomments);
  18. }
  19. SHcomments = null;
  20.  
  21. var SHcommentPagination = document.querySelectorAll('div[class*="comments-pagination"] ul#pagination-mesh li:not(.active) a.page-link');
  22. if( SHcommentPagination.length > 0 ) {
  23. UBaddPaginationEvents(SHcommentPagination);
  24. }
  25. SHcommentPagination = null;
  26. })();
  27.  
  28. function UBaddCommentPermalinks(SHcomments) {
  29. var permalinkTemplate = "<a class='com_date' title='%timestamp%' href='%perma%'>%when%</a>";
  30.  
  31. for (var comm in SHcomments) {
  32. if (SHcomments.hasOwnProperty(comm)) {
  33. var commID = SHcomments[comm].id.split('-')[1];
  34. var commDate = SHcomments[comm].querySelectorAll('div.comment-author.chapter span.com_date')[0];
  35.  
  36. var commTimestamp = commDate.title;
  37. var commWhen = commDate.textContent;
  38. var commLink = permalinkTemplate.replace("%perma%", "#comment-"+commID).replace("%timestamp%", commTimestamp).replace("%when%", commWhen);
  39.  
  40. commDate.insertAdjacentHTML("beforebegin", commLink);
  41. commDate.remove();
  42.  
  43. commID = commDate = commTimestamp = commWhen = commLink = null;
  44. }
  45. }
  46. SHcomments = permalinkTemplate = comm = null;
  47. }
  48.  
  49. function UBaddPaginationEvents(SHcommentPagination) {
  50. for (var pag in SHcommentPagination) {
  51. if (SHcommentPagination.hasOwnProperty(pag)) {
  52. SHcommentPagination[pag].addEventListener("click", UBpaginationEvent, false);
  53. }
  54. }
  55. SHcommentPagination = pag = null;
  56. }
  57.  
  58. function UBpaginationEvent() {
  59. setTimeout(function(){
  60. UBaddCommentPermalinks( document.querySelectorAll('div#comments div.comment_list_main li[id^="comment-"][class^="cmt_li_chp"]') );
  61. UBaddPaginationEvents( document.querySelectorAll('div[class*="comments-pagination"] ul#pagination-mesh li:not(.active) a.page-link') );
  62. }, 1000);
  63. }