diff --git a/service/httpd/onion.go b/service/httpd/onion.go index 36f54f47..d7597121 100644 --- a/service/httpd/onion.go +++ b/service/httpd/onion.go @@ -65,7 +65,7 @@ func (h *Httpd) startOnionService(server *http.Server) error { LocalListener: listener, RemotePorts: h.opts.OnionRemotePorts(), Version3: true, - NoWait: true, + NoWait: verbose, Key: pvk, }) if err != nil { diff --git a/service/httpd/web.go b/service/httpd/web.go index 36639b0c..d03483c4 100644 --- a/service/httpd/web.go +++ b/service/httpd/web.go @@ -94,7 +94,7 @@ func (web *web) handle() http.Handler { web.router.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") - w.Write(helper.String2Byte("User-agent: *\nDisallow: /")) // nolint:errcheck + w.Write(helper.String2Byte("User-agent: *\nDisallow:")) // nolint:errcheck }) return web.router diff --git a/template/assets/js/index.js b/template/assets/js/index.js index 65c947dd..1881aea2 100644 --- a/template/assets/js/index.js +++ b/template/assets/js/index.js @@ -1,5 +1,32 @@ +let policy; +if (typeof window.trustedTypes !== "undefined") { + try { + policy = window.trustedTypes.createPolicy('tt-policy', { + createScriptURL: (url) => url + }); + } catch (e) { + console.warn('Failed to create Trusted Types policy: ', e); + policy = null; + } +} else { + policy = { + createScriptURL: (url) => url + }; +} + if ("serviceWorker" in navigator) { - navigator.serviceWorker.register('/service-worker.js'); + const scriptURL = policy.createScriptURL('/service-worker.js'); + + try { + navigator.serviceWorker.register(scriptURL).catch(error => { + console.error('Service Worker registration failed: ', error); + if (error.name === 'SecurityError') { + console.warn('Service Worker registration failed due to security restrictions'); + } + }); + } catch (error) { + console.error('Failed to register Service Worker: ', error); + } } window.addEventListener('beforeinstallprompt', (e) => { @@ -27,7 +54,7 @@ window.addEventListener('beforeinstallprompt', (e) => { } }); -var unblock = function (collects) { +const unblock = () => { document.querySelector('div.form').style.backgroundColor = ''; document.querySelector('#wayback').disabled = false; document.querySelector('#playback').disabled = false; @@ -35,37 +62,67 @@ var unblock = function (collects) { document.getElementById('text').value = ''; }; -var render = function (collects) { +const render = (collects) => { "use strict"; - if (typeof collects !== "object") { + if (!collects || typeof collects !== 'object') { return; } - var archived = document.getElementById('archived'); - var html = ''; - collects.forEach(function (collect, i) { - html += ''; - }) - archived.innerHTML = html + archived.innerHTML; + + dst.appendChild(link); + row.appendChild(src); + row.appendChild(dst); + fragment.appendChild(row); + }); + archived.insertBefore(fragment, archived.firstChild); }; -var post = function (url) { +const post = (url) => { "use strict"; - var http = new XMLHttpRequest(), + const http = new XMLHttpRequest(), params = new URLSearchParams(), text = document.getElementById('text').value; if (!text || text.length === 0) { return; } + http.onload = () => { + http.onreadystatechange = null; + }; document.getElementById('text').disabled = true; document.querySelector('#wayback').disabled = true; @@ -74,10 +131,10 @@ var post = function (url) { http.open("POST", url, true); http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - http.onreadystatechange = function () { + http.onreadystatechange = () => { if (http.readyState === 4 && http.status === 200) { if (http.response !== undefined && http.response) { - var collects = JSON.parse(http.response) + const collects = JSON.parse(http.response) render(collects); } } diff --git a/template/views/layout.html b/template/views/layout.html index 0bc06892..26bd9fe5 100644 --- a/template/views/layout.html +++ b/template/views/layout.html @@ -1,20 +1,32 @@ - + - + - - + + + + + + + + + + + + + + Wayback Archiver @@ -26,7 +38,7 @@ - @@ -470,21 +557,48 @@
- - - + + +
- {{if not .PrivacyURL}} -
- {{end}} - {{if .PrivacyURL}} + {{ if not .PrivacyURL -}} +
+ {{- end}} + {{- if .PrivacyURL -}}
By messaging Wayback Archiver, you have read our Privacy Policy.
- {{end}} + {{- end}}