AO3: Archived Bookmarks

Tag bookmarks with 'Archived' or another chosen tag to have them automatically hidden from searches

  1. // ==UserScript==
  2. // @name AO3: Archived Bookmarks
  3. // @version 2.2
  4. // @description Tag bookmarks with 'Archived' or another chosen tag to have them automatically hidden from searches
  5. // @author sharkcat
  6. // @namespace https://github.com/sharkcatshark/Userscripts
  7. // @match *://archiveofourown.org/users/*/bookmarks
  8. // @match *://archiveofourown.org/bookmarks*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=archiveofourown.org
  10. // @license GNU GPLv3
  11. // ==/UserScript==
  12.  
  13. var archiveTag = "Archived"; // tag to use for fics you want to archive
  14. var archiveTagID = 1254691; // THIS MUST BE USER SET IF YOU CHANGE THE ABOVE // ID CAN BE FOUND HERE: &include_bookmark_search[tag_ids][]=1254691
  15.  
  16. var archiveString = "&include_bookmark_search%5Btag_ids%5D%5B%5D=" + archiveTagID;
  17. var archiveString2 = "&bookmark_search%5Bother_bookmark_tag_names%5D=" + archiveTag;
  18. var hiddenCount = 0;
  19.  
  20. // if actively searching for Archived works, do not hide
  21. if ((window.location.href.includes(archiveString)) || (window.location.href.includes(archiveString2))) {
  22. console.log("Currently searching for archived tags");
  23. }
  24. else {
  25. console.log("Not currently searching for archived tags")
  26. var bookmarks = document.querySelectorAll(".bookmark.blurb.group");
  27. bookmarks.forEach(checkForArchived);
  28. displayNumberArchived();
  29. console.log("Hidden Fic Count: " + hiddenCount);
  30. };
  31.  
  32. function checkForArchived(item) {
  33. var userTags = item.lastElementChild.querySelector(".meta.tags.commas");
  34.  
  35. if (userTags != null) { // if bookmark has user made tags
  36. var tags = userTags.getElementsByTagName("li");
  37. for (var i = 0; i < tags.length; ++i) { // loop through tags
  38. if (tags[i].innerText == archiveTag) { // if a tag matches archive tag
  39. item.style.display = "none"; // hide bookmark
  40. hiddenCount += 1;
  41. }
  42. }
  43. }
  44. };
  45.  
  46. function displayNumberArchived() {
  47. if (hiddenCount > 0) {
  48. var header = document.querySelector("h2.heading");
  49. header.innerText += " (" + hiddenCount + " Hidden)";
  50. }
  51. };