Skip to content

Instantly share code, notes, and snippets.

@kabili207
Created August 29, 2022 02:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kabili207/7c0a3eeb9d33523b99a4adc95b312300 to your computer and use it in GitHub Desktop.
Save kabili207/7c0a3eeb9d33523b99a4adc95b312300 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name AO3 Bookmarking Records
// @namespace Bairdel AO3 Bookmarking Records
// @description To keep track of bookmarks. Automatically adds on the current date and most recent chapter of the fic you are reading into the bookmark notes. Used for keeping track of when you last read a fic, and what chapter you were on.
// @version 0.2
// @author Bairdel
// @include http*://archiveofourown.org/works*
// @include http*://www.archiveofourown.org/*works*
// @license GNU GPLv3
// ==/UserScript==
(function() {
const divider = "Last Read: "; // the bit at the start of the automatically added text
// automatically checks the Private Bookmark checkbox. Set to false if you don't want this.
document.getElementById("bookmark_private").checked = false;
// keeps any bookmark notes you've made previously. Must be above the "Last Read: ".
// this updates the date you last read the fic each time.
var bookmarkNotes = (document.getElementById("bookmark_notes").innerHTML).split(divider)[0];
////////////////////////// customisations /////////////////////////////////
// get the current date. should be in local time. you could add HH:MM if you wanted.
var currdate = new Date();
var dd = String(currdate.getDate()).padStart(2, '0');
var mm = String(currdate.getMonth() + 1).padStart(2, '0'); //January is 0
var yyyy = currdate.getFullYear();
// change to preferred date format
var date = yyyy + '/' + mm + '/' + dd;
// gets the current chapter count. remove the split("/") to keep the /?.
var lastChapter = document.getElementsByClassName("chapters")[1].innerHTML.split("/")[0];
var title = document.getElementsByClassName("title heading")[0].innerHTML.trim(); // fic name
var author = document.querySelectorAll('[rel="author"]')[0].innerHTML.trim(); // fic author
var words = document.getElementsByClassName("words")[1].innerHTML; // fic wordcount
// status i.e. Completed: 2020-08-23, Updated: 2022-05-08, Published: 2015-06-29
var status;
if (document.getElementsByClassName("status").length != 0) {
// for multichapters
status = document.getElementsByClassName("status")[0].innerHTML + " " + document.getElementsByClassName("status")[1].innerHTML;
} else{
// for single chapter fics
status = document.getElementsByClassName("published")[0].innerHTML + " " + document.getElementsByClassName("published")[1].innerHTML;
}
////////////////////////////////////////////////////////////////////
// puts it all together. feel free to change this format to whatever you like.
// first part must always be the divider or a new date will be added each time.
// <br> puts the next text on a new line
bookmarkNotes = bookmarkNotes + "<br>Last Read: " + date + "<br>Chapter " + lastChapter;
//examples
// bookmarkNotes = bookmarkNotes + "<br>Last Read: " + date + "<br>Chapter " + lastChapter + "<br><br>" + title + " by " + author;
// bookmarkNotes = bookmarkNotes + "<br>Last Read: " + date + "<br>Chapter " + lastChapter + "<br><br>" + title + " by " + author + "<br>" + status;
// fills in the bookmark notes box.
document.getElementById("bookmark_notes").innerHTML = bookmarkNotes;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment