Skip to content

Commit f059a98

Browse files
authored
Merge pull request #61 from dmuth/fix-webpack-file-size
Fix webpack file size
2 parents c8433ad + 5e74c3d commit f059a98

File tree

10 files changed

+165
-50
lines changed

10 files changed

+165
-50
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ A local webserver can be set up by running `npm install http-server -g` to insta
6262
- `http-server`
6363
- `vim src/lib.js src/index.js`
6464
- Be sure to check in your changes before the next step!
65+
- `ngrok http 8080` - Stand up an Ngrok endpoint
66+
- Paste that URL into [my QR Code Generator](https://httpbin.dmuth.org/qrcode/)
67+
- Scan the generated URL code on my iPhone and test from there.
6568
- Testing
6669
- `rm -fv src/index.js && git co src/index.js` - Get the new SHA1 hash that will be displayed in debug messages.
6770
- The hash can be crosschecked with the results of `git hash-object src/index.js`

assets/css/dice.css

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11

22
.die {
3-
width: 100px;
4-
height: 100px;
5-
background: #ff1111;
6-
border-radius: 10px;
3+
width: 100px;
4+
height: 100px;
5+
background: #ff1111;
6+
border-radius: 10px;
77
margin-left: 20px;
88
margin-bottom: 20px;
99
}
1010

1111
.dot {
12-
position:absolute;
13-
width: 18px;
14-
height: 18px;
15-
border-radius: 18px;
16-
background: white;
17-
box-shadow: inset 5px 0 10px white;
12+
position:absolute;
13+
width: 18px;
14+
height: 18px;
15+
border-radius: 18px;
16+
background: white;
17+
box-shadow: inset 5px 0 10px white;
1818
}
1919

2020
.dot.center {
2121
/* Orders of margins are: top right bottom left */
22-
margin: 39px 0 0 41px;
22+
margin: 39px 0 0 41px;
2323
}
2424

2525
.dot.dtop {
26-
margin-top: 14px;
26+
margin-top: 14px;
2727
}
2828

2929
.dot.dleft {
30-
margin-left: 65px;
30+
margin-left: 65px;
3131
}
3232

3333
.dot.dright {
34-
margin-left: 16px;
34+
margin-left: 16px;
3535
}
3636

3737
.dot.dbottom {
38-
margin-top: 63px;
38+
margin-top: 63px;
3939
}
4040

4141
.dot.center.dleft {
42-
margin: 38px 0 0 16px;
42+
margin: 38px 0 0 16px;
4343
}
4444

4545
.dot.center.dright {
46-
margin: 38px 0 0 65px;
46+
margin: 38px 0 0 65px;
4747
}
4848

4949
.responsive {

dist/bundle.js.LICENSE.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* @preserve
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2013-2018 Petka Antonov
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
*/
25+
26+
/*!
27+
* The buffer module from node.js, for the browser.
28+
*
29+
* @author Feross Aboukhadijeh <https://feross.org>
30+
* @license MIT
31+
*/
32+
33+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
34+
35+
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */

index.html

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ <h1>Diceware Password Generator</h1>
9797
<div class="results_words_key" >Your words are: </div>
9898
<div class="results_words_value" data-test="results-words" ></div>
9999

100-
<div class="results_phrase_key" >Your passphrase is: </div>
100+
<div class="results_phrase_key" >Your passphrase is:</div>
101101
<div class="results_phrase_value" data-test="results-phrase" ></div>
102+
103+
<button type="button" class="btn btn-primary copy-button">
104+
<span class="glyphicon glyphicon-copy"></span> Copy to Clipboard
105+
</button>
102106

103107
<div class="results_num_possible_key" ># of possible passwords: </div>
104108
<div class="results_num_possible_value" ></div>
@@ -217,7 +221,6 @@ <h3>FAQ: Why not use 1Password or BitKeeper or something similar?</h3>
217221
By all means, feel free to do so. <a href="https://1password.com/">1Password</a> is an excellent product and I highly recommend it.
218222
That said, there's no reason that Diceware cannot be used concurrently with a password manager.
219223
But I <em>also</em> happen to like passwords I can remember. :-)
220-
</p>
221224

222225
If you want the absolute highest levels of password security, consider using <a href="https://strongboxsafe.com/">Strongbox</a>. One neat thing about Strongbox is that it comes with a built-in Diceware client!</p>
223226

@@ -406,7 +409,7 @@ <h3>FAQ: Are there any other Diceware websites out there?</h3>
406409

407410
<ul>
408411
<li>
409-
<a href="https://strongphrase.net/">https://strongphrase.net/</a> - StrongPhrase.net This website goes into more detail on password strengths and efforts requires to crack particular passwords.
412+
<a href="https://strongphrase.net/">https://strongphrase.net/</a> - StrongPhrase.net This website goes into more detail on password strengths and efforts requires to crack particular passwords. Also, the author of StrongPhrase <a href="https://github.com/dmuth/diceware/pull/57">contributed code for the clipboard feature</a>!
410413
</li>
411414
</ul>
412415

@@ -464,7 +467,21 @@ <h3>Who built this? / Contact</h3>
464467
<!-- Include all compiled plugins (below), or include individual files as needed -->
465468
<script src="./dist/bootstrap.min.js"></script>
466469

467-
<script src="./dist/bundle.js"></script>
470+
<script>
471+
472+
// If "debug" is in GET method data, add the current time to not use cached Javascript.
473+
const queryString = window.location.search;
474+
const urlParams = new URLSearchParams(queryString);
475+
const debug = location.search.indexOf("debug");
476+
477+
if (urlParams.get("debug")) {
478+
console.log("Debugging set, busting Javascript cache...");
479+
document.write('<script src="./dist/bundle.js?v=' + new Date().getTime() + '"><\/script>');
480+
} else {
481+
document.write('<script src="./dist/bundle.js"><\/script>');
482+
}
483+
484+
</script>
468485

469486
</body>
470487
</html>

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"scripts": {
1010
"test": "mocha ./tests/test.js",
1111
"clean": "rm -rfv dist/*bundle.js* node_modules package-lock.json",
12-
"build": "npm install; webpack --mode production",
13-
"dev-build": "npm install; webpack --watch --mode development",
12+
"build": "webpack --mode production",
13+
"dev-build": "webpack --watch --mode development",
1414
"release-build": "rm -fv diceware.zip ; zip -r ../diceware.zip *; mv ../diceware.zip ."
1515
},
1616
"repository": {

src/display.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
let lib = require("./lib.js")();
42

53
// Functions that relate to rolling dice
@@ -145,8 +143,20 @@ function results(cb) {
145143
jQuery(".results_words_value").hide().clone().appendTo(".results");
146144
jQuery(".results").append("<br clear=\"all\" />");
147145

148-
jQuery(".results_phrase_key").hide().clone().appendTo(".results");
149-
jQuery(".results_phrase_value").hide().clone().appendTo(".results");
146+
// Create a container for phrase and copy button
147+
jQuery("<div class='phrase-container' style='margin-bottom: 15px;'></div>").appendTo(".results");
148+
149+
// Add phrase key and value to container
150+
jQuery(".results_phrase_key").hide().clone().appendTo(".results .phrase-container");
151+
jQuery(".results_phrase_value").hide().clone().appendTo(".results .phrase-container");
152+
153+
// Clone the copy button directly from source
154+
const copyBtn = jQuery(".source .copy-button").clone();
155+
jQuery("<div class='copy-button-container' style='text-align: center; margin-top: 10px;'></div>")
156+
.hide()
157+
.append(copyBtn)
158+
.appendTo(".results .phrase-container");
159+
150160
jQuery(".results").append("<br clear=\"all\" />");
151161

152162
jQuery(".results_num_possible_key").hide().clone().appendTo(".results");
@@ -155,13 +165,15 @@ function results(cb) {
155165
jQuery(".results .results_words_key").fadeIn(500).promise().then(function() {
156166
return(jQuery(".results .results_words_value").fadeIn(500).promise())
157167
}).then(function() {
158-
return(jQuery(".results .results_phrase_key").fadeIn(400).promise());
168+
return(jQuery(".results .results_phrase_key").fadeIn(400).promise());
169+
}).then(function() {
170+
return(jQuery(".results .results_phrase_value").fadeIn(400).promise());
159171
}).then(function() {
160-
return(jQuery(".results .results_phrase_value").fadeIn(400).promise());
172+
return(jQuery(".results .copy-button-container").fadeIn(400).promise());
161173
}).then(function() {
162-
return(jQuery(".results .results_num_possible_key").fadeIn(300).promise());
174+
return(jQuery(".results .results_num_possible_key").fadeIn(300).promise());
163175
}).then(function() {
164-
return(jQuery(".results .results_num_possible_value").fadeIn(300).promise());
176+
return(jQuery(".results .results_num_possible_value").fadeIn(300).promise());
165177
}).then(function() {
166178
if (cb) {
167179
cb();

src/index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ window.Diceware.num_dice_per_roll = 5;
3434
* Set the handlers
3535
*/
3636
function set_handlers() {
37-
3837
//
3938
// Handler to mark the clicked number of dice button as active.
4039
//
@@ -45,6 +44,21 @@ function set_handlers() {
4544

4645
jQuery("#roll_dice").on("click", display.rollDiceHandler);
4746

47+
// Use event delegation for copy button
48+
console.log("Setting up copy button handler...");
49+
jQuery(document).on("click", ".copy-button", async function() {
50+
console.log("Copy button clicked!");
51+
const passphrase = jQuery('.results .results_phrase_value').text();
52+
console.log("Passphrase from the element: " + passphrase);
53+
try {
54+
await util.copyToClipboard(passphrase);
55+
console.log("Done copying!");
56+
} catch (err) {
57+
console.error('Failed to copy:', err);
58+
}
59+
});
60+
console.log("Copy button handler setup complete");
61+
4862
} // End of set_handlers()
4963

5064

@@ -73,7 +87,7 @@ function run_preflight_checks() {
7387
*/
7488
function go() {
7589

76-
console.log("Thanks for checking out my code! You can find the Git repo at https://github.com/dmuth/diceware, my blog at https://www.dmuth.org/, or you can bug me on Twitter at https://twitter.com/dmuth");
90+
console.log("Thanks for checking out my code! You can find the Git repo at https://github.com/dmuth/diceware, my blog at https://www.dmuth.org/, or you can bug me on Bsky at https://dmuth.bsky.social/");
7791

7892
console.log("Version: $Id$");
7993

src/util.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
let Promise = require("bluebird");
42

53
module.exports = function(arg) {
@@ -11,6 +9,7 @@ module.exports = function(arg) {
119
is_mobile: is_mobile,
1210
get_word: get_word,
1311
extract_get_data: extract_get_data,
12+
copyToClipboard: copyToClipboard,
1413
});
1514

1615
}
@@ -90,5 +89,29 @@ function extract_get_data(get_data) {
9089

9190
} // End of extractGetData()
9291

92+
/**
93+
* Copy text to clipboard and provide visual feedback
94+
*
95+
* @param {string} text The text to copy
96+
* @return {Promise} Resolves when copying is complete
97+
*/
98+
async function copyToClipboard(text) {
99+
try {
100+
await navigator.clipboard.writeText(text);
101+
const $copyBtn = $('.copy-button');
102+
const originalText = $copyBtn.html();
103+
104+
$copyBtn
105+
.html('<span class="glyphicon glyphicon-ok"></span> Copied!')
106+
.fadeIn();
107+
108+
setTimeout(() => {
109+
$copyBtn.html(originalText);
110+
}, 5000);
111+
} catch (err) {
112+
console.error('Failed to copy text:', err);
113+
}
114+
}
115+
93116

94117

webpack.config.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
1-
21
//
32
// Use the path module so that this will work on Windows systems
43
//
5-
var path = require('path');
4+
const path = require('path');
65

76
const webpack = require('webpack')
87

98
//
109
// Compile main.js (and its dependencies) into dist/bundle.js.
1110
//
12-
module.exports = {
11+
module.exports = (env, argv) => ({
12+
mode: argv.mode || 'development', // Default to development mode
1313
entry: './src/index.js',
1414
output: {
1515
filename: 'bundle.js',
16-
path: path.resolve(__dirname, 'dist')
16+
path: path.resolve(__dirname, 'dist'),
17+
},
18+
// Use source maps only in development
19+
devtool: argv.mode === 'development' ? 'eval-source-map' : false,
20+
watch: argv.mode === 'development', // Enable watch only in development
21+
watchOptions: {
22+
ignored: /node_modules/,
23+
poll: 1000, // Check for changes every second
24+
},
25+
optimization: {
26+
moduleIds: 'named', // Makes it easier to debug
1727
},
1828
resolve: {
1929
fallback: {
2030
"crypto": require.resolve("crypto-browserify"),
31+
"buffer": require.resolve("buffer/"),
2132
"stream": require.resolve("stream-browserify"),
22-
"vm": require.resolve("vm-browserify")
33+
"vm": require.resolve("vm-browserify"),
2334
}
2435
},
2536
plugins: [
@@ -28,5 +39,5 @@ module.exports = {
2839
process: 'process/browser.js'
2940
})
3041
]
31-
};
42+
});
3243

0 commit comments

Comments
 (0)