// ==UserScript== // @name Aniscripts // @namespace http://tampermonkey.net/ // @version 0.30 // @description Change stuff on Anilist.co // @author hoh // @match https://anilist.co/* // @grant none // @downloadURL none // ==/UserScript== (function(){ APIcallsUsed = 0; var APIcounter = setTimeout(function(){ APIcallsUsed = 0; },60*1000); Element.prototype.remove = function() { this.parentElement.removeChild(this); } NodeList.prototype.remove = HTMLCollection.prototype.remove = function() { for(var i = this.length - 1; i >= 0; i--) { if(this[i] && this[i].parentElement) { this[i].parentElement.removeChild(this[i]); } } } var activityCache = {};//reduce API calls var handleResponse = function(response){ return response.json().then(function(json){ return response.ok ? json : Promise.reject(json); }); }; var handleError = function(error){ //alert("Error, check console"); //fixme console.error(error); }; var url = 'https://graphql.anilist.co'; var listActivityCall = function(query,variables,callback,vars){ var handleData = function(data){ activityCache[variables.id] = data; callback(data,vars); }; var options = { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', }, body: JSON.stringify({ query: query, variables: variables }) }; if(activityCache.hasOwnProperty(variables.id)){ callback(activityCache[variables.id],vars); console.log("cache hit"); } else{ fetch(url,options).then(handleResponse).then(handleData).catch(handleError); console.log((++APIcallsUsed) + " API calls used this minute"); }; }; var enhanceNotifications = function(){ var prevLength = 0; var perform = function(){ if(document.URL != "https://anilist.co/notifications"){ return; }; var notifications = document.getElementsByClassName("notification"); var activities = []; for(var i=0;i= 1 && notifications[i].children[1].children.length && notifications[i].children[1].children[0].children.length && notifications[i].children[1].children[0].children[0].children.length && notifications[i].children[1].children[0].children[0].children[0].textContent == " liked your activity." ){ active.type = "likeActivity"; active.directLink = notifications[i].children[1].children[0].children[0].href active.text = notifications[i].children[1].children[0].children[0].innerHTML; active.textName = notifications[i].children[1].children[0].children[0].childNodes[0].textContent; active.textSpan = notifications[i].children[1].children[0].children[0].childNodes[1].textContent; active.link = notifications[i].children[1].children[0].children[0].href.match(/[0-9]+/)[0]; } else if( notifications[i].children.length >= 1 && notifications[i].children[1].children.length && notifications[i].children[1].children[0].children.length && notifications[i].children[1].children[0].children[0].children.length && notifications[i].children[1].children[0].children[0].children[0].textContent == " replied to your activity." ){ active.type = "replyActivity"; active.directLink = notifications[i].children[1].children[0].children[0].href active.text = notifications[i].children[1].children[0].children[0].innerHTML; active.textName = notifications[i].children[1].children[0].children[0].childNodes[0].textContent; active.textSpan = notifications[i].children[1].children[0].children[0].childNodes[1].textContent; active.link = notifications[i].children[1].children[0].children[0].href.match(/[0-9]+/)[0]; } else if( notifications[i].children.length >= 1 && notifications[i].children[1].children.length && notifications[i].children[1].children[0].children.length && notifications[i].children[1].children[0].children[0].children.length && notifications[i].children[1].children[0].children[0].children[0].textContent == " sent you a message." ){ active.type = "messageActivity"; active.directLink = notifications[i].children[1].children[0].children[0].href active.text = notifications[i].children[1].children[0].children[0].innerHTML; active.textName = notifications[i].children[1].children[0].children[0].childNodes[0].textContent; active.textSpan = notifications[i].children[1].children[0].children[0].childNodes[1].textContent; active.link = notifications[i].children[1].children[0].children[0].href.match(/[0-9]+/)[0]; } else if( notifications[i].children.length >= 1 && notifications[i].children[1].children.length && notifications[i].children[1].children[0].children.length && notifications[i].children[1].children[0].children[0].children.length && notifications[i].children[1].children[0].children[0].children[0].textContent == " liked your activity reply." ){ active.type = "likeReplyActivity"; active.directLink = notifications[i].children[1].children[0].children[0].href active.text = notifications[i].children[1].children[0].children[0].innerHTML; active.textName = notifications[i].children[1].children[0].children[0].childNodes[0].textContent; active.textSpan = notifications[i].children[1].children[0].children[0].childNodes[1].textContent; active.link = notifications[i].children[1].children[0].children[0].href.match(/[0-9]+/)[0]; } else if( notifications[i].children.length >= 1 && notifications[i].children[1].children.length && notifications[i].children[1].children[0].children.length && notifications[i].children[1].children[0].children[0].children.length && notifications[i].children[1].children[0].children[0].children[0].textContent == " mentioned you in their activity." ){ active.type = "mentionActivity"; active.directLink = notifications[i].children[1].children[0].children[0].href active.text = notifications[i].children[1].children[0].children[0].innerHTML; active.textName = notifications[i].children[1].children[0].children[0].childNodes[0].textContent; active.textSpan = notifications[i].children[1].children[0].children[0].childNodes[1].textContent; active.link = notifications[i].children[1].children[0].children[0].href.match(/[0-9]+/)[0]; } else if( notifications[i].children.length >= 1 && notifications[i].children[1].children.length && notifications[i].children[1].children[0].children.length >= 2 && notifications[i].children[1].children[0].children[1].textContent == " started following you." ){ active.type = "followActivity"; active.directLink = notifications[i].children[1].children[0].children[0].href active.text = notifications[i].children[1].children[0].children[0].innerHTML; active.textName = notifications[i].children[1].children[0].children[0].textContent; active.textSpan = notifications[i].children[1].children[0].children[1].textContent; } else if( notifications[i].children.length >= 1 && notifications[i].children[1].children.length && notifications[i].children[1].children[0].children.length >= 4 && notifications[i].children[1].children[0].children[3].textContent == " aired." ){ active.type = "airingActivity"; active.directLink = notifications[i].children[1].children[0].children[0].href active.text = notifications[i].children[1].children[0].innerHTML; }; if( notifications[i].children.length > 1 && notifications[i].children[1].children.length > 1 ){ active.time = notifications[i].children[1].children[1].innerHTML; } else{ active.time = document.createElement("span"); }; active.image = notifications[i].children[0].style.backgroundImage; active.href = notifications[i].children[0].href; activities.push(active); }; if(activities.length == prevLength){ console.log("nothing changed, ab"); return 0; } else{ console.log("go ahead"); prevLength = activities.length; }; var notificationsContainer = document.getElementsByClassName("notifications")[0]; if(document.getElementById("hohNotifications")){ document.getElementById("hohNotifications").remove(); }; var newContainer = document.createElement("div"); newContainer.id = "hohNotifications"; notificationsContainer.insertBefore(newContainer,notificationsContainer.firstChild); for(var i=0;i 1){ text.style.marginTop = "45px"; activities[i].textName += " +"; }; }; text.href = activities[i].directLink; var textName = document.createElement("span"); var textSpan = document.createElement("span"); textName.innerHTML = activities[i].textName; textSpan.innerHTML = activities[i].textSpan; textName.style.color = "rgb(var(--color-blue))"; text.appendChild(textName); if(activityCounter > 1){ textSpan.innerHTML = " liked your activities."; }; text.appendChild(textSpan); i += counter -1; } else if(activities[i].type == "replyActivity"){ var notNotImage = document.createElement("img"); notNotImage.classList.add(activities[i].link); notNotImage.style.height = "70px"; notNotImage.style.marginRight = "5px"; notNotImageContainer.appendChild(notNotImage); var counter = 1; while( i + counter < activities.length && activities[i + counter].type == "replyActivity" && activities[i + counter].link == activities[i].link ){ var miniImageWidth = 40; var miniImage = document.createElement("a"); miniImage.href = activities[i + counter].href; miniImage.style.backgroundImage = activities[i + counter].image; miniImage.style.height = miniImageWidth + "px"; miniImage.style.width = miniImageWidth + "px"; miniImage.style.display = "inline-block"; miniImage.style.backgroundPosition = "50%"; miniImage.style.backgroundRepeat = "no-repeat"; miniImage.style.backgroundSize = "cover"; miniImage.style.position = "absolute"; miniImage.style.marginLeft = (60 + (counter-1)*miniImageWidth) + "px"; newNotification.appendChild(miniImage); counter++; }; if(counter > 1){ text.style.marginTop = "45px"; activities[i].textName += " +"; }; text.href = activities[i].directLink; var textName = document.createElement("span"); var textSpan = document.createElement("span"); textName.innerHTML = activities[i].textName; textSpan.innerHTML = activities[i].textSpan; textName.style.color = "rgb(var(--color-blue))"; text.appendChild(textName); text.appendChild(textSpan); i += counter -1; } else if(activities[i].type == "messageActivity"){ var notNotImage = document.createElement("img"); notNotImage.classList.add(activities[i].link); notNotImage.style.height = "70px"; notNotImage.style.marginRight = "5px"; notNotImageContainer.appendChild(notNotImage); text.href = activities[i].directLink; var textName = document.createElement("span"); var textSpan = document.createElement("span"); textName.innerHTML = activities[i].textName; textSpan.innerHTML = activities[i].textSpan; textName.style.color = "rgb(var(--color-blue))"; text.appendChild(textName); text.appendChild(textSpan); } else if(activities[i].type == "likeReplyActivity"){ var notNotImage = document.createElement("img"); notNotImage.classList.add(activities[i].link); notNotImage.style.height = "70px"; notNotImage.style.marginRight = "5px"; notNotImageContainer.appendChild(notNotImage); text.href = activities[i].directLink; var textName = document.createElement("span"); var textSpan = document.createElement("span"); textName.innerHTML = activities[i].textName; textSpan.innerHTML = activities[i].textSpan; textName.style.color = "rgb(var(--color-blue))"; text.appendChild(textName); text.appendChild(textSpan); } else if(activities[i].type == "mentionActivity"){ var notNotImage = document.createElement("img"); notNotImage.classList.add(activities[i].link); notNotImage.style.height = "70px"; notNotImage.style.marginRight = "5px"; notNotImageContainer.appendChild(notNotImage); text.href = activities[i].directLink; var textName = document.createElement("span"); var textSpan = document.createElement("span"); textName.innerHTML = activities[i].textName; textSpan.innerHTML = activities[i].textSpan; textName.style.color = "rgb(var(--color-blue))"; text.appendChild(textName); text.appendChild(textSpan); } else if(activities[i].type == "airingActivity"){ text.href = activities[i].directLink; var textSpan = document.createElement("span"); textSpan.innerHTML = activities[i].text; text.appendChild(textSpan); } else if(activities[i].type == "followActivity"){ text.href = activities[i].directLink; var textName = document.createElement("span"); var textSpan = document.createElement("span"); textName.innerHTML = activities[i].textName; textSpan.innerHTML = activities[i].textSpan; textName.style.color = "rgb(var(--color-blue))"; text.appendChild(textName); text.appendChild(textSpan); }; newNotification.appendChild(notImage); newNotification.appendChild(notNotImageContainer); newNotification.appendChild(text); var time = document.createElement("div"); time.innerHTML = activities[i].time; time.style.position = "static"; time.style.float = "right"; time.style.marginRight = "20px"; time.style.marginTop = "10px"; newNotification.appendChild(time); newContainer.appendChild(newNotification); }; var pending = {}; for(var i=0;APIcallsUsed < 90;i++){//heavy if(!activities.length || i >= activities.length){ break; }; var imageCallBack = function(data,vars){ var type = data.data.Activity.type; var extra = 0; for(var j=0;j