AO3: Display what chapter a comment is on in inbox

In the AO3 inbox, display what chapter a comment is on

  1. // ==UserScript==
  2. // @name AO3: Display what chapter a comment is on in inbox
  3. // @version 2024-04-20
  4. // @description In the AO3 inbox, display what chapter a comment is on
  5. // @author ceiaOfSilence
  6. // @license MIT
  7. // @match https://archiveofourown.org/users/*/inbox*
  8. // @run-at document-idle
  9. // @namespace https://greasyfork.org/users/1291350
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. jQuery(('.heading.byline')).each(function () {
  16. var commentHeader = this;
  17. var url = jQuery(this).find("a[href^='/works']").attr('href');
  18. url = "https://archiveofourown.org" + url;
  19.  
  20. jQuery.get(url, function(response) {
  21. var chapterNumberContainer = jQuery(response).find('span.parent').first();
  22. if (chapterNumberContainer.length > 0) {
  23. var chapterNumber = chapterNumberContainer.text().trim().match(/\d+/)[0];
  24. }
  25. else {
  26. chapterNumber = "1";
  27. }
  28. var chapter = document.createElement('span');
  29. chapter.className = 'parent';
  30. chapter.innerText = `at Chapter ${chapterNumber}`;
  31. jQuery(commentHeader).append(chapter);
  32. }).fail(function () {
  33. console.log('failed to retrieve chapter number');
  34. });
  35. })
  36. })();