Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SW scope support & auto redirect #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
@@ -301,12 +301,14 @@ async function genCode() {
const privacy = optPrivacy.options[optPrivacy.selectedIndex].value
const hashStr = hashExp ? bytesToB64(hashExp) : ''
const urlsStr = imgUrls.join("', '")
let pathPrefix = document.getElementById('pathPrefix').value.replaceAll('/', '').replaceAll('\\', '')
let js = `\
var HASH = '${hashStr}'
var URLS = ['${urlsStr}']
var PRIVACY = ${privacy}
var UPDATE_INTERVAL = 120
var IMG_TIMEOUT = 10
var PATH_PREFIX = '${pathPrefix}'

${tmplCode}
`
8 changes: 5 additions & 3 deletions assets/js/tmpl.js
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ function pageEnv() {
var pendings = []

if (!sw.controller) {
var swPending = sw.register(jsUrl).catch(function(err) {
var swPending = sw.register(jsUrl, {scope: getRootPath(jsUrl)}).catch(function(err) {
fallback(err.message)
})
pendings.push(swPending)
@@ -46,7 +46,8 @@ function pageEnv() {
)
}
Promise.all(pendings).then(function() {
location.reload()
// location.reload()
location.replace(getRootPath(jsUrl))
})
}

@@ -295,7 +296,8 @@ function getRootPath(url) {
// e.g.
// 'https://mysite.com/'
// 'https://xx.github.io/path/to/'
return url.split('?')[0].replace(/[^/]+$/, '')
return url.split('?')[0].replace(/[^/]+$/, '') + (PATH_PREFIX ? PATH_PREFIX + '/' : '')

}

if (self.document) {
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -42,6 +42,12 @@ <h2>Step2</h2>
</div>
</div>

<h2>Step2.5</h2>
<p>Enter a sub folder name:</p>
<div>
<textarea id="pathPrefix" placeholder="Can be empty here"></textarea>
</div>

<h2>Step3</h2>
<div>
<textarea id="txtUrls" placeholder="Upload Image And Paste URLs"></textarea>