-
Notifications
You must be signed in to change notification settings - Fork 3
/
popup.js
76 lines (62 loc) · 2.11 KB
/
popup.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function readXml(xmlFile){
let xmlDoc;
if(typeof window.DOMParser != "undefined") {
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET",xmlFile,false);
xmlhttp.setRequestHeader("Access-Control-Allow-Origin", "https://archiveofourown.org/");
if (xmlhttp.overrideMimeType){
xmlhttp.overrideMimeType('text/xml');
}
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
}
else{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load(xmlFile);
}
return xmlDoc;
}
let xml = readXml("https://archiveofourown.org/tags/38408767/feed.atom");
var entry = xml.getElementsByTagName("entry");
const it = [];
const id = [];
const date = [];
for ( i = 0; i < entry.length; i++){
it.push(entry[i].getElementsByTagName("title")[0].firstChild.data);
id.push(entry[i].getElementsByTagName("id")[0].firstChild.data);
date.push(entry[i].getElementsByTagName("updated")[0].firstChild.data);
}
const titles = new Map();
const dates = new Map();
id.forEach((element, index) => {
titles.set(element,it[index]);
dates.set(element,new Date(date[index]));
});
const dates_sorted = new Map([...dates].sort((a, b) => a[1] - b[1]));
const id_sorted = [...dates_sorted.keys()];
function index_to_link(element){
let link;
link = "https://archiveofourown.org/works/" + element.substr(-8);
return link;
}
id_sorted.forEach((element,index) => {
var ListNode = document.querySelector('ul.Lists-new'),
liNode = document.createElement('li'),
a = document.createElement('a'),
a2 = document.createElement('a'),
i = document.createElement('i')
;
i.className = "fa-solid fa-rss Rss";
liNode.className = "List-item";
a.setAttribute('href',index_to_link(element));
a.textContent = titles.get(element);
a.className = "List-item-link";
a2.setAttribute('href','#');
a2.className = "List-item-link two";
a2.textContent = "3 days ago";
liNode.appendChild(i);
liNode.appendChild(a);
liNode.appendChild(a2);
ListNode.appendChild(liNode);
})