This commit is contained in:
Jesse-Ma
2022-06-30 12:32:28 +08:00
parent 9a7d98316c
commit 0bdd2eea5c
5 changed files with 55 additions and 69 deletions

View File

@@ -62,7 +62,6 @@ export function deleteNote(key) {
export function getNoteMeta(key) { export function getNoteMeta(key) {
console.log("getNoteMeta");
let noteMeta = {}; let noteMeta = {};
Jquery.ajax({ Jquery.ajax({
method: 'GET', method: 'GET',

View File

@@ -18,9 +18,9 @@ export function setStoreText(text, secret, password) {
let storeText = aesEncrypt(text, secretKey); let storeText = aesEncrypt(text, secretKey);
storeText = zip(storeText); storeText = zip(storeText);
let lock = '0'; let lock = 0;
if (password) { if (password) {
lock = '1'; lock = 1;
} }
storage.local.setText(secret.storeKey + '.text', lock + '|' + secret.cipher + '|' + storeText); storage.local.setText(secret.storeKey + '.text', lock + '|' + secret.cipher + '|' + storeText);

View File

@@ -161,7 +161,7 @@ export default {
escapeText: '', escapeText: '',
key: '', key: '',
md5: '', md5: '',
lock: '0', lock: 0,
}, },
secret: { secret: {
storeKey: '', storeKey: '',
@@ -169,9 +169,9 @@ export default {
cipher: '', cipher: '',
}, },
state: { state: {
lock: '0', lock: 0,
locking: '0', locking: 0,
commited: '0' commited: 0
} }
} }
}, },

View File

@@ -93,19 +93,13 @@
<div style="background: white;width:100%;height:40px;"> <div style="background: white;width:100%;height:40px;">
<div style="float:left;width:auto;">
<Button-group size="large">
</Button-group>
</div>
<img style="height:40px;float:left;" src="favicon.png"> <img style="height:40px;float:left;" src="favicon.png">
<div style="float:left;width:auto;"> <div style="float:left;width:auto;">
<Button-group size="large"> <Button-group size="large">
<Button type="error" :loading="loading"
style="margin-left:5px; border-radius: 0px;font-size: 24px;" @click="submitNote()"
icon="md-cloud-upload"></Button>
</Button-group> </Button-group>
@@ -120,24 +114,12 @@
<Button-group size="large"> <Button-group size="large">
<Button v-show="!showPassword" type="error"
style="margin-right:5px; border-radius: 0px;font-size: 24px;" @click="showInput()"
icon="md-unlock"></Button>
<Input v-show="!showPassword">
<Button slot="append" type="error" style="margin-right:5px; border-radius: 0px;font-size: 24px;"
icon="md-checkmark-circle"></Button>
</Input>
<Button type="error" :loading="loading"
style="margin-right:5px; border-radius: 0px;font-size: 24px;" @click="submitNote()"
icon="md-cloud-upload"></Button>
<Button type="error" style="margin-left:0px; border-radius: 0px;font-size: 24px;" <Button type="error" style="margin-left:0px; border-radius: 0px;font-size: 24px;"
@click="createNote()" icon="md-add"></Button> @click="createNote()" icon="md-add"></Button>
<Button type="error" style="margin-left:0px; border-radius: 0px;font-size: 24px;" <Button type="error" style="margin-left:5px; border-radius: 0px;font-size: 24px;"
@click="dropNote()" icon="md-trash"></Button> @click="dropNote()" icon="md-trash"></Button>
</Button-group> </Button-group>
@@ -206,7 +188,7 @@
<div id="wrapper" style="border-left: 0px solid #FF3366;"> <div id="wrapper" style="border-left: 0px solid #FF3366;">
<Input element-id="noteText" type="textarea" :border="false" v-model="noteForm.text" <Input element-id="noteText" type="textarea" :border="false" v-model="noteForm.text"
:autosize="{ minRows: 30, maxRows: 1024 }" placeholder="Enter something..." v-on:input="log" :autosize="{ minRows: 30, maxRows: 4096 }" placeholder="Enter something..." v-on:input="log"
@on-keydown="down" /> @on-keydown="down" />
</div> </div>
@@ -269,11 +251,11 @@ export default {
cipher: '', cipher: '',
}, },
state: { state: {
lock: '0', lock: 0,
locking: '0', locking: 0,
commited: '0' commited: 0
} }
} }
}, },
@@ -284,17 +266,17 @@ export default {
let keyMeta = storage.session.getObject(storeKey + '.keyMeta'); let keyMeta = storage.session.getObject(storeKey + '.keyMeta');
if (keyMeta) { if (keyMeta) {
this.state.lock = '0'; this.state.lock = 0;
this.secret.cipher = keyMeta.cipher; this.secret.cipher = keyMeta.cipher;
storage.local.setText(storeKey + '.text', "0|" + this.secret.cipher); storage.local.setText(storeKey + '.text', "0|" + this.secret.cipher);
storage.session.setObject(storeKey + '.keyMeta', null); storage.session.setObject(storeKey + '.keyMeta', null);
} else { } else {
let storeText = storage.local.getText(storeKey + '.text'); let storeText = storage.local.getText(storeKey + '.text');
this.state.lock = storeText.substring(0, 1); this.state.lock = parseInt(storeText.substring(0, 1));
this.secret.cipher = storeText.substring(2, 34) this.secret.cipher = storeText.substring(2, 34)
} }
if (this.state.lock == "1") { if (this.state.lock == 1) {
this.show = false; this.show = false;
this.noteForm.text = "*****lock*****"; this.noteForm.text = "*****lock*****";
return; return;
@@ -336,8 +318,8 @@ export default {
let storeText = storage.local.getText(this.secret.storeKey + '.text'); let storeText = storage.local.getText(this.secret.storeKey + '.text');
if (null != storeText && '' != storeText) { if (null != storeText && '' != storeText) {
let lock = storeText.substring(0, 1); let lock = parseInt(storeText.substring(0, 1));
if (lock == "1") { if (lock == 1) {
alert("note is encrypt!"); alert("note is encrypt!");
return; return;
} }
@@ -350,9 +332,9 @@ export default {
let plainText = aesDecrypt(storeText, secretKey); let plainText = aesDecrypt(storeText, secretKey);
if (plainText.startsWith("FLAGNOTE#")) { if (plainText.startsWith("FLAGNOTE#")) {
this.noteForm.text = plainText.substring(9); this.noteForm.text = plainText.substring(9);
this.state.lock = "0"; this.state.lock = 0;
} else { } else {
if (this.state.lock == "1") { if (this.state.lock == 1) {
alert("password is wrong!") alert("password is wrong!")
} }
} }
@@ -396,28 +378,28 @@ export default {
return saveNote(this.noteForm); return saveNote(this.noteForm);
}, },
submitNote() { submitNote() {
if (this.state.locking == "1") { if (this.state.locking == 1) {
return; return;
} }
this.state.locking = "1"; this.state.locking = 1;
this.loading = true; this.loading = true;
this.save().then(res => { this.save().then(res => {
if (res) { if (res) {
location.reload(); location.reload();
this.state.locking = "0"; this.state.locking = 0;
} }
}); });
}, },
hideNote() { hideNote() {
if (this.state.locking == "1") { if (this.state.locking == 1) {
return; return;
} }
this.state.locking = "1"; this.state.locking = 1;
if (this.state.lock == "1") { if (this.state.lock == 1) {
this.state.locking = "0"; this.state.locking = 0;
return; return;
} }
@@ -427,7 +409,7 @@ export default {
setStoreText(this.noteForm.text, this.secret, password); setStoreText(this.noteForm.text, this.secret, password);
this.state.lock = "1" this.state.lock = 1
this.noteForm.text = '******lock******'; this.noteForm.text = '******lock******';
@@ -439,20 +421,20 @@ export default {
noteText.selectionEnd = 1; noteText.selectionEnd = 1;
this.show = false; this.show = false;
this.state.locking = "0"; this.state.locking = 0;
}, },
showNote() { showNote() {
if (this.state.locking == "1") { if (this.state.locking == 1) {
return; return;
} }
this.state.locking = "1"; this.state.locking = 1;
if (this.state.lock == "0") { if (this.state.lock == 0) {
this.state.locking = "0"; this.state.locking = 0;
return; return;
} }
@@ -460,7 +442,7 @@ export default {
let storeText = storage.local.getText(this.secret.storeKey + '.text'); let storeText = storage.local.getText(this.secret.storeKey + '.text');
if (storeText) { if (storeText) {
let lock = storeText.substring(0, 1); let lock = parseInt(storeText.substring(0, 1));
if (!lock) { if (!lock) {
alert("note is not encrypt!"); alert("note is not encrypt!");

View File

@@ -123,7 +123,7 @@ button span {
<Button-group size="large"> <Button-group size="large">
<Button type="error" style="margin-left:0px; border-radius: 0px;font-size: 24px;" <Button type="error" style="margin-left:0px; border-radius: 0px;font-size: 24px;"
@click="createNote()" icon="md-add"></Button> @click="createNote()" icon="md-add"></Button>
<Button type="error" style="margin-left:0px; border-radius: 0px;font-size: 24px;" <Button type="error" style="margin-left:5px; border-radius: 0px;font-size: 24px;"
@click="dropNote()" icon="md-trash"></Button> @click="dropNote()" icon="md-trash"></Button>
</Button-group> </Button-group>
</div> </div>
@@ -207,7 +207,7 @@ export default {
escapeText: '', escapeText: '',
key: '', key: '',
md5: '', md5: '',
lock: '0', lock: 0,
ttl: 3600, ttl: 3600,
ttlDesc: '', ttlDesc: '',
}, },
@@ -217,9 +217,11 @@ export default {
cipher: '', cipher: '',
}, },
state: { state: {
lock: '0', lock: 0,
locking: '0', locking: 0,
commited: '0' initTime: null,
initTtl: null,
commited: 0
} }
} }
}, },
@@ -230,6 +232,8 @@ export default {
let noteMeta = storage.session.getObject(storeKey + '.noteMeta'); let noteMeta = storage.session.getObject(storeKey + '.noteMeta');
if (noteMeta) { if (noteMeta) {
this.state.lock = noteMeta.lock; this.state.lock = noteMeta.lock;
this.state.initTime = new Date().getTime();
this.state.initTtl = noteMeta.ttl;
this.secret.cipher = noteMeta.cipher; this.secret.cipher = noteMeta.cipher;
this.noteForm.md5 = noteMeta.md5; this.noteForm.md5 = noteMeta.md5;
this.noteForm.ttl = noteMeta.ttl; this.noteForm.ttl = noteMeta.ttl;
@@ -246,24 +250,25 @@ export default {
window.setInterval(function () { window.setInterval(function () {
let ittl = parseInt(that.noteForm.ttl / 1000); let ittl = parseInt(that.noteForm.ttl / 1000);
let mins = parseInt(ittl / 60); let mins = parseInt(ittl / 60);
if (mins < 10) {
mins = "0" + mins;
}
if (mins < 0) { if (mins < 0) {
mins = "00"; mins = "00";
} else if (mins < 10) {
mins = "0" + mins;
} }
let seds = parseInt(ittl % 60); let seds = parseInt(ittl % 60);
if (seds < 10) {
seds = "0" + seds;
}
if (seds < 0) { if (seds < 0) {
seds = "00"; seds = "00";
} else if (seds < 10) {
seds = "0" + seds;
} }
that.noteForm.ttlDesc = mins + ":" + seds; that.noteForm.ttlDesc = mins + ":" + seds;
that.noteForm.ttl -= 1000; that.noteForm.ttl = that.state.initTtl - (new Date().getTime() - that.state.initTime);
if (that.noteForm.ttl <= 0) { if (that.noteForm.ttl <= 0) {
that.storage.local.delete(that.secret.storeKey + '.text'); storage.local.delete(that.secret.storeKey + '.text');
that.storage.session.delete(that.secret.storeKey + '.keyMeta'); storage.session.delete(that.secret.storeKey + '.keyMeta');
location.reload(); location.reload();
} }
}, 1000) }, 1000)
@@ -290,7 +295,7 @@ export default {
let password; let password;
if (this.noteForm.lock == "1") { if (this.noteForm.lock == 1) {
password = "123456" password = "123456"
} }