From 3cf44d0e5e88717ead92896905c426ae1b486ae5 Mon Sep 17 00:00:00 2001 From: gnehs Date: Tue, 9 Oct 2018 21:20:43 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=96=B0=E7=9A=84=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E9=A0=81=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/script.js | 5 +- public/js/setting.js | 286 +++++++++++++++++++++++-------------------- 2 files changed, 154 insertions(+), 137 deletions(-) diff --git a/public/js/script.js b/public/js/script.js index d0c4a11c..d7d5c76f 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -53,8 +53,9 @@ router 'now*': showNow, 'lrc': showLrc, 'settings': showSettings, - 'settings/theme': showSettingsTheme, - 'settings/pic': showSettingsPic, + 'settings/network': showSettingsNetwork, + 'settings/customize': showSettingsCustomize, + 'settings/system': showSettingsSystem, 'settings/about': showSettingsAbout, '*': showHome }) diff --git a/public/js/setting.js b/public/js/setting.js index a64767cc..9916690c 100644 --- a/public/js/setting.js +++ b/public/js/setting.js @@ -8,25 +8,24 @@ $(async() => { if (!window.localStorage["pokaSW"]) window.localStorage["pokaSW"] = "true" let version = (await request('/info/')).version //serviceWorker - if ('serviceWorker' in navigator && window.localStorage["pokaSW"] == "true") { + if ('serviceWorker' in navigator && window.localStorage["pokaSW"] == "true") navigator.serviceWorker - .register('/sw.js', { scope: '/' }) - .then(reg => { - if (version != window.localStorage["PokaPlayerVersion"]) reg.update() - }) - .catch(err => console.log('Error!', err)); - } else { + .register('/sw.js', { scope: '/' }) + .then(reg => { + if (version != window.localStorage["PokaPlayerVersion"]) reg.update() + }) + .catch(err => console.log('Error!', err)); + else navigator.serviceWorker - .getRegistration("/").then(reg => { - reg.unregister(); - }) - .catch(err => console.log('Error!', err)); - } + .getRegistration("/").then(reg => { + reg.unregister(); + }) + .catch(err => console.log('Error!', err)); + // 更新版本號 - if (version != window.localStorage["PokaPlayerVersion"]) { + if (version != window.localStorage["PokaPlayerVersion"]) if ($("#content").attr("data-page") == "settings" || $("#content").attr("data-page") == "home") $("#header-wrapper .title .subtitle").text(`PokaPlayer ${version}`) - } window.localStorage["PokaPlayerVersion"] = version; }); //- 設定頁面用的範本 @@ -47,21 +46,127 @@ async function showSettings() { pokaHeader('設定', "PokaPlayer "+window.localStorage["PokaPlayerVersion"]) let settingItems = `` + $("#content").html(settingItems); +} +async function showSettingsSystem() { + + pokaHeader('系統和更新', "設定") + let settingItems = `` + $("#content").html(settingItems); + let getInfo = await request('/info/'); + let debug = await request('/debug/') + let checkUpdate = await request(`https://api.github.com/repos/gnehs/PokaPlayer/releases`); + let update = getInfo.version != checkUpdate[0].tag_name ? `更新到 ${checkUpdate[0].tag_name}` : `您的 PokaPlayer 已是最新版本` + if (debug){ + $("[data-upgrade]").attr('data-upgrade', true) + update = `與開發分支同步` + $("[data-version] .mdui-list-item-text").text(`${window.localStorage["PokaPlayerVersion"]}(${debug})`) + } else if (getInfo.version != checkUpdate[0].tag_name){ + $("[data-upgrade]").attr('data-upgrade', true) + pokaHeader('系統和更新', `可更新至 ${checkUpdate[0].tag_name}`) + } + $("[data-upgrade] .mdui-list-item-text").text(update) + //重啟 + $("[data-restart]").click(() => { + mdui.confirm('注意:若您未開啟 Docker 的自動重啟功能,您必須手動開啟 PokaPlayer', '確定要重新啟動嗎', + ()=>{ + mdui.alert('正在重新啟動','','',{history: false}); + axios.post('/restart') + },()=>{},{history: false}) + }) + //更新 + $("[data-upgrade=\"true\"]").click(() => { + mdui.dialog({ + title:`${checkUpdate[0].tag_name} 更新日誌`, + content: `
+
+ ${new showdown.Converter().makeHtml(checkUpdate[0].body)} +
+
+
+ 注意:若您未開啟 Docker 的自動重啟功能,您必須手動開啟 PokaPlayer`, + history: false, + buttons: [{ + text: '取消' + }, + { + text: '更新', + onClick: async inst => { + mdui.snackbar('正在更新...', { position: getSnackbarPosition() }); + let update = await request('/upgrade/') + if (update == "upgrade") { + mdui.snackbar('伺服器重新啟動', { + buttonText: '重新連接', + onButtonClick: () => window.location.reload(), + }) + } else if (update == "socket") { + socket.emit('update') + socket.on('Permission Denied Desu', () => mdui.snackbar('Permission Denied', { + timeout: 3000, + position: getSnackbarPosition() + })) + socket.on('init', () => mdui.snackbar('正在初始化...', { + timeout: 3000, + position: getSnackbarPosition() + })) + socket.on('git', data => mdui.snackbar({ + fetch: '初始化完成', + reset: '更新檔下載完成', + api: 'API 更新完成' + }[data], { + timeout: 3000, + position: getSnackbarPosition() + })) + socket.on('restart', () => { + socket.emit('restart') + mdui.snackbar('伺服器正在重新啟動...', { + buttonText: '重新連接', + onButtonClick: () => window.location.reload(), + position: getSnackbarPosition() + }) + }) + socket.on('err', data => mdui.snackbar('錯誤: ' + data, { + timeout: 8000, + position: getSnackbarPosition() + })) + } + } + } + ] + }); + }) +} +async function showSettingsNetwork(){ + $('#content').attr('data-page', 'settings') + pokaHeader('網路和快取', "設定") + let settingItems = `` + ${settingsItem("清除 Service Worker 快取","","delete_forever","","data-clean")} + ` $("#content").html(settingItems); // 音質設定 $("[data-music-res]").click(function() { @@ -78,7 +183,7 @@ async function showSettings() {
低音質,128K,跟 YouTube 差不多的爛音質,在網路夭壽慢的情況下請選擇此選項
- +
中等音質,音質只比 YouTube 好那麼一點點,可在 3G 網路下流暢的串流
- +
高音質,音質較原始音質略差,可在 4G 網路下流暢的串流
- +
原始音質,在網路狀況許可下,建議選擇此選項聆聽高音質音樂
- + `, history: false, buttons: [{ text: '取消' - }], + }], onClose: ()=>$("[data-music-res] .mdui-list-item-text").text(window.localStorage["musicRes"]) - }); + }); }); // 圖片流量節省 $("[data-imgRes]").click(function() { @@ -123,12 +228,12 @@ async function showSettings() { window.localStorage["imgRes"] = $("[data-imgRes] input").prop('checked'); $("[data-imgRes] .mdui-list-item-text").text($("[data-imgRes] input").prop('checked') ? "將會把所有圖片替換為您指定的隨機圖片" : "已關閉"); }); + // 快取開關 $("[data-pokaSW]").click(function() { $("[data-pokaSW] input").prop('checked', !$("[data-pokaSW] input").prop('checked')) window.localStorage["pokaSW"] = $("[data-pokaSW] input").prop('checked'); console.log($("[data-pokaSW] input").prop('checked')) $("[data-pokaSW] .mdui-list-item-text").text($("[data-pokaSW] input").prop('checked') ? "已開啟" : "已關閉"); - mdui.snackbar({ message: "請重新整理來註冊或註銷 Service Worker", timeout: 2000, position: getSnackbarPosition() }); if($("[data-pokaSW] input").prop('checked')) navigator.serviceWorker .register('/sw.js', { scope: '/' }) @@ -142,17 +247,27 @@ async function showSettings() { }) .catch(err => console.log('Error!', err)); }); + // 快取清理 + $("[data-clean]").click(() => { + caches.delete('PokaPlayer') + mdui.snackbar({ message: "清理完畢", timeout: 400, position: getSnackbarPosition() }); + }) } -async function showSettingsTheme() { +async function showSettingsCustomize() { $('#content').attr('data-page', 'settings') - pokaHeader('設定', '主題' ) + pokaHeader('個人化', "設定") let settingItems = `` - $("#content").html(settingItems) +
  • 隨機圖片
  • + ${settingsItem("圖片來源",window.localStorage["randomImgName"],"image","","data-pic-source")} + ${settingsItem("自訂圖片來源",window.localStorage["randomImg"],"link","","data-pic-custom-link")} + ` + $("#content").html(settingItems); + // 主題 $('[data-theme="mdui-theme-color"]').click(function() { mdui.dialog({ title: '設定主題色', @@ -221,17 +336,8 @@ async function showSettingsTheme() { metaThemeColor.setAttribute("content", $('header>div:first-child').css("background-color")); } }) - }); -} -async function showSettingsPic() { - $('#content').attr('data-page', 'settings') - pokaHeader('設定', '隨機圖片' ) - let settingItems = `` - $("#content").html(settingItems) + }); + // 隨機圖片 $('[data-pic-source]').click(function() { let imgsOption = imgs => { /*let option = '' @@ -358,107 +464,17 @@ async function showSettingsAbout() { pokaHeader('設定', '關於') let settingItems = `` $("#content").html(settingItems) - //重啟 - $("[data-restart]").click(() => { - mdui.confirm('注意:若您未開啟 Docker 的自動重啟功能,您必須手動開啟 PokaPlayer', '確定要重新啟動嗎', - ()=>{ - mdui.alert('正在重新啟動','','',{history: false}); - axios.post('/restart') - },()=>{},{history: false}) - }) - // 快取清理 - $("[data-clean]").click(() => { - mdui.confirm('確定要清除嗎', '清除 Service Worker 快取', - ()=>caches.delete('PokaPlayer'),()=>{},{history: false}) - }) - // PokaPlayer 詳細資料 let getInfo = await request('/info/'); $("[data-dev] .mdui-list-item-text").text(getInfo.author) - let debug = await request('/debug/') - let checkUpdate = await request(`https://api.github.com/repos/gnehs/PokaPlayer/releases`); - let update = getInfo.version != checkUpdate[0].tag_name ? `更新到 ${checkUpdate[0].tag_name}` : `您的 PokaPlayer 已是最新版本` - if (debug){ - pokaHeader('設定', `開發模式`) - $("[data-upgrade]").attr('data-upgrade', true) - update = `與開發分支同步` - $("[data-version] .mdui-list-item-text").text(`${window.localStorage["PokaPlayerVersion"]}(${debug})`) - } else if (getInfo.version != checkUpdate[0].tag_name){ - $("[data-upgrade]").attr('data-upgrade', true) - pokaHeader('設定', `可更新至 ${checkUpdate[0].tag_name}`) - } - $("[data-upgrade] .mdui-list-item-text").text(update) - - //更新 - $("[data-upgrade=\"true\"]").click(() => { - mdui.dialog({ - title:`${checkUpdate[0].tag_name} 更新日誌`, - content: `
    -
    - ${new showdown.Converter().makeHtml(checkUpdate[0].body)} -
    -
    -
    - 注意:若您未開啟 Docker 的自動重啟功能,您必須手動開啟 PokaPlayer`, - history: false, - buttons: [{ - text: '取消' - }, - { - text: '更新', - onClick: async inst => { - mdui.snackbar('正在更新...', { position: getSnackbarPosition() }); - let update = await request('/upgrade/') - if (update == "upgrade") { - mdui.snackbar('伺服器重新啟動', { - buttonText: '重新連接', - onButtonClick: () => window.location.reload(), - }) - } else if (update == "socket") { - socket.emit('update') - socket.on('Permission Denied Desu', () => mdui.snackbar('Permission Denied', { - timeout: 3000, - position: getSnackbarPosition() - })) - socket.on('init', () => mdui.snackbar('正在初始化...', { - timeout: 3000, - position: getSnackbarPosition() - })) - socket.on('git', data => mdui.snackbar({ - fetch: '初始化完成', - reset: '更新檔下載完成', - api: 'API 更新完成' - }[data], { - timeout: 3000, - position: getSnackbarPosition() - })) - socket.on('restart', () => { - socket.emit('restart') - mdui.snackbar('伺服器正在重新啟動...', { - buttonText: '重新連接', - onButtonClick: () => window.location.reload(), - position: getSnackbarPosition() - }) - }) - socket.on('err', data => mdui.snackbar('錯誤: ' + data, { - timeout: 8000, - position: getSnackbarPosition() - })) - } - } - } - ] - }); - }) + $("[data-version] .mdui-list-item-text").text(getInfo.version) } \ No newline at end of file From 13e24b7ae7b002eb0c7dc606f380337029deceac Mon Sep 17 00:00:00 2001 From: gnehs Date: Tue, 9 Oct 2018 21:24:32 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=B2=92=E6=9C=89?= =?UTF-8?q?=E8=AE=80=E5=8F=96=E5=88=B0=E7=89=88=E6=9C=AC=E8=99=9F=E7=9A=84?= =?UTF-8?q?=E6=83=85=E6=B3=81=E4=B8=8B=E9=A1=AF=E7=A4=BA=E9=8C=AF=E8=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/setting.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/public/js/setting.js b/public/js/setting.js index 9916690c..5fc91bcb 100644 --- a/public/js/setting.js +++ b/public/js/setting.js @@ -6,6 +6,7 @@ $(async() => { if (!window.localStorage["randomImgName"]) window.localStorage["randomImgName"] = "預設圖庫" if (!window.localStorage["imgRes"]) window.localStorage["imgRes"] = "false" if (!window.localStorage["pokaSW"]) window.localStorage["pokaSW"] = "true" + if (!window.localStorage["PokaPlayerVersion"]) window.localStorage["PokaPlayerVersion"] = "" let version = (await request('/info/')).version //serviceWorker if ('serviceWorker' in navigator && window.localStorage["pokaSW"] == "true") @@ -477,4 +478,5 @@ async function showSettingsAbout() { let getInfo = await request('/info/'); $("[data-dev] .mdui-list-item-text").text(getInfo.author) $("[data-version] .mdui-list-item-text").text(getInfo.version) + window.localStorage["PokaPlayerVersion"] = getInfo.version } \ No newline at end of file From 747d465b7f0676b2f66ad5a9750b3b762a4bb008 Mon Sep 17 00:00:00 2001 From: gnehs Date: Tue, 9 Oct 2018 21:57:27 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E7=A8=8B=E5=BC=8F=E7=A2=BC=E5=B0=8F?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/setting.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/public/js/setting.js b/public/js/setting.js index 5fc91bcb..2b36d2b7 100644 --- a/public/js/setting.js +++ b/public/js/setting.js @@ -8,7 +8,14 @@ $(async() => { if (!window.localStorage["pokaSW"]) window.localStorage["pokaSW"] = "true" if (!window.localStorage["PokaPlayerVersion"]) window.localStorage["PokaPlayerVersion"] = "" let version = (await request('/info/')).version - //serviceWorker + + // 更新版本號 + if (version != window.localStorage["PokaPlayerVersion"]) + if ($("#content").attr("data-page") == "settings" || $("#content").attr("data-page") == "home") + $("#header-wrapper .title .subtitle").text(`PokaPlayer ${version}`) + window.localStorage["PokaPlayerVersion"] = version; + + //serviceWorker if ('serviceWorker' in navigator && window.localStorage["pokaSW"] == "true") navigator.serviceWorker .register('/sw.js', { scope: '/' }) @@ -23,11 +30,6 @@ $(async() => { }) .catch(err => console.log('Error!', err)); - // 更新版本號 - if (version != window.localStorage["PokaPlayerVersion"]) - if ($("#content").attr("data-page") == "settings" || $("#content").attr("data-page") == "home") - $("#header-wrapper .title .subtitle").text(`PokaPlayer ${version}`) - window.localStorage["PokaPlayerVersion"] = version; }); //- 設定頁面用的範本 var settingsItem = (title, text = '', icon = '', link = '', data = '', other = '', cssClass = '') => { From c139b117a462754da65e8bd478bf2d740da180b5 Mon Sep 17 00:00:00 2001 From: gnehs Date: Wed, 10 Oct 2018 14:25:54 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E9=A0=90=E8=A8=AD=E9=97=9C=E9=96=89=20SW?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/setting.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/setting.js b/public/js/setting.js index 2b36d2b7..a871bd27 100644 --- a/public/js/setting.js +++ b/public/js/setting.js @@ -5,7 +5,7 @@ $(async() => { if (!window.localStorage["randomImg"]) window.localStorage["randomImg"] = "/og/og.png" if (!window.localStorage["randomImgName"]) window.localStorage["randomImgName"] = "預設圖庫" if (!window.localStorage["imgRes"]) window.localStorage["imgRes"] = "false" - if (!window.localStorage["pokaSW"]) window.localStorage["pokaSW"] = "true" + if (!window.localStorage["pokaSW"]) window.localStorage["pokaSW"] = "false" if (!window.localStorage["PokaPlayerVersion"]) window.localStorage["PokaPlayerVersion"] = "" let version = (await request('/info/')).version From 32d945d4eb1d63a9c9587647f8ef09e7a3cc7aef Mon Sep 17 00:00:00 2001 From: gnehs Date: Wed, 10 Oct 2018 15:15:57 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E9=A0=81=E9=9D=A2=E5=84=AA=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/setting.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/js/setting.js b/public/js/setting.js index a871bd27..b2f90a83 100644 --- a/public/js/setting.js +++ b/public/js/setting.js @@ -61,9 +61,11 @@ async function showSettingsSystem() { pokaHeader('系統和更新', "設定") let settingItems = `
      ${settingsItem("返回","","arrow_back","settings")} - ${settingsItem("更新","正在檢查更新...","system_update","","data-upgrade")} +
    • 帳號
    • ${settingsItem("登出","","account_circle","",`onclick="window.localStorage['userPASS']=false;location.href='/login'"`)} ${settingsItem("嘗試重新登入","","account_circle","",`onclick="location.href='/login'"`)} +
    • 系統
    • + ${settingsItem("更新","正在檢查更新...","system_update","","data-upgrade")} ${settingsItem("重新啟動","","refresh","","data-restart")}
    ` $("#content").html(settingItems); From 106e2a170e589b587446d6d522b08647fcf40d01 Mon Sep 17 00:00:00 2001 From: gnehs Date: Wed, 10 Oct 2018 22:39:33 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=BA=96=E5=82=99=E7=99=BC=E5=B8=83=200.12?= =?UTF-8?q?.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 2 +- package.json | 2 +- public/js/login.js | 2 +- public/js/setting.js | 99 +++++++++++++++++++++++++------------------- 4 files changed, 60 insertions(+), 45 deletions(-) diff --git a/package-lock.json b/package-lock.json index e2c41fe8..b9a1b57a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "pokaplayer", - "version": "0.12.4", + "version": "0.12.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 6e9abc11..bcf6bf57 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pokaplayer", - "version": "0.12.4", + "version": "0.12.5", "description": "", "main": "index.js", "scripts": { diff --git a/public/js/login.js b/public/js/login.js index f40f8e7e..7fc8250e 100644 --- a/public/js/login.js +++ b/public/js/login.js @@ -1,7 +1,7 @@ // 初始化網頁 $(function() { var userPASS = window.localStorage["userPASS"] - if (userPASS) { + if (userPASS && userPASS != "false") { mdui.snackbar({ message: '偵測到已儲存的密碼,正在嘗試登入', timeout: 1000 diff --git a/public/js/setting.js b/public/js/setting.js index b2f90a83..20e6d0c2 100644 --- a/public/js/setting.js +++ b/public/js/setting.js @@ -16,19 +16,20 @@ $(async() => { window.localStorage["PokaPlayerVersion"] = version; //serviceWorker - if ('serviceWorker' in navigator && window.localStorage["pokaSW"] == "true") + if ('serviceWorker' in navigator && window.localStorage["pokaSW"] == "true") { navigator.serviceWorker - .register('/sw.js', { scope: '/' }) - .then(reg => { - if (version != window.localStorage["PokaPlayerVersion"]) reg.update() - }) - .catch(err => console.log('Error!', err)); - else + .register('/sw.js', { scope: '/' }) + .then(reg => { + if (version != window.localStorage["PokaPlayerVersion"]) reg.update() + }) + .catch(err => console.log('Error!', err)); + } else { navigator.serviceWorker - .getRegistration("/").then(reg => { - reg.unregister(); - }) - .catch(err => console.log('Error!', err)); + .getRegistration("/").then(reg => { + reg ? reg.unregister() : void(0) + }) + .catch(err => console.log('Error!', err)); + } }); //- 設定頁面用的範本 @@ -84,14 +85,18 @@ async function showSettingsSystem() { $("[data-upgrade] .mdui-list-item-text").text(update) //重啟 $("[data-restart]").click(() => { - mdui.confirm('注意:若您未開啟 Docker 的自動重啟功能,您必須手動開啟 PokaPlayer', '確定要重新啟動嗎', - ()=>{ - mdui.alert('正在重新啟動','','',{history: false}); - axios.post('/restart') - },()=>{},{history: false}) + let r = confirm("確定要重新啟動嗎\n注意:若您未開啟 Docker 的自動重啟功能,您必須手動開啟 PokaPlayer"); + if(r){ + mdui.snackbar('正在重新啟動', { + buttonText: '重新連接', + onButtonClick: () => window.location.reload(), + }) + axios.post('/restart') + } }) //更新 $("[data-upgrade=\"true\"]").click(() => { + router.pause(); mdui.dialog({ title:`${checkUpdate[0].tag_name} 更新日誌`, content: `
    @@ -101,7 +106,10 @@ async function showSettingsSystem() {
    注意:若您未開啟 Docker 的自動重啟功能,您必須手動開啟 PokaPlayer`, - history: false, + onClosed:()=> { + router.resume(); + router.navigate('settings/system'); + }, buttons: [{ text: '取消' }, @@ -175,6 +183,7 @@ async function showSettingsNetwork(){ $("#content").html(settingItems); // 音質設定 $("[data-music-res]").click(function() { + router.pause(); mdui.dialog({ title: '音質設定', content: `
    @@ -220,11 +229,14 @@ async function showSettingsNetwork(){ `, - history: false, buttons: [{ text: '取消' }], - onClose: ()=>$("[data-music-res] .mdui-list-item-text").text(window.localStorage["musicRes"]) + onClose: ()=>$("[data-music-res] .mdui-list-item-text").text(window.localStorage["musicRes"]), + onClosed: ()=> { + router.resume(); + router.navigate('settings/network'); + } }); }); // 圖片流量節省 @@ -237,7 +249,6 @@ async function showSettingsNetwork(){ $("[data-pokaSW]").click(function() { $("[data-pokaSW] input").prop('checked', !$("[data-pokaSW] input").prop('checked')) window.localStorage["pokaSW"] = $("[data-pokaSW] input").prop('checked'); - console.log($("[data-pokaSW] input").prop('checked')) $("[data-pokaSW] .mdui-list-item-text").text($("[data-pokaSW] input").prop('checked') ? "已開啟" : "已關閉"); if($("[data-pokaSW] input").prop('checked')) navigator.serviceWorker @@ -274,6 +285,7 @@ async function showSettingsCustomize() { $("#content").html(settingItems); // 主題 $('[data-theme="mdui-theme-color"]').click(function() { + router.pause(); mdui.dialog({ title: '設定主題色', content: `
      @@ -282,7 +294,6 @@ async function showSettingsCustomize() { ${settingsItem("Dark","","","", `onclick="window.localStorage['mdui-theme-color']='true'" mdui-dialog-close`)}
    `, - history: false, buttons: [{ text: '取消' }], @@ -295,6 +306,10 @@ async function showSettingsCustomize() { //設定顏色 let metaThemeColor = document.querySelector("meta[name=theme-color]"); metaThemeColor.setAttribute("content", $('header>div:first-child').css("background-color")); + }, + onClosed: ()=> { + router.navigate('settings/customize'); + router.resume(); } }); }); @@ -316,11 +331,15 @@ async function showSettingsCustomize() { } } option += "" + router.pause(); mdui.dialog({ title: `設定${accent ? `強調色` : `主色`}`, content: option, - history: false, - buttons: [{text: '確定'}] + buttons: [{text: '確定'}], + onClosed: ()=> { + router.navigate('settings/customize'); + router.resume(); + } }); $('[data-color-type]').click(function(){ let isAccent= $(this).attr('data-color-type') == "accent" @@ -345,12 +364,6 @@ async function showSettingsCustomize() { // 隨機圖片 $('[data-pic-source]').click(function() { let imgsOption = imgs => { - /*let option = '' - for (i = 0; i < imgs.length; i++) { - let img = imgs[i] - option += settingsItem(img.name, '', '', '', `data-img-src="${img.src}" mdui-dialog-close`) - } - return option*/ let option = `
    ` for (i = 0; i < imgs.length; i++) { let img = imgs[i] @@ -435,33 +448,35 @@ async function showSettingsCustomize() { description: '雲圖床提供', src: 'https://api.yuntuchuang.com/api/jianyue.php' }] + router.pause(); mdui.dialog({ title: '設定圖片來源', content: `
      ${imgsOption(imgs)}
    `, - history: false, - buttons: [{text: '取消'}] + buttons: [{text: '取消'}], + onClosed: ()=> { + router.navigate('settings/customize'); + router.resume(); + } }); $('[data-img-src]').click(function(){ let src = $(this).attr('data-img-src') let name = $(this).children('.title').text() window.localStorage["randomImg"] = src window.localStorage["randomImgName"] = name - pokaHeader('設定', '隨機圖片',src,false,false) + pokaHeader('個人化', "設定",src,false,false) $('[data-pic-source] .mdui-list-item-text').text(name) $('[data-pic-custom-link] .mdui-list-item-text').text(src) }) }); $('[data-pic-custom-link]').click(function(){ - mdui.prompt('請輸入圖片網址', '自訂圖片來源', - value => { - if (value){ - window.localStorage["randomImg"] = value - $('[data-pic-custom-link] .mdui-list-item-text').text(value) - window.localStorage["randomImgName"] = "自訂" - pokaHeader('設定', '隨機圖片',value,false,false) - } - },()=>{},{history: false} - ); + //似乎有 bug + let img=prompt("請輸入圖片網址", "https://images2.imgbox.com/99/e2/knJdNcns_o.jpg"); + if(img != null){ + window.localStorage["randomImg"] = img + $('[data-pic-custom-link] .mdui-list-item-text').text(img) + window.localStorage["randomImgName"] = "自訂" + pokaHeader('個人化', "設定",img,false,false) + } }) } async function showSettingsAbout() {