on master help sign in
add back in ability to go to the next site in the ring that matches langs
67981cdckipp01
scripts/portal.js+11−8
@@ -53,8 +53,9 @@ function Portal (sites) {
53 }
53 }
54
54
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)
60 } else {
61 } else {
@@ -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)))
75
76
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)]
78
79
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
81 } else {
83 } else {
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)]
87+ : this.randomSite
85 }
88 }
86 }
89 }
87}
90}