Green SSL Password Fields

Colors the passwd field green if secure, red if not

  1. // ==UserScript==
  2. // @name Green SSL Password Fields
  3. // @namespace http://khopis.com/scripts
  4. // @description Colors the passwd field green if secure, red if not
  5. // @include *
  6. // @icon http://img402.imageshack.us/img402/3606/securecubegreen.png
  7. // @author Adam Katz <scriptsATkhopiscom>
  8. // @version 0.3+20120322
  9. // @copyright 2010-2012 by Adam Katz
  10. // @license AGPL v3+
  11. // @licstart The following is the entire license notice for this script.
  12. /*
  13. * Copyright (C) 2010-2012 Adam Katz
  14. *
  15. * This program is free software: you can redistribute it and/or modify it
  16. * under the terms of the GNU Affero General Public License as published by
  17. * the Free Software Foundation, either version 3 of the License, or (at your
  18. * option) any later version. This program is distributed in the hope that
  19. * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  20. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License at <http://www.gnu.org/licenses>.
  22. */
  23. // @licend The above is the entire license notice for this script.
  24. // ==/UserScript==
  25.  
  26. var ssl_bg = "#cfb"; // green background for SSL-protected password fields
  27. var plain_bg = "#fcb"; // red background for non-SSL-protected password fields
  28.  
  29. var rel_ssl = rel_plain = '';
  30. var pw_field = 'input[type="password"]';
  31.  
  32. var forms = document.getElementsByTagName("form");
  33.  
  34. // For each form, on each password field, note the domain it submits to
  35. // (unless it's the same domain as the current page). TODO: strip subdomains
  36. for (var f=0, fl=forms.length; f < fl; f++) {
  37. var submitDom = forms[f].action.match(/^https?:..([^\/]+)/i);
  38.  
  39. var pws = document.evaluate("//input[@type='password']", forms[f], null,
  40. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  41.  
  42. if (!pws || !submitDom || !submitDom[1] || submitDom[1] == location.host)
  43. { continue; }
  44.  
  45. for (var p=0, pl=pws.snapshotLength; p < pl; p++) {
  46. pws.snapshotItem(p).title = "Form submits to '" + submitDom[1] + "' "
  47. + pws.snapshotItem(p).title;
  48. }
  49. }
  50.  
  51. function cssbg(sel, bgcolor) {
  52. return sel + pw_field
  53. + ' { color:#000; background:' + bgcolor + '!important; }\n';
  54. }
  55.  
  56. if (location.protocol == "https:") { rel_ssl = pw_field + ", "; }
  57. else { rel_plain = pw_field + ", "; }
  58.  
  59. var style = document.createElement("style");
  60. style.type = "text/css";
  61. style.appendChild(document.createTextNode(
  62. cssbg(rel_ssl + 'form[action^="https://"] ', ssl_bg) +
  63. cssbg(rel_plain + 'form[action^="http://"] ', plain_bg)
  64. ));
  65. var head = document.getElementsByTagName("head");
  66. head && head[0] ? head = head[0] : head = document.body;
  67. head.appendChild(style);