ao3 mark for later

Adds mark for later buttons to work index pages.

  1. // ==UserScript==
  2. // @name ao3 mark for later
  3. // @description Adds mark for later buttons to work index pages.
  4. // @namespace ao3
  5. // @match http*://archiveofourown.org/*works*
  6. // @match http*://archiveofourown.org/*bookmarks*
  7. // @match http*://archiveofourown.org/series/*
  8. // @match http*://archiveofourown.org/*readings*
  9. // @match http*://archiveofourown.org/collections*
  10. // @match http*://archiveofourown.org/users/*
  11. // @exclude http*://archiveofourown.org/*readings?*show=to-read*
  12. // @grant none
  13. // @version 1.2
  14. // ==/UserScript==
  15.  
  16. (function () {
  17. const blurbs = Array.from(document.querySelectorAll('li.blurb'));
  18.  
  19. if (!blurbs.length) {
  20. return;
  21. }
  22.  
  23. const style = document.createElement('style');
  24.  
  25. style.innerHTML = `
  26. .blurb .mark {
  27. right: 0.5em;
  28. white-space: nowrap;
  29. test-align: center;
  30. clear: none;
  31. float: left;
  32. }
  33.  
  34. @media only screen and (min-width: 800px) {
  35. .blurb .mark {
  36. right: 7em;
  37. top: 0.5em;
  38. }
  39. }
  40. `;
  41.  
  42. document.head.appendChild(style);
  43.  
  44. blurbs.forEach(blurb => {
  45. let workId;
  46. let notAO3;
  47.  
  48. try {
  49. const titleLink = blurb.querySelector('.header.module .heading a');
  50. workId = (titleLink.href.match(/\/works\/(\d+)\b/) || [])[1];
  51. notAO3 = (titleLink.href.match(/archiveofourown.org/)||[]);
  52. } catch (ex) {
  53. }
  54.  
  55. if (!workId || !notAO3[0]) {
  56. console.log('[ao3 mark for later] - skipping blurb that isn\'t a work blurb: ', blurb);
  57. return;
  58. }
  59.  
  60. let section = blurb.querySelector('.actions')
  61. console.log(!section)
  62. if(!section)
  63. {
  64. section = blurb
  65. }
  66.  
  67. section.innerHTML += `
  68. <div class="mark">
  69. <ul class="actions" role="menu">
  70. <li>
  71. <a href=https://archiveofourown.org/works/${workId}/mark_for_later>Mark for Later</a>
  72. </li>
  73. </ul>
  74. </div>
  75. `;
  76. });
  77. })();