From 8df78578876d9acc99fc2dc6d9205d51eb10e344 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 4 Oct 2018 11:56:55 +1200 Subject: [PATCH] Standard --- scripts/portal.js | 81 ++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 46 deletions(-) diff --git a/scripts/portal.js b/scripts/portal.js index 8219703..676f2ef 100644 --- a/scripts/portal.js +++ b/scripts/portal.js @@ -1,74 +1,63 @@ -'use strict'; +'use strict' + +function Portal (sites) { + this.el = document.createElement('div') + this.sites = sites -function Portal(sites) -{ - this.el = document.createElement("div"); - this.sites = sites; - // Templates - function _readme() - { + function _readme () { return `

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 diaries, wikis & portfolios.

To add yourself to the ring, submit a Pull Request.
If you found a broken link, please report it.

` } - function _buttons() - { + function _buttons () { return `

Random | Information

` } - function _directory(sites) - { + function _directory (sites) { return ` - \n${_readme()}${_buttons()}` + \n${_readme()}${_buttons()}` } - - function _redirect(target) - { + + function _redirect (target) { return `

Redirecting to ${target}

Directory | Skip | Random | Information

` } - // + // - this.install = function(host) - { - host.appendChild(this.el); - } - - this.start = function() - { - this.el.innerHTML = window.location.hash && window.location.hash.length > 4 ? _redirect(this.next()) : _directory(this.sites); + this.install = function (host) { + host.appendChild(this.el) } - this.reload = function() - { - setTimeout(()=>{ window.location.reload() },500) + this.start = function () { + this.el.innerHTML = window.location.hash && window.location.hash.length > 4 ? _redirect(this.next()) : _directory(this.sites) } - this.navigate = function(target) - { - setTimeout(() => { window.location.href = target; },3000) + this.reload = function () { + setTimeout(() => { window.location.reload() }, 500) } - - this.locate = function() - { - const hash = window.location.hash.replace("#","").trim(); - - if(hash == "random"){ - return Math.floor(Math.random()*this.sites.length) + + this.navigate = function (target) { + setTimeout(() => { window.location.href = target }, 3000) + } + + this.locate = function () { + const hash = window.location.hash.replace('#', '').trim() + + if (hash == 'random') { + return Math.floor(Math.random() * this.sites.length) } - - for(const id in this.sites){ - if(this.sites[id].indexOf(hash) >-1){ + + for (const id in this.sites) { + if (this.sites[id].indexOf(hash) > -1) { return parseInt(id) } } - return -1; + return -1 } - - this.next = function(loc = this.locate()) - { - return loc == this.sites.length-1 ? this.sites[0] : this.sites[loc+1]; + + this.next = function (loc = this.locate()) { + return loc == this.sites.length - 1 ? this.sites[0] : this.sites[loc + 1] } }