diff --git a/assets/js/main.js b/assets/js/main.js index 77791ed..fe13355 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -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} ` diff --git a/assets/js/tmpl.js b/assets/js/tmpl.js index 5940397..12ac606 100644 --- a/assets/js/tmpl.js +++ b/assets/js/tmpl.js @@ -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) { diff --git a/index.html b/index.html index f025216..229d152 100644 --- a/index.html +++ b/index.html @@ -42,6 +42,12 @@

Step2

+

Step2.5

+

Enter a sub folder name:

+
+ +
+

Step3