diff --git a/_locales/en/messages.json b/_locales/en/messages.json index fa3a063..361d428 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -114,7 +114,7 @@ "message": "Please input \"confirm\" to ensure: " }, "confirmValue": { - "message": "Warn!!! It will be override, please deep think about it !!!" + "message": "Warn!!! It will be override, please deep think about it !!! Please input \"confirm\" to ensure" }, "importToLocal": { "message": "import to local" @@ -427,5 +427,20 @@ }, "remindMenu": { "message": "remind menu" + }, + "showError": { + "message": "Error!" + }, + "goToOptions": { + "message": "Please go to the options page for configuration." + }, + "githubToken": { + "message": "GitHub Token" + }, + "giteeToken": { + "message": "Gitee Token" + }, + "input": { + "message": "Please input " } } diff --git a/_locales/zh_CN/messages.json b/_locales/zh_CN/messages.json index bd84bcd..f4f4cdf 100644 --- a/_locales/zh_CN/messages.json +++ b/_locales/zh_CN/messages.json @@ -48,7 +48,7 @@ "message": "查看配置" }, "restoreKey": { - "message": "点击“恢复全部”或恢复单个标签时:" + "message": "点击“打开整组”或点击单个标签时:" }, "restoreValueDelete": { "message": "打开标签并将其从标签列表中删除" @@ -57,13 +57,13 @@ "message": "打开标签但不将其从标签列表中删除" }, "openBackgroundAfterSendTab": { - "message": "点击“发送当前标签”后:" + "message": "点击“发送当前标签”或“发送所有标签”或“发送其他标签”后:" }, "openBackgroundAfterSendTabYes": { - "message": "打开展示页" + "message": "打开后台页" }, "openBackgroundAfterSendTabNo": { - "message": "不打开展示页" + "message": "不打开后台页" }, "saveButtonValue": { "message": "保存配置" @@ -114,7 +114,7 @@ "message": "请输入\"确定\"表示确认:" }, "confirmValue": { - "message": "会覆盖的,小心谨慎思考这操作到底要不要!!!" + "message": "会覆盖的,小心谨慎思考这操作到底要不要!!!请输入\"确定\"表示确认" }, "importToLocal": { "message": "导入" @@ -427,5 +427,20 @@ }, "remindMenu": { "message": "定时功能菜单" + }, + "showError": { + "message": "出错了!" + }, + "goToOptions": { + "message": "请去配置页面进行配置!" + }, + "githubToken": { + "message": "GitHub Token" + }, + "giteeToken": { + "message": "Gitee Token" + }, + "input": { + "message": "请输入" } } diff --git a/fonts/glyphicons-halflings-regular.woff2 b/fonts/glyphicons-halflings-regular.woff2 new file mode 100644 index 0000000..64539b5 Binary files /dev/null and b/fonts/glyphicons-halflings-regular.woff2 differ diff --git a/js/workbench.js b/js/workbench.js index cf8be0e..e2e7b6b 100644 --- a/js/workbench.js +++ b/js/workbench.js @@ -563,13 +563,18 @@ https://www.google.com | Google // 响应推送到github的gist的动作 document.getElementById('pushToGithubGist').addEventListener('click', function () { var confirm = prompt(`${chrome.i18n.getMessage("confirmKey")}`, `${chrome.i18n.getMessage("confirmValue")}`); - if (confirm.trim() == "确定" || confirm.trim() == "confirm") { + if (confirm.trim() === "确定" || confirm.trim() === "confirm") { console.log("yes"); chrome.storage.local.get(null, function (storage) { + if (!storage.githubGistToken) { + console.log("githubGistToken没有保存"); + showAlert(`${chrome.i18n.getMessage("showError")}`,`${chrome.i18n.getMessage("githubTokenNoSaved")}`+"\n"+`${chrome.i18n.getMessage("goToOptions")}`) + return + } console.log(storage.handleGistStatus); if (storage.handleGistStatus) { console.log("handleGistStatus有值"); - if (storage.handleGistStatus.type == "IDLE") { + if (storage.handleGistStatus.type === "IDLE") { pushToGithubGist(); } else { var time = moment().format('YYYY-MM-DD HH:mm:ss'); @@ -594,13 +599,18 @@ https://www.google.com | Google // 响应推送到gitee的gist的动作 document.getElementById('pushToGiteeGist').addEventListener('click', function () { var confirm = prompt(`${chrome.i18n.getMessage("confirmKey")}`, `${chrome.i18n.getMessage("confirmValue")}`); - if (confirm.trim() == "确定" || confirm.trim() == "confirm") { + if (confirm.trim() === "确定" || confirm.trim() === "confirm") { console.log("yes"); chrome.storage.local.get(null, function (storage) { + if (!storage.giteeGistToken) { + console.log("giteeGistToken没有保存"); + showAlert(`${chrome.i18n.getMessage("showError")}`,`${chrome.i18n.getMessage("giteeTokenNoSaved")}`+"\n"+`${chrome.i18n.getMessage("goToOptions")}`) + return + } console.log(storage.handleGistStatus); if (storage.handleGistStatus) { console.log("handleGistStatus有值"); - if (storage.handleGistStatus.type == "IDLE") { + if (storage.handleGistStatus.type === "IDLE") { pushToGiteeGist(); } else { var time = moment().format('YYYY-MM-DD HH:mm:ss'); @@ -625,13 +635,18 @@ https://www.google.com | Google // 响应从github的gist拉取的动作 document.getElementById('pullFromGithubGist').addEventListener('click', function () { var confirm = prompt(`${chrome.i18n.getMessage("confirmKey")}`, `${chrome.i18n.getMessage("confirmValue")}`); - if (confirm.trim() == "确定" || confirm.trim() == "confirm") { + if (confirm.trim() === "确定" || confirm.trim() === "confirm") { console.log("yes"); chrome.storage.local.get(null, function (storage) { + if (!storage.githubGistToken) { + console.log("githubGistToken没有保存"); + showAlert(`${chrome.i18n.getMessage("showError")}`,`${chrome.i18n.getMessage("githubTokenNoSaved")}`+"\n"+`${chrome.i18n.getMessage("goToOptions")}`) + return + } console.log(storage.handleGistStatus); if (storage.handleGistStatus) { console.log("handleGistStatus有值"); - if (storage.handleGistStatus.type == "IDLE") { + if (storage.handleGistStatus.type === "IDLE") { pullFromGithubGist(); } else { var time = moment().format('YYYY-MM-DD HH:mm:ss'); @@ -657,13 +672,18 @@ https://www.google.com | Google // 响应从gitee的gist拉取的动作 document.getElementById('pullFromGiteeGist').addEventListener('click', function () { var confirm = prompt(`${chrome.i18n.getMessage("confirmKey")}`, `${chrome.i18n.getMessage("confirmValue")}`); - if (confirm.trim() == "确定" || confirm.trim() == "confirm") { + if (confirm.trim() === "确定" || confirm.trim() === "confirm") { console.log("yes"); chrome.storage.local.get(null, function (storage) { + if (!storage.giteeGistToken) { + console.log("giteeGistToken没有保存"); + showAlert(`${chrome.i18n.getMessage("showError")}`,`${chrome.i18n.getMessage("giteeTokenNoSaved")}`+"\n"+`${chrome.i18n.getMessage("goToOptions")}`) + return + } console.log(storage.handleGistStatus); if (storage.handleGistStatus) { console.log("handleGistStatus有值"); - if (storage.handleGistStatus.type == "IDLE") { + if (storage.handleGistStatus.type === "IDLE") { pullFromGiteeGist(); } else { var time = moment().format('YYYY-MM-DD HH:mm:ss'); @@ -2122,7 +2142,7 @@ https://www.google.com | Google // 展示配置 function showOptions() { - chrome.storage.local.get('options', function (storage) { + chrome.storage.local.get(null, function (storage) { var opts = storage.options || {}; if (opts.deleteTabOnOpen === undefined) { @@ -2135,6 +2155,14 @@ https://www.google.com | Google } else { $('input[name="openBackgroundAfterSendTab"][value="' + opts.openBackgroundAfterSendTab + '"]').prop('checked', 'checked'); } + + // 如果已经有保存token就直接列出 + if (storage.githubGistToken) { + document.getElementById("githubToken").value= storage.githubGistToken + } + if (storage.giteeGistToken) { + document.getElementById("giteeToken").value= storage.giteeGistToken + } }); document.getElementById("options").innerHTML = `
@@ -2147,14 +2175,39 @@ https://www.google.com | Google
-
-

${chrome.i18n.getMessage("openBackgroundAfterSendTab")}

+
+

${chrome.i18n.getMessage("openBackgroundAfterSendTab")}

+
+
+

+

+
-
-

-

+ +
+ +
+
+ +
+ +
+
+
-
+ +
+ +
+
+ +
+ +
+
+
+
+
${chrome.i18n.getMessage("savedValue")}
` @@ -2162,12 +2215,16 @@ https://www.google.com | Google document.getElementById('save').addEventListener('click', function () { var deleteTabOnOpen = document.querySelector('input[name="deleteTabOnOpen"]:checked').value; var openBackgroundAfterSendTab = document.querySelector('input[name="openBackgroundAfterSendTab"]:checked').value; + let githubGistToken = document.getElementById("githubToken").value + let giteeGistToken = document.getElementById("giteeToken").value chrome.storage.local.set({ options: { deleteTabOnOpen: deleteTabOnOpen, openBackgroundAfterSendTab: openBackgroundAfterSendTab - } + }, + githubGistToken: githubGistToken, + giteeGistToken: giteeGistToken }, function () { // show "settings saved" notice thing document.getElementById('saved').style.display = 'block'; window.setTimeout(function () { @@ -2175,6 +2232,30 @@ https://www.google.com | Google }, 1000); }); }); + document.getElementById('changeEye').addEventListener('click', function () { + var passwordInput = document.getElementById("githubToken"); + var visibilityIcon = document.getElementById("changeEye"); + + if (passwordInput.type === "password") { + passwordInput.type = "text"; + visibilityIcon.className = "glyphicon glyphicon-eye-close"; + } else { + passwordInput.type = "password"; + visibilityIcon.className = "glyphicon glyphicon-eye-open"; + } + }); + document.getElementById('changeEye2').addEventListener('click', function () { + var passwordInput = document.getElementById("giteeToken"); + var visibilityIcon = document.getElementById("changeEye2"); + + if (passwordInput.type === "password") { + passwordInput.type = "text"; + visibilityIcon.className = "glyphicon glyphicon-eye-close"; + } else { + passwordInput.type = "password"; + visibilityIcon.className = "glyphicon glyphicon-eye-open"; + } + }); }; @@ -2197,6 +2278,36 @@ https://www.google.com | Google }, 3000); } + // 统一的弹窗提示 + function showAlert(title, message) { + var modalHtml = ` + + `; + + var modalContainer = document.createElement('div'); + modalContainer.innerHTML = modalHtml; + document.body.appendChild(modalContainer); + + $('#alertModal').modal('show'); + } + // 判断是否int function isInt(i) { return typeof i == "number" && !(i % 1) && !isNaN(i);