Permalink
Browse files

add keyboard shortcut command + /

  • Loading branch information...
1 parent d5a1016 commit 08f4efc0eb37708b6bd3cb41394abaca1be61097 @nnutter committed Aug 4, 2011
Showing with 52 additions and 35 deletions.
  1. +43 −35 Hashed.safariextension/Global.html
  2. +9 −0 Hashed.safariextension/InjectEnd.js
@@ -13,43 +13,51 @@
-->
<html>
- <head>
- <title>Global</title>
- <script src="PwdHash/md5.js" type="text/javascript"></script>
- <script src="PwdHash/hashed-password.js" type="text/javascript"></script>
- <script src="PwdHash/domain-extractor.js" type="text/javascript"></script>
- <script type="text/javascript">
- function generatePwdHash(event) {
- if (event.command === "generatepwdhash") {
- var URL = event.target.browserWindow.activeTab.url;
- if (!URL) return;
-
- var masterPassword = safari.extension.secureSettings.masterPassword;
- if (!masterPassword) {
- event.target.browserWindow.activeTab.page.dispatchMessage("missingMasterPassword");
- return;
- }
-
- var domain = (new SPH_DomainExtractor()).extractDomain(URL);
- if (!domain) return;
-
- var result = new String(new SPH_HashedPassword(masterPassword, domain));
- if (!result) return;
-
- event.target.browserWindow.activeTab.page.dispatchMessage("pwdHash", result.valueOf());
- //event.target.browserWindow.activeTab.url = domain + '-' + result;
+<head>
+ <title>Global</title>
+ <script src="PwdHash/md5.js" type="text/javascript"></script>
+ <script src="PwdHash/hashed-password.js" type="text/javascript"></script>
+ <script src="PwdHash/domain-extractor.js" type="text/javascript"></script>
+ <script type="text/javascript">
+ function generatePwdHash(event) {
+ if (event.command === "generatepwdhash" || event.name === "pleaseGeneratePwdHash") {
+ var URL = event.target.browserWindow.activeTab.url;
+ if (!URL) return;
+
+ var masterPassword = safari.extension.secureSettings.masterPassword;
+ if (!masterPassword) {
+ event.target.browserWindow.activeTab.page.dispatchMessage("missingMasterPassword");
+ return;
}
+
+ var domain = (new SPH_DomainExtractor()).extractDomain(URL);
+ if (!domain) return;
+
+ var result = new String(new SPH_HashedPassword(masterPassword, domain));
+ if (!result) return;
+
+ event.target.browserWindow.activeTab.page.dispatchMessage("pwdHash", result.valueOf());
}
-function canGeneratePwdHash(event) {
- if (event.command === "generatepwdhash") {
- var URL = event.target.browserWindow.activeTab.url;
- var masterPassword = safari.extension.settings.masterPassword;
- event.target.disabled = false;
- }
-}
-safari.application.addEventListener("command", generatePwdHash, false);
-safari.application.addEventListener("validate", canGeneratePwdHash, false);
-</script>
+ }
+
+ function canGeneratePwdHash(event) {
+ if (event.command === "generatepwdhash") {
+ var URL = event.target.browserWindow.activeTab.url;
+ var masterPassword = safari.extension.settings.masterPassword;
+ event.target.disabled = false;
+ }
+ }
+
+ function receiveMessage(event) {
+ if (event.name === "pleaseGeneratePwdHash") {
+ generatePwdHash(event);
+ }
+ }
+
+ safari.application.addEventListener("command", generatePwdHash, false);
+ safari.application.addEventListener("validate", canGeneratePwdHash, false);
+ safari.application.addEventListener("message", receiveMessage, false);
+ </script>
</head>
<body>
</body>
@@ -40,5 +40,14 @@ if (window.top === window) {
alert("You must set a Master Password in Hashed for Safari's extension settings.");
}
+
+ function handleKeyboardShortcut(event) {
+ if (event && event.metaKey && event.keyCode == 92) {
+ safari.self.tab.dispatchMessage("pleaseGeneratePwdHash");
+ }
+ }
+
+ document.onkeypress = handleKeyboardShortcut;
+
safari.self.addEventListener("message", receivePwdHash, false);
}

0 comments on commit 08f4efc

Please sign in to comment.