AO3 Collection Exchange Assignment Notes

Free text notes next to each assignment

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         AO3 Collection Exchange Assignment Notes
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Free text notes next to each assignment
// @author       exuvia
// @match        https://archiveofourown.org/collections/*/assignments?unfulfilled=true*
// @match        https://archiveofourown.org/collections/*/assignments?fulfilled=true*
// @match        https://archiveofourown.org/collections/*/assignments?pinch_hit=true*
// @match        https://archiveofourown.org/collections/*/assignments*
// @icon         http://archiveofourown.org/favicon.ico
// @grant        none
// ==/UserScript==

(function() {

	/*
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.
	*/

	const settings = {//change these: true for on, false for off
		notes : true, //notes are saved in localStorage, which goes away on incognito sessions
		doubleAssignFlag : true, //not implemented
		hideOption : true //not implemented
	};

	window.saveName = "AO3CollectionAssignmentNotes" + window.location.href.match(/collections\/(.+)\/assignments/)[1];

	window.saveData = {};

	window.exportSave = () => { //To export save, enter exportSave() into console
		window.localStorage[window.saveName];
	}

	window.importSave = (save) => {//To import save, enter importSave(save export) into console
		window.localStorage[window.saveName] = save;
		location.reload(true)
	}


	if (window.localStorage[window.saveName] !== undefined) window.saveData = JSON.parse(window.localStorage[window.saveName]);


	const exportNotes = () => JSON.parse(window.localStorage[window.saveName]);

	const createTextbox = (id, writer, recip) => { //creates note box to write in
		let textbox = document.createElement("INPUT");
		textbox.setAttribute("type", "text");
		textbox.style.width = "50%";
		textbox.style.float = "right";
		textbox.oninput = () => {
			window.saveData[id] = {
				writer : writer,
				recip : recip,
				notes : textbox.value
			}
		//	console.log("Updated!")
			window.localStorage[window.saveName] = JSON.stringify(window.saveData);
		}
		if (window.saveData[id] !== undefined) textbox.value = window.saveData[id].notes;
		return textbox;
	}

	if (settings.notes === true){

		if (window.location.href.includes("unfulfilled=true")){//Assignments: Open
			Array.from(document.getElementsByClassName("creator")).forEach(details => {
			  let writer = details.childNodes[2].nodeValue.trim();
			  let recip = details.getElementsByClassName("recipient")[0].innerText.replace("for ","").trim();
			  let id = writer + recip;
			  details.appendChild(createTextbox(id,writer,recip));
			})
		}

		else if (window.location.href.includes("fulfilled=true")){//Assignments: Complete
			Array.from(document.getElementsByClassName("index group")).forEach(item => {
			  let writer = item.children[0].childNodes[0].nodeValue.trim();
			  let recip = item.querySelectorAll("[href*='assignments']")[0].innerText.trim();
			  let id = writer + recip;
			  item.children[0].appendChild(createTextbox(id,writer,recip));
			})
		}

		else if (window.location.href.includes("pinch_hit=true")){//Assignments: Pinch Hits
			Array.from(document.getElementsByClassName("creator")).forEach(details => {
			  let writer = details.childNodes[2].nodeValue.trim();
			  let recip = details.getElementsByClassName("recipient")[0].innerText.replace("for ","").trim();
			  let id = writer + recip;
			  details.appendChild(createTextbox(id,writer,recip));
			})
		}

		else{//Assignments: Defaulted
			Array.from(document.getElementsByClassName("assignment")).forEach(item => {
			  let recip = item.children[0].innerText.trim()
			  let writer = item.nextElementSibling.children[0].innerText.replace("Undefault ","").trim()
			  let id = writer + recip;
			  item.nextElementSibling.appendChild(createTextbox(id,writer,recip));
			})
		}


	}


})();