passwdsave.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. (function () {
  2. var ask = true; /*true改为false默认记住不询问*/
  3. function go() {
  4. var allInput = document.querySelectorAll("input");
  5. var allShownInput = [];
  6. var name;
  7. var pass;
  8. for (var i = 0; i < allInput.length; i++) {
  9. if (allInput[i].offsetWidth != 0) {
  10. if (allInput[i].hasAttribute("type")) {
  11. if ((allInput[i].getAttribute("type") == "password") || (allInput[i].getAttribute("type") == "text"))
  12. allShownInput.push(allInput[i]);
  13. } else
  14. allShownInput.push(allInput[i]);
  15. }
  16. }
  17. for (i = 1; i < allShownInput.length; i++) {
  18. if (allShownInput[i].type == "password") {
  19. pass = allShownInput[i];
  20. name = allShownInput[i - 1];
  21. }
  22. }
  23. if ((!pass) || (!name)) return;
  24. if (ask) {
  25. if (!localStorage.xxM_ifrm) {
  26. if (confirm("记住本站密码吗?")) { /*这里可以更改询问语句*/
  27. localStorage.setItem("xxM_ifrm", "true");
  28. localStorage.xxM_ifrm = "true";
  29. } else {
  30. localStorage.setItem("xxM_ifrm", "false");
  31. return;
  32. }
  33. }
  34. if (localStorage.xxM_ifrm == "false") {
  35. return;
  36. }
  37. }
  38. if (!localStorage.xxM_name) {
  39. localStorage.setItem("xxM_name", "");
  40. localStorage.setItem("xxM_pass", "");
  41. }
  42. name.value = localStorage.xxM_name;
  43. pass.value = localStorage.xxM_pass;
  44. name.addEventListener("input", function () {
  45. localStorage.xxM_name = name.value;
  46. });
  47. pass.addEventListener("input", function () {
  48. localStorage.xxM_pass = pass.value;
  49. });
  50. }
  51. go();
  52. })()