on master help sign in
There we go
3247f77Devine Lu Linvega
scripts/portal.js+26−12
@@ -1,36 +1,45 @@
1function Portal(sites)
1function Portal(sites)
2{
2{
3− this.el = document.createElement("div");
3+ this.el = document.createElement("pre");
4 this.sites = sites;
4 this.sites = sites;
5
5
6 this.install = function()
6 this.install = function()
7 {
7 {
8− document.body.appendChild(this.el)
8+ document.body.appendChild(this.el);
9 }
9 }
10
10
11 this.start = function()
11 this.start = function()
12 {
12 {
13+ this.install();
13− if(window.location.hash){
14+ this.el.innerHTML = window.location.hash ? this.redirect() : this.directory();
14− this.redirect();
15− return;
16− }
17−
18− this.directory();
19 }
15 }
20
16
21 this.directory = function()
17 this.directory = function()
22 {
18 {
19+ var html = ""
20+
21+ for(id in this.sites){
22+ var site = this.sites[id]
23+ html += `${id}) <a href='${site}'>${site}</a>\n`
24+ }
25+ html += `\n<a href='#random' onClick="window.location.reload()">Random</a> | <a href='https://github.com/XXIIVV/webring'>Information</a>`
26+
23− return "hello"
27+ return html
24 }
28 }
25
29
26 this.location = function()
30 this.location = function()
27 {
31 {
28− return "hello"
32+ return window.location.hash.replace("#","").trim();
29 }
33 }
30
34
31 this.locate = function()
35 this.locate = function()
32 {
36 {
33− var hash = window.location.hash.replace("#","").trim();
37+ var hash = this.location();
38+
39+ if(hash == "random"){
40+ return Math.floor(Math.random()*this.sites.length)
41+ }
42+
34 for(var id in this.sites){
43 for(var id in this.sites){
35 var site = this.sites[id];
44 var site = this.sites[id];
36 if(site.indexOf(hash) >-1){
45 if(site.indexOf(hash) >-1){
@@ -49,7 +58,12 @@ function Portal(sites)
49 {
58 {
50 var location = this.locate();
59 var location = this.locate();
51 var target = this.next(location);
60 var target = this.next(location);
61+
62+ var html = ""
52
63
53− console.log(location,target)
64+ html = `Redirecting to ${target}
65+ <meta http-equiv="refresh" content="30; url=${target}">
66+<a href='' onClick="window.location.reload()">Directory</a> | <a href='#${target}' onClick="window.location.reload()">Skip</a> | <a href='#random' onClick="window.location.reload()">Random</a> | <a href='https://github.com/XXIIVV/webring'>Information</a>`
67+ return html
54 }
68 }
55}
69}