Skip to content

Commit

Permalink
尝试通过播放无声音频保证可以在后台全速算号
Browse files Browse the repository at this point in the history
  • Loading branch information
TransparentLC committed Jul 24, 2024
1 parent 37fe8ac commit 02610a9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
<li><a href="https://blog.dejavu.moe/posts/the-scientific-vanity-pgp-counting-guide/">某科学的 PGP 算号指南</a></li>
</ul>
<p>密钥使用 <a href="https://openpgpjs.org/">OpenPGP.js</a> 在浏览器中生成,不会发送到其他地方。如果仍然担心这一点,可以检查源代码、查看浏览器开发者工具的“网络”部分、或在页面加载完成后断网使用。</p>
<p>注意:浏览器可能会限制在后台标签页中运行的内容,因此算号时请<strong>避免切换到其它标签页或将浏览器窗口最小化</strong>,否则会严重影响算号速度。作为替代,你可以将这个标签页拖出成为一个单独的窗口,使用各类工具将窗口置顶,然后拖到屏幕边缘。</p>
<hr>
<div class="form-group">
<label>密钥类型</label>
Expand Down
10 changes: 10 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from 'openpgp/lightweight';
import { createVanityKey } from './vanity-key.ts';
import tadaData from './tada.ogg?inline';
import silenceData from './near-silence.ogg?inline';
import {
EllipticCurveName,
GenerateKeyOptions,
Expand All @@ -17,6 +18,13 @@ import 'terminal.css';

const tada = new Audio(tadaData);

// 通过播放音频阻止浏览器降低setTimeout的频率
// 完全静音的音频是没有效果的……
// ffmpeg -f lavfi -i "sine=frequency=1:duration=1" -c:a libopus -ar 8k -b:a 1k -movflags +faststart -fflags +bitexact -map_metadata -1 -dn near-silence.ogg
const silence = new Audio(silenceData);
silence.volume = .01;
silence.loop = true;

const app: {
keyType: EllipticCurveName | '2048' | '3072' | '4096',
userIDInput: UserID,
Expand Down Expand Up @@ -131,6 +139,7 @@ const app: {
this.hashCount = 0;
this.runningTime = 0;
this.running = true;
silence.play();
try {
const options: GenerateKeyOptions = {
userIDs: this.userID,
Expand Down Expand Up @@ -189,6 +198,7 @@ const app: {
alert(err);
} finally {
this.running = false;
silence.pause();
}
},

Expand Down
Binary file added src/near-silence.ogg
Binary file not shown.

0 comments on commit 02610a9

Please sign in to comment.