Skip to content

Commit

Permalink
支持使用ntfy发送提醒
Browse files Browse the repository at this point in the history
  • Loading branch information
TransparentLC committed Jul 17, 2024
1 parent 08bcd6b commit 9f73114
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@
<button @click="subkeyCombine" class="btn btn-block btn-ghost btn-primary">保存合并后的私钥</button>
</details>
<div class="form-group">
<input v-model="notificationSfx" type="checkbox">算号成功后播放提示音
<input v-model="notification.sfx" type="checkbox">算号成功后播放提示音
<br>
<input v-model="notification.ntfy" type="checkbox">算号成功后使用 <a href="https://ntfy.sh/app">ntfy</a> 发送通知 <input v-model="notification.ntfyTopic" type="text" style="width:unset;padding:unset" placeholder="主题名称" pattern="[\-_A-Za-z\d]{1,64}">
<br>
<input v-model="nonstopMode" type="checkbox">不间断算号(在控制台中查看先前生成的密钥)
</div>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"preview": "vite preview"
},
"devDependencies": {
"@types/node": "^20.14.10",
"@types/node": "^20.14.11",
"rollup-plugin-visualizer": "^5.12.0",
"typescript": "^5.2.2",
"vite": "^5.3.1",
"vite": "^5.3.4",
"vite-plugin-html": "^3.2.2"
},
"dependencies": {
Expand Down
34 changes: 28 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ const app: {
patternNumber: string,
patternLength: number,
vanitySubkey: boolean,
notificationSfx: boolean,
notification: {
sfx: boolean,
ntfy: boolean,
ntfyTopic: string,
},
nonstopMode: boolean,
backTime: number,
estimatedHashCount: bigint,
Expand Down Expand Up @@ -60,7 +64,11 @@ const app: {
patternNumber: '0123456789ABCDEFXXXX'[Math.floor(Math.random() * 20)],
patternLength: 6 + Math.floor(Math.random() * 3),
vanitySubkey: false,
notificationSfx: false,
notification: {
sfx: false,
ntfy: false,
ntfyTopic: '',
},
nonstopMode: false,
get backTime() {
return this.thread * this.iteration;
Expand Down Expand Up @@ -158,12 +166,26 @@ const app: {
);
if (generatedKey) {
this.generatedKey = generatedKey;
console.log(generatedKey.privateKey.armor());
console.log('Created:', generatedKey.publicKey.getCreationTime().toISOString());
console.log('Fingerprint:', this.formatFingerprint(generatedKey.publicKey.getFingerprint()));
if (this.notificationSfx) {
const armor = generatedKey.privateKey.armor();
const created = generatedKey.publicKey.getCreationTime().toISOString();
const fingerprint = this.formatFingerprint(generatedKey.publicKey.getFingerprint());
console.log(armor);
console.log('Created:', created);
console.log('Fingerprint:', fingerprint);
if (this.notification.sfx) {
tada.play();
}
if (this.notification.ntfy && this.notification.ntfyTopic) {
fetch(`https://ntfy.sh/`, {
method: 'POST',
body: JSON.stringify({
topic: this.notification.ntfyTopic,
markdown: true,
title: 'webgl-vanity-gpg 计算出了新的密钥!',
message: 'Fingerprint: `' + fingerprint + '`\n\nCreated: ' + created + '\n\n请回到打开的 webgl-vanity-gpg 页面,在页面上/控制台中查看生成的密钥。',
}),
});
}
}
} while (this.running && this.nonstopMode);
} catch (err) {
Expand Down

0 comments on commit 9f73114

Please sign in to comment.