// ==UserScript==
// @name ao3 bookmark helper
// @description makes bookmarks easier
// @namespace ao3
// @match http*://archiveofourown.org/works/*
// @grant none
// @version 1.2
// @license MIT
// ==/UserScript==
(function() {
'use strict';
/*START SETTINGS: Change these to true/false based on your preferences*/
const ADD_URL_AND_USERNAME = true; // Add the title of the work and the username (and pseud if applicable) of the creator with relevant links to each to the bookmark notes.
//Note: Highly recommended as bookmark notes are not deleted when a work is deleted, and finding a lost work is easier with the title, username, and url.
const ADD_SUMMARY = true; // Add the summary of the work to the bookmark notes
const REC_DEFAULT = true; // Autocheck the Rec checkbox to make the bookmark a rec
const PRIVATE_DEFAULT = false; // Autocheck the Private checkbox to make the bookmark private
const ADD_CATEGORIES = false; // Add a copy of the relationship categories to the bookmarker tag list
const ADD_FANDOM_TAGS = true; // Add a copy of the fandom tags to the bookmarker tag list
const ADD_CHARACTER_TAGS = true; // Add a copy of the character tags to the bookmarker tag list
const ADD_RELATIONSHIP_TAGS = true; // Add a copy of the relationship tags to the bookmarker tag list
const ADD_ADDITIONAL_TAGS = true; // Add a copy of the additional/freeform tags to the bookmarker tag list
const ADD_RATING = true; // Add a copy of the rating (with "Rating: " before it) to the bookmarker tag list
const ADD_ARCHIVE_WARNINGS = true; // Add a copy of the archive warnings to the bookmarker tag list
const ADD_CUSTOM_TAGS = false; // Add set default tags to bookmarker tag list, default tags listed below
const CUSTOM_TAGS = "TBR, Example Tag, Example Tag 2"; // List of the default tags the bookmark will be given, comma seperated.
const ADD_EXACT_WORDCOUNT_TAG = false; // Add a tag with the exact word count
const ADD_WORDCOUNT_TAG = true; // Add a tag for the word count from the following set
//Word count will be split up into 7 groups, edit the list below to change the ranges (default: 1000, 10000, 20000, 50000, 100000, 150000)
//the ranges will be < the first number, first number - second number, second number - third number, etc and finally > the last number
const WORDCOUNTS = [1000, 10000, 20000, 50000, 100000, 150000];
const ADD_EXACT_WORDCOUNT_TAG_LIST = true; // Add a tag for special case word counts (ie. 100 words, 1000 words, etc) Does not have to be 3, can be any number of special cases
const EXACT_WORDCOUNT_TAG_LIST = [100, 1000, 10000]
/*END SETTINGS*/
if(ADD_URL_AND_USERNAME)
{
var url = window.location.href;
var notesBox = document.getElementById("bookmark_notes");
var title = document.getElementsByClassName("title heading");
var userName = document.getElementsByClassName("byline heading");
userName = userName[0];
title = title[0];
var x = 0;
if(notesBox)
{
if(userName.textContent.includes("("))
{
var pseud = userName.textContent.split("(");
userName = pseud[1].trim();
pseud = pseud[0].trim();
userName = userName.substring(0, userName.length-1);
notesBox.value = "<a href=\"" + url + "\">" + title.textContent.trim() + "</a> by <a href=\"/users/" + userName + "/pseuds/" + pseud + "\"> (" + pseud + ") " + userName + "</a>";
}
else
{
userName = userName.textContent.trim();
notesBox.value = "<a href=\"" + url + "\">" + title.textContent.trim() + "</a> by <a href=\"/users/" + userName + "/pseuds/" + userName + "\">" + userName + "</a>";
}
}
}
if(ADD_SUMMARY)
{
var summary = document.getElementsByClassName("summary");
summary = summary[0];
summary = summary.getElementsByClassName("userstuff");
notesBox.value = notesBox.value + "\n\nSummary: " + summary[0].textContent;
}
if(REC_DEFAULT)
{
var recBox = document.getElementById("bookmark_rec");
recBox.checked = true;
}
if(PRIVATE_DEFAULT)
{
var privateBox = document.getElementById("bookmark_private");
privateBox.checked = true;
}
var tagBox = document.getElementById("bookmark_tag_string_autocomplete");
var i = 0;
if(ADD_CATEGORIES)
{
var categorys = document.getElementsByClassName("category tags");
var categoryTags = categorys[1].getElementsByClassName("tag");
i = 0;
while(i < categoryTags.length)
{
tagBox.value = tagBox.value + ", " + categoryTags[i].textContent;
i++;
}
}
if(ADD_FANDOM_TAGS)
{
var fandoms = document.getElementsByClassName("fandom tags");
var fandomTags = fandoms[1].getElementsByClassName("tag");
i = 0;
while(i < fandomTags.length)
{
tagBox.value = tagBox.value + ", " + fandomTags[i].textContent;
i++;
}
}
if(ADD_CHARACTER_TAGS)
{
var characters = document.getElementsByClassName("character tags");
if(characters.length != 0)
{
var characterTags = characters[1].getElementsByClassName("tag");
i = 0;
while(i < characterTags.length)
{
tagBox.value = tagBox.value + ", " + characterTags[i].textContent;
i++;
}
}
}
if(ADD_RELATIONSHIP_TAGS)
{
var relationships = document.getElementsByClassName("relationship tags");
if(relationships.length != 0)
{
var relationshipTags = relationships[1].getElementsByClassName("tag");
i = 0;
while(i < relationshipTags.length)
{
tagBox.value = tagBox.value + ", " + relationshipTags[i].textContent;
i++;
}
}
}
if(ADD_ADDITIONAL_TAGS)
{
var freeforms = document.getElementsByClassName("freeform tags");
if(freeforms.length != 0)
{
var freeformTags = freeforms[1].getElementsByClassName("tag");
i = 0;
while(i < freeformTags.length)
{
tagBox.value = tagBox.value + ", " + freeformTags[i].textContent;
i++;
}
}
}
if(ADD_RATING)
{
var ratings = document.getElementsByClassName("rating tags");
var ratingTags = ratings[1].getElementsByClassName("tag");
i = 0;
while(i < ratingTags.length)
{
tagBox.value = tagBox.value + ", Rating: " + ratingTags[i].textContent;
i++;
}
}
if(ADD_ARCHIVE_WARNINGS)
{
var warnings = document.getElementsByClassName("warning tags");
var warningTags = warnings[1].getElementsByClassName("tag");
i = 0;
while(i < warningTags.length)
{
tagBox.value = tagBox.value + ", " + warningTags[i].textContent;
i++;
}
}
if(ADD_CUSTOM_TAGS)
{
tagBox.value = tagBox.value + ", " + CUSTOM_TAGS
}
var wordcount = document.getElementsByClassName("words");
wordcount = wordcount[1].textContent;
wordcount = RemoveCommas(wordcount);
if(ADD_EXACT_WORDCOUNT_TAG)
{
tagBox.value = tagBox.value + ", Word Count:" + wordcount;
}
if(ADD_WORDCOUNT_TAG)
{
if(wordcount < WORDCOUNTS[0])
{
tagBox.value = tagBox.value + ", Word Count: < " + WORDCOUNTS[0];
}
else if(wordcount >= WORDCOUNTS[0] & wordcount < WORDCOUNTS[1])
{
tagBox.value = tagBox.value + ", Word Count: " + WORDCOUNTS[0] + "-" + WORDCOUNTS[1];
}
else if(wordcount >= WORDCOUNTS[1] & wordcount < WORDCOUNTS[2])
{
tagBox.value = tagBox.value + ", Word Count: " + WORDCOUNTS[1] + "-" + WORDCOUNTS[2];
}
else if(wordcount >= WORDCOUNTS[2] & wordcount < WORDCOUNTS[3])
{
tagBox.value = tagBox.value + ", Word Count: " + WORDCOUNTS[2] + "-" + WORDCOUNTS[3];
}
else if(wordcount >= WORDCOUNTS[3] & wordcount < WORDCOUNTS[4])
{
tagBox.value = tagBox.value + ", Word Count: " + WORDCOUNTS[3] + "-" + WORDCOUNTS[4];
}
else if(wordcount >= WORDCOUNTS[4] & wordcount < WORDCOUNTS[5])
{
tagBox.value = tagBox.value + ", Word Count: " + WORDCOUNTS[4] + "-" + WORDCOUNTS[5];
}
else if(wordcount >= WORDCOUNTS[5])
{
tagBox.value = tagBox.value + ", Word Count: > " + WORDCOUNTS[4];
}
}
if(ADD_EXACT_WORDCOUNT_TAG_LIST)
{
var j = 0;
while(j < EXACT_WORDCOUNT_TAG_LIST.length)
{
if(wordcount == EXACT_WORDCOUNT_TAG_LIST[j])
{
tagBox.value = tagBox.value + ", Word Count: " + EXACT_WORDCOUNT_TAG_LIST[j];
j = EXACT_WORDCOUNT_TAG_LIST.length;
}
j++;
}
}
return ;
function RemoveCommas(wordcount)
{
if(wordcount.includes(','))
{
wordcount = wordcount.replace(',', '');
}
if(wordcount.includes(','))
{
wordcount = RemoveCommas(wordcount);
}
return wordcount;
}
}
)();