-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload-every-url-from-yoast-sitemap.js
91 lines (79 loc) · 2.22 KB
/
load-every-url-from-yoast-sitemap.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
class GetUrls {
constructor(url) {
this.url = url;
this.urls = [];
this.counter = 0;
this.holder = 'iframeholder';
this.addElm();
this.getUrlsBySitemaps();
setTimeout(()=> {
this.run();
}, 2000)
}
addElm()
{
let e = document.createElement('div');
e.setAttribute('id', this.holder );
document.body.append(e);
}
addIframe(url)
{
let holder = document.getElementById(this.holder);
holder.innerHTML = "";
let iframe = document.createElement('iframe');
iframe.setAttribute('src', url);
iframe.setAttribute('height', 400);
iframe.setAttribute('width', 1000);
holder.append(iframe);
window.scrollTo(holder.offsetLeft,holder.offsetTop);
}
getUrlsBySitemaps() {
this.getSitemapIndexXml(this.url);
}
getSitemapIndexXml(url){
fetch(url)
.then(response => response.text())
.then(str => (new window.DOMParser()).parseFromString(str, "text/xml"))
.then((data) => {
let locs = data.getElementsByTagName("loc");
for(var i = 0; i < locs.length; i++){
this.getSitemapXml(locs[i].innerHTML)
}
});
}
getSitemapXml(url){
fetch(url)
.then(response => response.text())
.then(str => (new window.DOMParser()).parseFromString(str, "text/xml"))
.then((data) => {
let locs = data.getElementsByTagName("loc");
for(var i = 0; i < locs.length; i++){
this.addUrl(locs[i].innerHTML)
}
});
}
addUrl(url){
if(this.urls.includes(url)) return;
this.urls.push(url)
}
getUrls() {
console.log(this.urls);
}
run() {
setTimeout(() => {
this.addIframe(this.urls[this.counter]);
this.counter++;
if(this.counter < this.urls.length) {
this.run();
}
}, 2000);
}
restart() {
this.counter = 0;
document.getElementById(this.holder).remove();
this.addElm();
this.run();
}
}
// example will start after 15 seconds
let out = new GetUrls("https://"+window.location.hostname+"/sitemap_index.xml");