-
Notifications
You must be signed in to change notification settings - Fork 1
/
decrypt_progress_bar.js
72 lines (54 loc) · 2.05 KB
/
decrypt_progress_bar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/** @fileoverview A progress bar for the decryption process. */
/** @constructor */
keepasschrome.DecryptProgressBar = function() {
/** @private {number} */
this.totalEncryptionRounds_;
/** @private {number} */
this.completedEncryptionRounds_ = 0;
/** @private {!Element} */
this.progressBarInnerElement_;
/** @private {number} */
this.progressBarWidth_;
};
/**
* Renders itself at the end of the parent element.
* @param {!Element} parentElement The parent of this progress bar.
*/
keepasschrome.DecryptProgressBar.prototype.render = function(parentElement) {
var progressBarElement = document.createElement('span');
progressBarElement.classList.add('decrypt-progress-bar');
this.progressBarInnerElement_ = document.createElement('span');
this.progressBarInnerElement_.classList.add('decrypt-progress-bar-inner');
progressBarElement.appendChild(this.progressBarInnerElement_);
parentElement.appendChild(progressBarElement);
this.progressBarWidth_ =
parseInt(window.getComputedStyle(progressBarElement).width, 10);
};
/**
* Sets the number of times to encrypt the password to generate the decryption
* key.
* @param {number} totalEncryptionRounds The total number of encryption rounds.
*/
keepasschrome.DecryptProgressBar.prototype.setTotalEncryptionRounds = function(
totalEncryptionRounds) {
this.totalEncryptionRounds_ = totalEncryptionRounds;
};
/** Call when a single encryption round is complete. */
keepasschrome.DecryptProgressBar.prototype.encryptionRoundComplete =
function() {
this.completedEncryptionRounds_++;
this.maybeUpdateProgressBar_();
};
/**
* Decides whether or not to update the progress bar (doesn't update for every
* round complete becasue that's slow) and updates it.
* @private
*/
keepasschrome.DecryptProgressBar.prototype.maybeUpdateProgressBar_ =
function() {
if (this.completedEncryptionRounds_ % 250 === 0) {
this.progressBarInnerElement_.style.width =
(this.completedEncryptionRounds_ / this.totalEncryptionRounds_) *
this.progressBarWidth_ + 'px';
}
};