commit c403ca036bde25300af27674f5877b8c21b566ea Author: s2 Date: Wed Nov 15 16:56:03 2017 +0100 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..c4b6e6d --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# pwgen + +## What it does ## + +Simply generate a password and copy it to the clipboard diff --git a/icons/lock-32.png b/icons/lock-32.png new file mode 100644 index 0000000..66cb06e Binary files /dev/null and b/icons/lock-32.png differ diff --git a/icons/lock-48.png b/icons/lock-48.png new file mode 100644 index 0000000..cbc31db Binary files /dev/null and b/icons/lock-48.png differ diff --git a/icons/lock.png b/icons/lock.png new file mode 100644 index 0000000..6ea1ca9 Binary files /dev/null and b/icons/lock.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..532f447 --- /dev/null +++ b/manifest.json @@ -0,0 +1,24 @@ +{ + "description": "Just a toolbar button that generates a password and copies it to your clipboard.", + "manifest_version": 2, + "name": "pwgen", + "version": "1.0", + "homepage_url": "http://www.google.com", + "icons": { + "48": "icons/lock-48.png" + }, + "browser_action": { + "default_icon": "icons/lock-32.png", + "theme_icons": [{ + "light": "icons/lock-32-light.png", + "dark": "icons/lock-32.png", + "size": 32 + }], + "default_title": "pwgen", + "default_popup": "popup/pwgen.html" + }, + "permissions": [ + "clipboardWrite", + "storage" + ] +} diff --git a/popup/pwgen.css b/popup/pwgen.css new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/popup/pwgen.css @@ -0,0 +1 @@ + diff --git a/popup/pwgen.html b/popup/pwgen.html new file mode 100644 index 0000000..d20db4b --- /dev/null +++ b/popup/pwgen.html @@ -0,0 +1,26 @@ + + + + + + + + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + + + diff --git a/popup/pwgen.js b/popup/pwgen.js new file mode 100644 index 0000000..036976d --- /dev/null +++ b/popup/pwgen.js @@ -0,0 +1,48 @@ +function randPassword(length, includeSpecial) { + let pwdChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"; + if (includeSpecial) { + pwdChars += '°^!"§$%&/()=?`´\}][{²³€|<>-.,;:*+_'; + } + let randPassword = Array(length).fill(pwdChars).map(function(x) { + return x[Math.floor(Math.random() * x.length)] + }).join(''); + return randPassword; +} + +function getParams() { + return { + length: parseInt(document.getElementById('length').value), + special: document.getElementById('special').checked + } +} + +function loadOptions() { + return browser.storage.local.get({ + length: 14, + special: true + }); +} + +function saveOptions(options) { + return browser.storage.local.set(options); +} + +document.getElementById('new').addEventListener('click', (ev) => { + ev.preventDefault(); + var params = getParams(); + document.getElementById('pw').value = randPassword(params.length, params.special); + saveOptions(params); +}); + +document.getElementById('copy').addEventListener('click', (ev) => { + ev.preventDefault(); + var copyText = document.getElementById('pw'); + copyText.select(); + document.execCommand('copy'); +}); + +loadOptions().then((options) => { + document.getElementById('length').value = options.length; + document.getElementById('special').checked = options.special; + document.getElementById('pw').value = randPassword(getParams().length, getParams().special); +});