on master help sign in
Merge pull request #310 from ckipp01/bugfix/firefox-random

fix firefox redirect issue

commitc86f30ab43636aa998a7b35cb572b8aa7788ef52 authorЛu Лinveгa <aliceffekt@gmail.com> dateThu 12 Sep 2019, 15:51 (7 years ago) parent976e0bf50db8a2
2 files changed+21−17
scripts/hallway.js+4−4 scripts/portal.js+17−13
scripts/hallway.js+4−4
@@ -18,8 +18,8 @@ function Hallway (sites) {
1818 this._main.id = 'entries'
1919 this._footer = document.createElement('footer')
2020 this._footer.id = 'footer'
21− this.readme = `<p>The <strong>Hallway</strong> is a decentralized forum, to join the conversation, add a <a href="https://github.com/XXIIVV/webring#joining-the-hallway">feed:</a> field to your entry in the <a href="https://github.com/XXIIVV/Webring/">webring</a>.</p>`
22− this.nav = `<p class='buttons'><a href='https://github.com/XXIIVV/webring'>Information</a> | <a href="index.html">The Portal</a> | <a href="wiki.html">The Wiki</a> | <a id="opml">OPML</a></p>`
21+ this.readme = '<p>The <strong>Hallway</strong> is a decentralized forum, to join the conversation, add a <a href="https://github.com/XXIIVV/webring#joining-the-hallway">feed:</a> field to your entry in the <a href="https://github.com/XXIIVV/Webring/">webring</a>.</p>'
22+ this.nav = '<p class="buttons"><a href="https://github.com/XXIIVV/webring">Information</a> | <a href="index.html">The Portal</a> | <a href="wiki.html">The Wiki</a> | <a id="opml">OPML</a></p>'
2323 this._footer.innerHTML = `${this.readme}${this.nav}`
2424
2525 this.install = function (host) {
@@ -118,10 +118,10 @@ function Hallway (sites) {
118118
119119 this.templateEntry = function (entry) {
120120 entry.html = entry.body
121− .replace(reChannel, `$1<span class='channel'>/$2</span>`)
121+ .replace(reChannel, '$1<span class="channel">/$2</span>')
122122 .replace(reUser, this.findMention)
123123 .replace(reTag, '$1<span class="tag">$2</span>')
124− .replace(reUrl, `<a target="_blank" href='$1'>$1</a>`)
124+ .replace(reUrl, '<a target="_blank" href="$1">$1</a>')
125125
126126 const filter = window.location.hash.substr(1).replace(/\+/g, ' ').toLowerCase()
127127 const highlight = filter === entry.author.toLowerCase()
scripts/portal.js+17−13
@@ -8,18 +8,18 @@ function Portal (sites) {
88 // Templates
99
1010 function _readme () {
11− 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/scripts/sites.js' 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>`
11+ 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/scripts/sites.js" 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>'
1212 }
1313
1414 function _buttons () {
15− 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> | <a href="hallway.html">The Hallway</a> | <a href="wiki.html">The Wiki</a> | <a id="opml">OPML</a></p>`
15+ return '<p class="buttons"><a href="#random" onClick="portal.reload()">Random</a> | <a href="https://github.com/XXIIVV/webring">Information</a> <a id="icon" href="#random" onClick="portal.reload()"></a> | <a href="hallway.html">The Hallway</a> | <a href="wiki.html">The Wiki</a> | <a id="opml">OPML</a></p>'
1616 }
1717
1818 function _directory (sites) {
1919 const siteTypesArray = [...new Set(sites.map(site => site.type).filter(Boolean))]
2020 const siteTypes = siteTypesArray.reduce((output, siteType) =>
21− `${output}<a data-type='${siteType}' href='#' onclick='toggleType(event)'>&lt;${siteType}&gt;</a>`,
22− `<a class='current' href='#' onclick='toggleType(event)'>&lt;all&gt;</a>`)
21+ `${output}<a data-type="${siteType}" href="#" onclick="toggleType(event)">&lt;${siteType}&gt;</a>`,
22+ '<a class="current" href="#" onclick="toggleType(event)">&lt;all&gt;</a>')
2323 const listItems = sites.reduce((acc, site, id) =>
2424 `${acc}<li ${_type(site)} id='${id}'><a href='${site.url}'>${_name(site)}</a></li>`, '')
2525 return `<nav>${siteTypes}</nav><main><ul>${listItems}</ul></main><footer>${_readme()}${_buttons()}</footer>`
@@ -35,8 +35,7 @@ function Portal (sites) {
3535
3636 function _redirect (site) {
3737 return `<main><p>Redirecting to <a href="${site.url}">${site.url}</a></p></main>
38− <meta http-equiv="refresh" content="3; url=${site.url}">
39− <footer><p class='buttons'><a href='#' onClick="portal.reload('')">Directory</a> | <a href='#${site.url}' 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>`
38+ <footer><p class='buttons'><a href='#' onClick="portal.reload('')">Directory</a> | <a href='#${site.url}' onClick="portal.reload()">Skip</a> | <a href='#random' onClick="portal.reload()">Random</a> | <a href='https://github.com/XXIIVV/webring'>Information</a> <a id='icon' href='#random' onClick="portal.reload()"></a></p>`
4039 }
4140
4241 //
@@ -46,7 +45,13 @@ function Portal (sites) {
4645 }
4746
4847 this.start = function () {
49− this.el.innerHTML = window.location.hash && window.location.hash.length > 4 ? _redirect(this.next()) : _directory(this.sites)
48+ if (window.location.hash && window.location.hash.length > 4) {
49+ const site = this.next()
50+ this.el.innerHTML = _redirect(site)
51+ setTimeout(() => { window.location = site.url }, 3000)
52+ } else {
53+ this.el.innerHTML = _directory(this.sites)
54+ }
5055 }
5156
5257 this.reload = function () {
@@ -69,19 +74,18 @@ function Portal (sites) {
6974 }
7075
7176 this.next = function (loc = this.locate()) {
72− return loc == this.sites.length - 1 ? this.sites[0] : this.sites[loc + 1]
77+ return loc === this.sites.length - 1 ? this.sites[0] : this.sites[loc + 1]
7378 }
74−
7579}
7680
7781function toggleType (e) {
7882 e.preventDefault()
7983 const navLink = e.target
8084 const selectedType = navLink.dataset.type
81− document.querySelector(`nav a.current`).classList.remove('current')
85+ document.querySelector('nav a.current').classList.remove('current')
8286 navLink.classList.add('current')
83− document.querySelectorAll(`main li`).forEach(el => el.style.display = 'block')
84− if(selectedType) {
85− document.querySelectorAll(`main li:not([data-type='${selectedType}'])`).forEach(el => el.style.display = 'none')
87+ document.querySelectorAll('main li').forEach(el => { el.style.display = 'block' })
88+ if (selectedType) {
89+ document.querySelectorAll(`main li:not([data-type='${selectedType}'])`).forEach(el => { el.style.display = 'none' })
8690 }
8791}