AO3 Collection Exchange Assignment Notes

Free text notes next to each assignment

  1. // ==UserScript==
  2. // @name AO3 Collection Exchange Assignment Notes
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Free text notes next to each assignment
  6. // @author exuvia
  7. // @match https://archiveofourown.org/collections/*/assignments?unfulfilled=true*
  8. // @match https://archiveofourown.org/collections/*/assignments?fulfilled=true*
  9. // @match https://archiveofourown.org/collections/*/assignments?pinch_hit=true*
  10. // @match https://archiveofourown.org/collections/*/assignments*
  11. // @icon http://archiveofourown.org/favicon.ico
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function() {
  16.  
  17. /*
  18. This assumes all gifter-recip pairs are unique. So "A for B" would never appear more than once, and "A for B" could be used to uniquely identify an assignment.
  19. */
  20.  
  21. const settings = {//change these: true for on, false for off
  22. notes : true, //notes are saved in localStorage, which goes away on incognito sessions
  23. doubleAssignFlag : true, //not implemented
  24. hideOption : true //not implemented
  25. };
  26.  
  27. window.saveName = "AO3CollectionAssignmentNotes" + window.location.href.match(/collections\/(.+)\/assignments/)[1];
  28.  
  29. window.saveData = {};
  30.  
  31. window.exportSave = () => { //To export save, enter exportSave() into console
  32. window.localStorage[window.saveName];
  33. }
  34.  
  35. window.importSave = (save) => {//To import save, enter importSave(save export) into console
  36. window.localStorage[window.saveName] = save;
  37. location.reload(true)
  38. }
  39.  
  40.  
  41. if (window.localStorage[window.saveName] !== undefined) window.saveData = JSON.parse(window.localStorage[window.saveName]);
  42.  
  43.  
  44. const exportNotes = () => JSON.parse(window.localStorage[window.saveName]);
  45.  
  46. const createTextbox = (id, writer, recip) => { //creates note box to write in
  47. let textbox = document.createElement("INPUT");
  48. textbox.setAttribute("type", "text");
  49. textbox.style.width = "50%";
  50. textbox.style.float = "right";
  51. textbox.oninput = () => {
  52. window.saveData[id] = {
  53. writer : writer,
  54. recip : recip,
  55. notes : textbox.value
  56. }
  57. // console.log("Updated!")
  58. window.localStorage[window.saveName] = JSON.stringify(window.saveData);
  59. }
  60. if (window.saveData[id] !== undefined) textbox.value = window.saveData[id].notes;
  61. return textbox;
  62. }
  63.  
  64. if (settings.notes === true){
  65.  
  66. if (window.location.href.includes("unfulfilled=true")){//Assignments: Open
  67. Array.from(document.getElementsByClassName("creator")).forEach(details => {
  68. let writer = details.childNodes[2].nodeValue.trim();
  69. let recip = details.getElementsByClassName("recipient")[0].innerText.replace("for ","").trim();
  70. let id = writer + recip;
  71. details.appendChild(createTextbox(id,writer,recip));
  72. })
  73. }
  74.  
  75. else if (window.location.href.includes("fulfilled=true")){//Assignments: Complete
  76. Array.from(document.getElementsByClassName("index group")).forEach(item => {
  77. let writer = item.children[0].childNodes[0].nodeValue.trim();
  78. let recip = item.querySelectorAll("[href*='assignments']")[0].innerText.trim();
  79. let id = writer + recip;
  80. item.children[0].appendChild(createTextbox(id,writer,recip));
  81. })
  82. }
  83.  
  84. else if (window.location.href.includes("pinch_hit=true")){//Assignments: Pinch Hits
  85. Array.from(document.getElementsByClassName("creator")).forEach(details => {
  86. let writer = details.childNodes[2].nodeValue.trim();
  87. let recip = details.getElementsByClassName("recipient")[0].innerText.replace("for ","").trim();
  88. let id = writer + recip;
  89. details.appendChild(createTextbox(id,writer,recip));
  90. })
  91. }
  92.  
  93. else{//Assignments: Defaulted
  94. Array.from(document.getElementsByClassName("assignment")).forEach(item => {
  95. let recip = item.children[0].innerText.trim()
  96. let writer = item.nextElementSibling.children[0].innerText.replace("Undefault ","").trim()
  97. let id = writer + recip;
  98. item.nextElementSibling.appendChild(createTextbox(id,writer,recip));
  99. })
  100. }
  101.  
  102.  
  103. }
  104.  
  105.  
  106. })();