@@ -53,8 +53,9 @@ function Portal (sites) {
55 this.start = function () {
55 this.start = function () {
56+ const hash = window.location.hash
56− if (window.location.hash && window.location.hash.length > 4) {
57+ if (hash && hash.length > 4) {
57− const site = this.next()
58+ const site = this.getSite(hash.replace('#', '').trim())
58 this.el.innerHTML = _redirectView(site)
59 this.el.innerHTML = _redirectView(site)
59 setTimeout(() => { window.location = site.url }, 3000)
60 setTimeout(() => { window.location = site.url }, 3000)
@@ -73,15 +74,17 @@ function Portal (sites) {
73 this.sitesMatchingLangs = this.sites
74 this.sitesMatchingLangs = this.sites
74 .filter(site => site.langs && site.langs.some(lang => navigator.languages.includes(lang)))
75 .filter(site => site.langs && site.langs.some(lang => navigator.languages.includes(lang)))
76− this.next = function () {
77+ this.nextSiteIndex = (ceiling, index) => index === ceiling ? 0 : index + 1
77− const hash = window.location.hash.replace('#', '').trim()
78+ this.randomSite = this.sitesMatchingLangs[Math.floor(Math.random() * this.sitesMatchingLangs.length)]
80+ this.getSite = function (hash) {
79 if (hash === 'random') {
81 if (hash === 'random') {
80− return this.sitesMatchingLangs[Math.floor(Math.random() * this.sitesMatchingLangs.length)]
82+ return this.randomSite
82− return sites.find(site => site.url.includes(hash))
84+ const index = this.sitesMatchingLangs.findIndex(site => site.url.includes(hash))
83− ? sites.find(site => site.url.includes(hash))
85+ return (index > -1)
84− : this.sitesMatchingLangs[Math.floor(Math.random() * this.sitesMatchingLangs.length)]
86+ ? this.sitesMatchingLangs[this.nextSiteIndex(this.sitesMatchingLangs.length, index)]