on 7689ddf help sign in
webring/scripts/portal.js
69 lines 1.7 kB history raw
1function Portal(sites)
2{
3 this.el = document.createElement("pre");
4 this.sites = sites;
5
6 this.install = function()
7 {
8 document.body.appendChild(this.el);
9 }
11 this.start = function()
12 {
13 this.install();
14 this.el.innerHTML = window.location.hash ? this.redirect() : this.directory();
15 }
17 this.directory = function()
18 {
19 var html = ""
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>`
27 return html
28 }
30 this.location = function()
31 {
32 return window.location.hash.replace("#","").trim();
33 }
35 this.locate = function()
36 {
37 var hash = this.location();
39 if(hash == "random"){
40 return Math.floor(Math.random()*this.sites.length)
41 }
43 for(var id in this.sites){
44 var site = this.sites[id];
45 if(site.indexOf(hash) >-1){
46 return parseInt(id)
47 }
48 }
49 return -1
50 }
52 this.next = function(loc)
53 {
54 return loc == this.sites.length-1 ? this.sites[0] : this.sites[loc+1];
55 }
57 this.redirect = function()
58 {
59 var location = this.locate();
60 var target = this.next(location);
62 var html = ""
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
68 }