Artex / Find Artists

// ==UserScript==
// @name        Find Artists
// @namespace   Artex
// @description Find artists your not watching from your favorites.
// @include     https://www.furaffinity.net/watchlist/by/*
// @include     http://www.furaffinity.net/watchlist/by/*
// @version     1
// @grant       none
// ==/UserScript==



function getWatching() {
	var list = {};
	var artists = document.getElementsByClassName("artist_name");
	for (i = 0; i < artists.length; i ++) {
			list[artists[i].textContent.toLowerCase().replace("_","")] = true;
	}
	return list;
	//TODO: handle multiple pages (required if watching 1k+ artists)
}

function findArtistsNotWatched(file, callback) {
	var watching = getWatching();
	var notWatching = {};
	var read = new FileReader();
	read.onload = function(e) {
		var text = e.target.result;
		var submissions = JSON.parse(text);
		for (var s in submissions) {
			var artist = submissions[s].artist;
			if (!watching[artist]) {
				notWatching[artist] = true;
			}
		}
		callback(notWatching);
	}
	read.readAsText(file);
}

function makeArtistList(artists) {
	var container = document.createElement("div");
	container.style.width = "500px";
	container.style.margin = "0 auto";
	document.body.insertBefore(container, document.body.firstChild);
	
	for (var artist in artists) {
		var a = document.createElement("a");
		a.href =  "/user/" + artist;
		a.style.display = "inline-block";
		a.style.width = "250px";

		var img = document.createElement("img");
		img.src = "https://a.facdn.net/"+artist+".gif";
		a.appendChild(img);

		var text = document.createElement("span");
		text.textContent = artist;
		a.appendChild(text);

		container.appendChild(a);
	}
}

function initialize() {
	var fileInput = document.createElement("input");
	fileInput.setAttribute("type", "file");
	document.body.insertBefore(fileInput, document.body.firstChild);
	fileInput.addEventListener("change", function() {
		findArtistsNotWatched(this.files[0], function(artists) {
      makeArtistList(artists);
		});
	});
}

initialize();