Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

content.min.js 4.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. 'use strict';
  3. var _formParser = require('./form-parser');
  4. function _isThereALoginForm(formInfo) {
  5. return formInfo.passwordField !== null;
  6. }
  7. function fillFormFields(formInfo, data) {
  8. var event = new Event('input');
  9. formInfo.passwordField.value = data.password;
  10. formInfo.passwordField.dispatchEvent(event);
  11. if (formInfo.loginField !== null) {
  12. formInfo.loginField.value = data.login;
  13. formInfo.loginField.dispatchEvent(event);
  14. }
  15. }
  16. chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
  17. var loginForm = (0, _formParser.getLoginForm)(window.document);
  18. if (loginForm !== null) {
  19. var formInfo = (0, _formParser.getFormInfo)(loginForm);
  20. if (message.type === 'isThereALoginForm') {
  21. return sendResponse({ isThereALoginForm: _isThereALoginForm(formInfo) });
  22. }
  23. if (message.type === 'submitForm') {
  24. var data = { password: message.password, login: message.login };
  25. fillFormFields(formInfo, data);
  26. if (formInfo.button === null) {
  27. loginForm.submit();
  28. } else {
  29. formInfo.button.click();
  30. }
  31. }
  32. }
  33. });
  34. },{"./form-parser":2}],2:[function(require,module,exports){
  35. 'use strict';
  36. Object.defineProperty(exports, "__esModule", {
  37. value: true
  38. });
  39. exports.getScore = getScore;
  40. exports.getBestByScore = getBestByScore;
  41. exports.getLoginForm = getLoginForm;
  42. exports.getFormInfo = getFormInfo;
  43. function _valueIn(value, array) {
  44. for (var i = 0; i < array.length; i++) {
  45. if (value.indexOf(array[i]) >= 0) {
  46. return true;
  47. }
  48. }
  49. return false;
  50. }
  51. function _getButtonValue(element) {
  52. var nodeValue = null;
  53. if (element.nodeName === 'BUTTON' && element.type === 'submit') {
  54. nodeValue = element.childNodes[0].nodeValue;
  55. } else if (element.nodeName === 'INPUT' && element.type === 'submit') {
  56. nodeValue = element.value;
  57. }
  58. return nodeValue;
  59. }
  60. function _getButtonScore(buttonNodeValue) {
  61. var loginButtons = ['submit', 'login', 'enter', 'log in', 'signin', 'sign in', 'let\'s go'];
  62. var cancelButtons = ['reset', 'cancel', 'back', 'abort', 'undo', 'exit', 'empty', 'clear'];
  63. if (_valueIn(buttonNodeValue.toLowerCase(), loginButtons)) {
  64. return 10;
  65. }
  66. if (_valueIn(buttonNodeValue.toLowerCase(), cancelButtons)) {
  67. return -5;
  68. }
  69. return 0;
  70. }
  71. function getScore(form) {
  72. var score = 0;
  73. Array.from(form.elements).forEach(function (element) {
  74. var buttonNodeValue = _getButtonValue(element);
  75. if (buttonNodeValue !== null) {
  76. score += _getButtonScore(buttonNodeValue);
  77. }
  78. });
  79. return score;
  80. }
  81. function getBestByScore(forms) {
  82. if (forms.length > 0) {
  83. return forms.reduce(function (prev, current) {
  84. return prev.score > current.score ? prev : current;
  85. });
  86. }
  87. return null;
  88. }
  89. function getLoginForm(document) {
  90. var forms = [];
  91. Array.from(document.forms).forEach(function (form) {
  92. var score = getScore(form);
  93. if (score > 0) {
  94. forms.push({ score: score, form: form });
  95. }
  96. });
  97. var formInfo = getBestByScore(forms);
  98. if (!formInfo) {
  99. return null;
  100. }
  101. return formInfo.form;
  102. }
  103. function _getPasswordField(form) {
  104. return form.querySelector('input[type=password]');
  105. }
  106. function _getLoginField(form, passwordField) {
  107. var previousElement = null;
  108. var loginField = null;
  109. Array.from(form.querySelectorAll('input')).forEach(function (element) {
  110. if (element === passwordField && previousElement !== null) {
  111. loginField = previousElement;
  112. }
  113. previousElement = element;
  114. });
  115. return loginField;
  116. }
  117. function _getButton(form) {
  118. var buttons = [];
  119. Array.from(form.elements).forEach(function (element) {
  120. var buttonNodeValue = _getButtonValue(element);
  121. if (buttonNodeValue !== null) {
  122. buttons.push({ score: _getButtonScore(buttonNodeValue), button: element });
  123. }
  124. });
  125. var buttonInfo = getBestByScore(buttons);
  126. if (!buttonInfo) {
  127. return null;
  128. }
  129. return buttonInfo.button;
  130. }
  131. function getFormInfo(form) {
  132. var passwordField = _getPasswordField(form);
  133. return {
  134. loginField: _getLoginField(form, passwordField),
  135. passwordField: passwordField,
  136. button: _getButton(form)
  137. };
  138. }
  139. },{}]},{},[1]);