// ==UserScript==
// @name Download Your Anime/Manga XML List On Any Page + Wayback Machine Your Profile.
// @namespace http://tampermonkey.net/
// @version 0.3
// @description This script adds 3 buttons on MAL, 1 is button added on any anime page, the other is button added on any manga page, these buttons allow you to download your Anime/Manga XML list. The last button is added only on your profile and Backups Your Profile using the Wayback Machine service.
// @author hacker09
// @match https://myanimelist.net/anime/*
// @match https://myanimelist.net/manga/*
// @match https://myanimelist.net/profile/*
// @grant none
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
var $ = window.jQuery; //Defines That The Symbol $ Is A jQuery
var username = $('a.header-profile-link')[0].innerText
//*****************************************************************************************************************************************************
if (window.location.pathname.split('/')[1] === 'anime')
{
var BackupAnimeBTN = document.createElement("a");
BackupAnimeBTN.innerHTML = "Backup My AnimeList";
document.querySelector("span.information.type").parentElement.appendChild(BackupAnimeBTN);
BackupAnimeBTN.setAttribute("id", "BackupAnimeBTN");
BackupAnimeBTN.setAttribute("style", "margin-left: 15px;font-size: 10px;");
// 1Function that will run after the mouse click was detected
function clickonanimebackupbtn (zEvent) {
document.body.innerHTML += '<form id="submit" name="submit" action="https://malscraper.azurewebsites.net/scrape" method="post"><input type="text" name="username" value="'+username+'" autofocus style="display: none;"><select name="listtype" style="display: none;"><option value="anime"></option></select><input type="checkbox" name="update_on_import" checked style="display: none;"></form>';
document.getElementById("submit").submit();
}
// 1Function that detects the mouse click on the Backup My AnimeList Button, and run the function above
document.querySelector("#BackupAnimeBTN").addEventListener ("click", clickonanimebackupbtn , false);
}
//*****************************************************************************************************************************************************
if (window.location.pathname.split('/')[1] === 'manga')
{
var BackupMangaBTN = document.createElement("a");
BackupMangaBTN.innerHTML = "Backup My MangaList";
document.querySelector("span.information.studio.author").parentElement.appendChild(BackupMangaBTN);
BackupMangaBTN.setAttribute("id", "BackupMangaBTN");
BackupMangaBTN.setAttribute("style", "margin-left: 15px;font-size: 10px;");
// 2Function that will run after the mouse click was detected
function clickonmangabackupbtn (zEvent) {
document.body.innerHTML += '<form id="submit" name="submit" action="https://malscraper.azurewebsites.net/scrape" method="post"><input type="text" name="username" value="'+username+'" autofocus style="display: none;"><select name="listtype" style="display: none;"><option value="manga"></option></select><input type="checkbox" name="update_on_import" checked style="display: none;"></form>';
document.getElementById("submit").submit();
}
// 2Function that detects the mouse click on the Backup My MangaList Button, and run the function above
document.querySelector("#BackupMangaBTN").addEventListener ("click", clickonmangabackupbtn , false);
}
//*****************************************************************************************************************************************************
if (window.location.href === 'https://myanimelist.net/profile/'+username+'')
{
var BackupProfileBTN = document.createElement("a");
BackupProfileBTN.innerHTML = "Backup My Profile";
document.querySelector("a.header-right.mt4.mr0").parentElement.appendChild(BackupProfileBTN);
BackupProfileBTN.setAttribute("id", "BackupProfileBTN");
BackupProfileBTN.setAttribute("style", "margin-left: 15px;font-size: 10px;");
// 3Function that will run after the mouse click was detected
function clickonprofilebackupbtn (zEvent) {saveprofileonarchiveorg();}
// 3Function that detects the mouse click on the Backup My Profile Button, and run the function below
document.querySelector("#BackupProfileBTN").addEventListener ("click", clickonprofilebackupbtn , false);
function saveprofileonarchiveorg (){function iFrameLoaded(id, src) {
var deferred = $.Deferred(),
iframe = $("<iframe id='iframe'></iframe>").attr({
"id": id,
"src": src
});
iframe.load(deferred.resolve);
iframe.appendTo("body");
deferred.done(function() {
console.log("iframe loaded: " + id);
});
return deferred.promise();
}
$.when(iFrameLoaded("Update MALGraph", "https://anime.plus/"+username+"/queue-add"),
iFrameLoaded("Update Badges", "https://www.mal-badges.net/users/"+username+"/update"),
iFrameLoaded("Currently Watching", "https://web.archive.org/save/https://myanimelist.net/animelist/"+username+"?status=1"),
iFrameLoaded("Completed", "https://web.archive.org/save/https://myanimelist.net/animelist/"+username+"?status=2"),
iFrameLoaded("On Hold", "https://web.archive.org/save/https://myanimelist.net/animelist/"+username+"?status=3"),
iFrameLoaded("Dropped", "https://web.archive.org/save/https://myanimelist.net/animelist/"+username+"?status=4"),
iFrameLoaded("Plan to Watch", "https://web.archive.org/save/https://myanimelist.net/animelist/"+username+"?status=6"),
iFrameLoaded("Topics in Forum Replied To", "https://web.archive.org/save/https://myanimelist.net/forum/search?u="+username+"&q=&uloc=1&loc=-1"),
iFrameLoaded("MAL History", "https://web.archive.org/save/https://myanimelist.net/history/"+username+"/anime"),
iFrameLoaded("Profile texts/statistics/Favorites/Comments and 12 Friends","https://web.archive.org/save/https://myanimelist.net/profile/"+username+"#statistics"), iFrameLoaded("Clubs","https://web.archive.org/save/https://myanimelist.net/profile/"+username+"/clubs"),
iFrameLoaded("Recommendations", "https://web.archive.org/save/https://myanimelist.net/profile/"+username+"/recommendations"),
iFrameLoaded("Reviews", "https://web.archive.org/save/https://myanimelist.net/profile/"+username+"/reviews"))
.then(function() {window.location.assign("https://google.com");
});
}}
})();