-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuserlist_tampermonkey.js
46 lines (43 loc) · 1.83 KB
/
userlist_tampermonkey.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// ==UserScript==
// @name Weebpocalypse list linking
// @namespace jwfiredragon
// @version 1.1
// @description Allows linking user anime lists in Weebpocalypse
// @author jwfiredragon
// @match https://jwfiredragon.github.io/weebpocalypse/
// @grant GM_xmlhttpRequest
// @grant unsafeWindow
// ==/UserScript==
var description = document.getElementById("description");
description.innerHTML = '<p>Currently using: Default list</p>';
var username = prompt("Enter your MAL username, or leave blank to use the default list:", "");
if(username != "" && username != null) {
GM_xmlhttpRequest({
method: "GET",
url: `https://api.myanimelist.net/v2/users/${username}/animelist?status=completed&limit=1000&fields=alternative_titles`,
headers: {
"X-MAL-CLIENT-ID": "865edc428f4197b494945019f50eb1b5"
},
onload: function(response) {
if(response.readyState === 4 && response.status === 200) {
var animes = JSON.parse(response.responseText);
var u_anime_list = [];
Object.values(animes.data).forEach(val => {
var title = val.node.title;
var title_en = val.node.alternative_titles.en;
if(title_en === title || title_en === "") {
u_anime_list.push(title.replace("\"", "'"));
}
else {
u_anime_list.push((`${title} / ${title_en}`).replace("\"", "'"));
}
});
unsafeWindow.anime_list = u_anime_list;
description.innerHTML = `<p>Currently using: ${username}'s list</p>`;
}
else {
alert(`Error: ${response.status} ${response.statusText}`);
}
}
});
}