|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- (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){
- 'use strict';
-
- var _formParser = require('./form-parser');
-
- function _isThereALoginForm(formInfo) {
- return formInfo.passwordField !== null;
- }
-
- function fillFormFields(formInfo, data) {
- var event = new Event('input');
- formInfo.passwordField.value = data.password;
- formInfo.passwordField.dispatchEvent(event);
-
- if (formInfo.loginField !== null) {
- formInfo.loginField.value = data.login;
- formInfo.loginField.dispatchEvent(event);
- }
- }
-
- chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
- var loginForm = (0, _formParser.getLoginForm)(window.document);
- if (loginForm !== null) {
- var formInfo = (0, _formParser.getFormInfo)(loginForm);
-
- if (message.type === 'isThereALoginForm') {
- return sendResponse({ isThereALoginForm: _isThereALoginForm(formInfo) });
- }
-
- if (message.type === 'submitForm') {
- var data = { password: message.password, login: message.login };
- fillFormFields(formInfo, data);
-
- if (formInfo.button === null) {
- loginForm.submit();
- } else {
- formInfo.button.click();
- }
- }
- }
- });
-
- },{"./form-parser":2}],2:[function(require,module,exports){
- 'use strict';
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.getScore = getScore;
- exports.getBestByScore = getBestByScore;
- exports.getLoginForm = getLoginForm;
- exports.getFormInfo = getFormInfo;
-
-
- function _valueIn(value, array) {
- for (var i = 0; i < array.length; i++) {
- if (value.indexOf(array[i]) >= 0) {
- return true;
- }
- }
- return false;
- }
-
- function _getButtonValue(element) {
- var nodeValue = null;
- if (element.nodeName === 'BUTTON' && element.type === 'submit') {
- nodeValue = element.childNodes[0].nodeValue;
- } else if (element.nodeName === 'INPUT' && element.type === 'submit') {
- nodeValue = element.value;
- }
- return nodeValue;
- }
-
- function _getButtonScore(buttonNodeValue) {
- var loginButtons = ['submit', 'login', 'enter', 'log in', 'signin', 'sign in', 'let\'s go'];
- var cancelButtons = ['reset', 'cancel', 'back', 'abort', 'undo', 'exit', 'empty', 'clear'];
- if (_valueIn(buttonNodeValue.toLowerCase(), loginButtons)) {
- return 10;
- }
- if (_valueIn(buttonNodeValue.toLowerCase(), cancelButtons)) {
- return -5;
- }
- return 0;
- }
-
- function getScore(form) {
- var score = 0;
- Array.from(form.elements).forEach(function (element) {
- var buttonNodeValue = _getButtonValue(element);
- if (buttonNodeValue !== null) {
- score += _getButtonScore(buttonNodeValue);
- }
- });
- return score;
- }
-
- function getBestByScore(forms) {
- if (forms.length > 0) {
- return forms.reduce(function (prev, current) {
- return prev.score > current.score ? prev : current;
- });
- }
- return null;
- }
-
- function getLoginForm(document) {
- var forms = [];
- Array.from(document.forms).forEach(function (form) {
- var score = getScore(form);
- if (score > 0) {
- forms.push({ score: score, form: form });
- }
- });
-
- var formInfo = getBestByScore(forms);
- if (!formInfo) {
- return null;
- }
-
- return formInfo.form;
- }
-
- function _getPasswordField(form) {
- return form.querySelector('input[type=password]');
- }
-
- function _getLoginField(form, passwordField) {
- var previousElement = null;
- var loginField = null;
- Array.from(form.querySelectorAll('input')).forEach(function (element) {
- if (element === passwordField && previousElement !== null) {
- loginField = previousElement;
- }
- previousElement = element;
- });
- return loginField;
- }
-
- function _getButton(form) {
- var buttons = [];
- Array.from(form.elements).forEach(function (element) {
- var buttonNodeValue = _getButtonValue(element);
- if (buttonNodeValue !== null) {
- buttons.push({ score: _getButtonScore(buttonNodeValue), button: element });
- }
- });
-
- var buttonInfo = getBestByScore(buttons);
- if (!buttonInfo) {
- return null;
- }
-
- return buttonInfo.button;
- }
-
- function getFormInfo(form) {
- var passwordField = _getPasswordField(form);
- return {
- loginField: _getLoginField(form, passwordField),
- passwordField: passwordField,
- button: _getButton(form)
- };
- }
-
- },{}]},{},[1]);
|