Skip to content

Commit

Permalink
实现 #26 的功能需求
Browse files Browse the repository at this point in the history
  • Loading branch information
scoful committed Sep 30, 2023
1 parent 5e481da commit 09678d0
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 22 deletions.
17 changes: 16 additions & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 "
}
}
25 changes: 20 additions & 5 deletions _locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"message": "查看配置"
},
"restoreKey": {
"message": "点击“恢复全部”或恢复单个标签时"
"message": "点击“打开整组”或点击单个标签时"
},
"restoreValueDelete": {
"message": "打开标签并将其从标签列表中删除"
Expand All @@ -57,13 +57,13 @@
"message": "打开标签但不将其从标签列表中删除"
},
"openBackgroundAfterSendTab": {
"message": "点击“发送当前标签”后:"
"message": "点击“发送当前标签”或“发送所有标签”或“发送其他标签”后:"
},
"openBackgroundAfterSendTabYes": {
"message": "打开展示页"
"message": "打开后台页"
},
"openBackgroundAfterSendTabNo": {
"message": "不打开展示页"
"message": "不打开后台页"
},
"saveButtonValue": {
"message": "保存配置"
Expand Down Expand Up @@ -114,7 +114,7 @@
"message": "请输入\"确定\"表示确认:"
},
"confirmValue": {
"message": "会覆盖的,小心谨慎思考这操作到底要不要!!!"
"message": "会覆盖的,小心谨慎思考这操作到底要不要!!!请输入\"确定\"表示确认"
},
"importToLocal": {
"message": "导入"
Expand Down Expand Up @@ -427,5 +427,20 @@
},
"remindMenu": {
"message": "定时功能菜单"
},
"showError": {
"message": "出错了!"
},
"goToOptions": {
"message": "请去配置页面进行配置!"
},
"githubToken": {
"message": "GitHub Token"
},
"giteeToken": {
"message": "Gitee Token"
},
"input": {
"message": "请输入"
}
}
Binary file added fonts/glyphicons-halflings-regular.woff2
Binary file not shown.
143 changes: 127 additions & 16 deletions js/workbench.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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) {
Expand All @@ -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 = `
<div class="option">
Expand All @@ -2147,34 +2175,87 @@ https://www.google.com | Google
</div>
</div>
<div class="option">
<div class="desc">
<p>${chrome.i18n.getMessage("openBackgroundAfterSendTab")}</p>
<div class="desc">
<p>${chrome.i18n.getMessage("openBackgroundAfterSendTab")}</p>
</div>
<div class="choices">
<p><label for="openBackgroundAfterSendTab"><input type="radio" name="openBackgroundAfterSendTab" value="yes">${chrome.i18n.getMessage("openBackgroundAfterSendTabYes")}</label></p>
<p><label for="openBackgroundAfterSendTab"><input type="radio" name="openBackgroundAfterSendTab" value="no">${chrome.i18n.getMessage("openBackgroundAfterSendTabNo")}</label></p>
</div>
</div>
<div class="choices">
<p><label for="openBackgroundAfterSendTab"><input type="radio" name="openBackgroundAfterSendTab" value="yes">${chrome.i18n.getMessage("openBackgroundAfterSendTabYes")}</label></p>
<p><label for="openBackgroundAfterSendTab"><input type="radio" name="openBackgroundAfterSendTab" value="no">${chrome.i18n.getMessage("openBackgroundAfterSendTabNo")}</label></p>
<div class="form-group row">
<label for="password" class="col-sm-2 control-label">${chrome.i18n.getMessage("githubToken")}:</label>
<div class="col-sm-5">
<div class="input-group">
<input type="password" class="form-control" id="githubToken" placeholder="${chrome.i18n.getMessage("input")}${chrome.i18n.getMessage("githubToken")}">
<div class="input-group-addon">
<span class="glyphicon glyphicon-eye-open" id="changeEye"></span>
</div>
</div>
</div>
</div>
</div>
<div class="form-group row">
<label for="password" class="col-sm-2 control-label">${chrome.i18n.getMessage("giteeToken")}:</label>
<div class="col-sm-5">
<div class="input-group">
<input type="password" class="form-control" id="giteeToken" placeholder="${chrome.i18n.getMessage("input")}${chrome.i18n.getMessage("giteeToken")}">
<div class="input-group-addon">
<span class="glyphicon glyphicon-eye-open" id="changeEye2"></span>
</div>
</div>
</div>
</div>
<button id="save">${chrome.i18n.getMessage("saveButtonValue")}</button>
<div id="saved">${chrome.i18n.getMessage("savedValue")}</div>
`
// 保存配置
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 () {
document.getElementById('saved').style.display = 'none';
}, 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";
}
});
};


Expand All @@ -2197,6 +2278,36 @@ https://www.google.com | Google
}, 3000);
}

// 统一的弹窗提示
function showAlert(title, message) {
var modalHtml = `
<div class="modal fade" id="alertModal" tabindex="-1" role="dialog" aria-labelledby="alertModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="alertModalLabel">${title}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
${message}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
</div>
</div>
</div>
</div>
`;

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);
Expand Down

0 comments on commit 09678d0

Please sign in to comment.