on master help sign in
Standard
8df7857Devine Lu Linvega
scripts/portal.js+34−45
@@ -1,74 +1,63 @@
1−'use strict';
1+'use strict'
2+
3+function Portal (sites) {
4+ this.el = document.createElement('div')
5+ this.sites = sites
2
6
3−function Portal(sites)
4−{
5− this.el = document.createElement("div");
6− this.sites = sites;
7−
8 // Templates
7 // Templates
9
8
10− function _readme()
9+ function _readme () {
11− {
12 return `<p class='readme'>This webring is an attempt to inspire artists & developers to build their own website and share traffic among each other. The ring welcomes personalized websites such as <b>diaries, wikis & portfolios</b>.</p><p>To add yourself to the ring, submit a <a href='https://github.com/XXIIVV/webring/edit/master/index.html' target='_blank'>Pull Request</a>.<br />If you found a broken link, please <a href='https://github.com/XXIIVV/webring/issues/new' target='_blank'>report it</a>.</p>`
10 return `<p class='readme'>This webring is an attempt to inspire artists & developers to build their own website and share traffic among each other. The ring welcomes personalized websites such as <b>diaries, wikis & portfolios</b>.</p><p>To add yourself to the ring, submit a <a href='https://github.com/XXIIVV/webring/edit/master/index.html' target='_blank'>Pull Request</a>.<br />If you found a broken link, please <a href='https://github.com/XXIIVV/webring/issues/new' target='_blank'>report it</a>.</p>`
13 }
11 }
14
12
15− function _buttons()
13+ function _buttons () {
16− {
17 return `<p class='buttons'><a href='#random' onClick="portal.reload('random')">Random</a> | <a href='https://github.com/XXIIVV/webring'>Information</a> <a id='icon' href='#random' onClick="portal.reload('random')"></a></p>`
14 return `<p class='buttons'><a href='#random' onClick="portal.reload('random')">Random</a> | <a href='https://github.com/XXIIVV/webring'>Information</a> <a id='icon' href='#random' onClick="portal.reload('random')"></a></p>`
18 }
15 }
19
16
20− function _directory(sites)
17+ function _directory (sites) {
21− {
22 return `
18 return `
23− <ul>${sites.reduce((acc,val,id) => { return `${acc}<li>${id}) <a href='${val}'>${val.split("//")[1]}</a></li>`; },"")}</ul>\n${_readme()}${_buttons()}`
19+ <ul>${sites.reduce((acc, val, id) => { return `${acc}<li>${id}) <a href='${val}'>${val.split('//')[1]}</a></li>` }, '')}</ul>\n${_readme()}${_buttons()}`
24 }
20 }
25−
21+
26− function _redirect(target)
22+ function _redirect (target) {
27− {
28 return `<p>Redirecting to <b>${target}</b></p><meta http-equiv="refresh" content="3; url=${target}">
23 return `<p>Redirecting to <b>${target}</b></p><meta http-equiv="refresh" content="3; url=${target}">
29 <p class='buttons'><a href='#' onClick="portal.reload('')">Directory</a> | <a href='#${target}' onClick="portal.reload('random')">Skip</a> | <a href='#random' onClick="portal.reload('random')">Random</a> | <a href='https://github.com/XXIIVV/webring'>Information</a> <a id='icon' href='#random' onClick="portal.reload('random')"></a></p>`
24 <p class='buttons'><a href='#' onClick="portal.reload('')">Directory</a> | <a href='#${target}' onClick="portal.reload('random')">Skip</a> | <a href='#random' onClick="portal.reload('random')">Random</a> | <a href='https://github.com/XXIIVV/webring'>Information</a> <a id='icon' href='#random' onClick="portal.reload('random')"></a></p>`
30 }
25 }
31
26
32− //
27+ //
33
28
34− this.install = function(host)
29+ this.install = function (host) {
35− {
36− host.appendChild(this.el);
30+ host.appendChild(this.el)
37 }
31 }
38−
32+
39− this.start = function()
33+ this.start = function () {
40− {
41− this.el.innerHTML = window.location.hash && window.location.hash.length > 4 ? _redirect(this.next()) : _directory(this.sites);
34+ this.el.innerHTML = window.location.hash && window.location.hash.length > 4 ? _redirect(this.next()) : _directory(this.sites)
42 }
35 }
43
36
44− this.reload = function()
37+ this.reload = function () {
45− {
46− setTimeout(()=>{ window.location.reload() },500)
38+ setTimeout(() => { window.location.reload() }, 500)
47 }
39 }
48
40
49− this.navigate = function(target)
41+ this.navigate = function (target) {
50− {
51− setTimeout(() => { window.location.href = target; },3000)
42+ setTimeout(() => { window.location.href = target }, 3000)
52 }
43 }
53−
44+
54− this.locate = function()
45+ this.locate = function () {
55− {
56− const hash = window.location.hash.replace("#","").trim();
46+ const hash = window.location.hash.replace('#', '').trim()
57−
47+
58− if(hash == "random"){
48+ if (hash == 'random') {
59− return Math.floor(Math.random()*this.sites.length)
49+ return Math.floor(Math.random() * this.sites.length)
60 }
50 }
61−
51+
62− for(const id in this.sites){
52+ for (const id in this.sites) {
63− if(this.sites[id].indexOf(hash) >-1){
53+ if (this.sites[id].indexOf(hash) > -1) {
64 return parseInt(id)
54 return parseInt(id)
65 }
55 }
66 }
56 }
67− return -1;
57+ return -1
68 }
58 }
69−
59+
70− this.next = function(loc = this.locate())
60+ this.next = function (loc = this.locate()) {
71− {
72− return loc == this.sites.length-1 ? this.sites[0] : this.sites[loc+1];
61+ return loc == this.sites.length - 1 ? this.sites[0] : this.sites[loc + 1]
73 }
62 }
74}
63}