SH Permalinks for Comments

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

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