finished refactoring minification on autofill collect

This commit is contained in:
Kyle Spearrin 2017-01-19 22:43:45 -05:00
parent 33ce9be01c
commit 0d74e145e2
1 changed files with 355 additions and 225 deletions

View File

@ -44,109 +44,170 @@
false !== canuf.a && 'input' === canuf.target.tagName.toLowerCase() && (canuf.target.dataset['com.agilebits.onepassword.userEdited'] = 'yes'); false !== canuf.a && 'input' === canuf.target.tagName.toLowerCase() && (canuf.target.dataset['com.agilebits.onepassword.userEdited'] = 'yes');
}, true); }, true);
function sasrie(theDoc, oneShotId) { function getPageDetails(theDoc, oneShotId) {
function jihid(noosun, otab) { // start helpers
var asril = noosun[otab];
if ('string' == typeof asril) { // get the value of a dom element's attribute
return asril; function getElementAttrValue(el, attrName) {
var attrVal = el[attrName];
if ('string' == typeof attrVal) {
return attrVal;
} }
asril = noosun.getAttribute(otab); attrVal = el.getAttribute(attrName);
return 'string' == typeof asril ? asril : null; return 'string' == typeof attrVal ? attrVal : null;
} }
function tepe(fige, nihat) { // has the element been fake tested?
if (-1 === ['text', 'password'].indexOf(nihat.type.toLowerCase()) || !(passwordRegEx.test(fige.value) || passwordRegEx.test(fige.htmlID) || passwordRegEx.test(fige.htmlName) || passwordRegEx.test(fige.placeholder) || passwordRegEx.test(fige['label-tag']) || passwordRegEx.test(fige['label-data']) || passwordRegEx.test(fige['label-aria']))) { function checkIfFakeTested(field, el) {
if (-1 === ['text', 'password'].indexOf(el.type.toLowerCase()) ||
!(passwordRegEx.test(field.value) ||
passwordRegEx.test(field.htmlID) || passwordRegEx.test(field.htmlName) ||
passwordRegEx.test(field.placeholder) || passwordRegEx.test(field['label-tag']) ||
passwordRegEx.test(field['label-data']) || passwordRegEx.test(field['label-aria']))) {
return false; return false;
} }
if (!fige.visible) {
if (!field.visible) {
return true; return true;
} }
if ('password' == nihat.type.toLowerCase()) {
if ('password' == el.type.toLowerCase()) {
return false; return false;
} }
var jeko = nihat.type;
jesceln(nihat, true); var elType = el.type;
return jeko !== nihat.type; focusElement(el, true);
return elType !== el.type;
} }
function sumu(bafo) { // get the value of a dom element
switch (toLowerString(bafo.type)) { function getElementValue(el) {
switch (toLowerString(el.type)) {
case 'checkbox': case 'checkbox':
return bafo.checked ? '✓' : ''; return el.checked ? '✓' : '';
case 'hidden': case 'hidden':
bafo = bafo.value; el = el.value;
if (!bafo || 'number' != typeof bafo.length) { if (!el || 'number' != typeof el.length) {
return ''; return '';
} }
254 < bafo.length && (bafo = bafo.substr(0, 254) + '...SNIPPED'); 254 < el.length && (el = el.substr(0, 254) + '...SNIPPED');
return bafo; return el;
default: default:
return bafo.value; return el.value;
} }
} }
function muri(goofu) { // get all the options for a "select" element
return goofu.options ? (goofu = Array.prototype.slice.call(goofu.options).map(function (luebi) { function getSelectElementOptions(el) {
var cituen = luebi.text, cituen = cituen ? toLowerString(cituen).replace(/\\s/gm, '').replace(/[~`!@$%^&*()\\-_+=:;'\"\\[\\]|\\\\,<.>\\?]/gm, '') : null; if (!el.options) {
return [cituen ? cituen : null, luebi.value]; return null;
}), { }
options: goofu
}) : null; var options = Array.prototype.slice.call(el.options).map(function (option) {
var optionText = option.text ?
toLowerString(option.text).replace(/\\s/gm, '').replace(/[~`!@$%^&*()\\-_+=:;'\"\\[\\]|\\\\,<.>\\?]/gm, '') :
null;
return [optionText ? optionText : null, option.value];
})
return {
options: options
};
} }
function cobu(mickuf) { // get the top label
var rana; function getLabelTop(el) {
for (mickuf = mickuf.parentElement || mickuf.parentNode; mickuf && 'td' != toLowerString(mickuf.tagName) ;) { var parent;
mickuf = mickuf.parentElement || mickuf.parentNode; for (el = el.parentElement || el.parentNode; el && 'td' != toLowerString(el.tagName) ;) {
el = el.parentElement || el.parentNode;
} }
if (!mickuf || void 0 === mickuf) {
if (!el || void 0 === el) {
return null; return null;
} }
rana = mickuf.parentElement || mickuf.parentNode;
if ('tr' != rana.tagName.toLowerCase()) { parent = el.parentElement || el.parentNode;
if ('tr' != parent.tagName.toLowerCase()) {
return null; return null;
} }
rana = rana.previousElementSibling;
if (!rana || 'tr' != (rana.tagName + '').toLowerCase() || rana.cells && mickuf.cellIndex >= rana.cells.length) { parent = parent.previousElementSibling;
if (!parent || 'tr' != (parent.tagName + '').toLowerCase() ||
parent.cells && el.cellIndex >= parent.cells.length) {
return null; return null;
} }
mickuf = rana.cells[mickuf.cellIndex];
mickuf = mickuf.textContent || mickuf.innerText; el = parent.cells[el.cellIndex];
return mickuf = loopi(mickuf); var elText = el.textContent || el.innerText;
return elText = cleanText(elText);
} }
function kasu(prifue) { // get all the tags for a given label
var jefu, hage = []; function getLabelTag(el) {
if (prifue.labels && prifue.labels.length && 0 < prifue.labels.length) { var docLabel,
hage = Array.prototype.slice.call(prifue.labels); theLabels = [];
if (el.labels && el.labels.length && 0 < el.labels.length) {
theLabels = Array.prototype.slice.call(el.labels);
} else { } else {
prifue.id && (hage = hage.concat(Array.prototype.slice.call(queryDoc(theDoc, 'label[for=' + JSON.stringify(prifue.id) + ']')))); if (el.id) {
if (prifue.name) { theLabels = theLabels.concat(Array.prototype.slice.call(
jefu = queryDoc(theDoc, 'label[for=' + JSON.stringify(prifue.name) + ']'); queryDoc(theDoc, 'label[for=' + JSON.stringify(el.id) + ']')));
for (var dilaf = 0; dilaf < jefu.length; dilaf++) { }
-1 === hage.indexOf(jefu[dilaf]) && hage.push(jefu[dilaf]);
if (el.name) {
docLabel = queryDoc(theDoc, 'label[for=' + JSON.stringify(el.name) + ']');
for (var labelIndex = 0; labelIndex < docLabel.length; labelIndex++) {
if (-1 === theLabels.indexOf(docLabel[labelIndex])) {
theLabels.push(docLabel[labelIndex])
}
} }
} }
for (jefu = prifue; jefu && jefu != theDoc; jefu = jefu.parentNode) {
'label' === toLowerString(jefu.tagName) && -1 === hage.indexOf(jefu) && hage.push(jefu); for (var theEl = el; theEl && theEl != theDoc; theEl = theEl.parentNode) {
if ('label' === toLowerString(theEl.tagName) && -1 === theLabels.indexOf(theEl)) {
theLabels.push(theEl);
}
} }
} }
0 === hage.length && (jefu = prifue.parentNode, 'dd' === jefu.tagName.toLowerCase() && null !== jefu.previousElementSibling && 'dt' === jefu.previousElementSibling.tagName.toLowerCase() && hage.push(jefu.previousElementSibling));
return 0 < hage.length ? hage.map(function (noquo) { if (0 === theLabels.length) {
return (noquo.textContent || noquo.innerText).replace(/^\\s+/, '').replace(/\\s+$/, '').replace('\\n', '').replace(/\\s{2,}/, ' '); theEl = el.parentNode;
}).join('') : null; if ('dd' === theEl.tagName.toLowerCase() && null !== theEl.previousElementSibling
&& 'dt' === theEl.previousElementSibling.tagName.toLowerCase()) {
theLabels.push(theEl.previousElementSibling);
}
}
if (0 > theLabels.length) {
return null;
}
return theLabels.map(function (l) {
return (l.textContent || l.innerText)
.replace(/^\\s+/, '').replace(/\\s+$/, '').replace('\\n', '').replace(/\\s{2,}/, ' ');
}).join('');
} }
function etit(kisa, puju, lofes, aynem) { // add property and value to the object if there is a value
void 0 !== aynem && aynem === lofes || null === lofes || void 0 === lofes || (kisa[puju] = lofes); function addProp(obj, prop, val, d) {
if (0 !== d && d === val || null === val || void 0 === val) {
return;
}
obj[prop] = val;
} }
// lowercase helper
function toLowerString(s) { function toLowerString(s) {
return 'string' === typeof s ? s.toLowerCase() : ('' + s).toLowerCase(); return 'string' === typeof s ? s.toLowerCase() : ('' + s).toLowerCase();
} }
// query the document helper
function queryDoc(doc, query) { function queryDoc(doc, query) {
var els = []; var els = [];
try { try {
@ -155,139 +216,162 @@
return els; return els;
} }
// end helpers
var theView = theDoc.defaultView ? theDoc.defaultView : window, var theView = theDoc.defaultView ? theDoc.defaultView : window,
passwordRegEx = RegExp('((\\\\b|_|-)pin(\\\\b|_|-)|password|passwort|kennwort|(\\\\b|_|-)passe(\\\\b|_|-)|contraseña|senha|密码|adgangskode|hasło|wachtwoord)', 'i'); passwordRegEx = RegExp('((\\\\b|_|-)pin(\\\\b|_|-)|password|passwort|kennwort|(\\\\b|_|-)passe(\\\\b|_|-)|contraseña|senha|密码|adgangskode|hasło|wachtwoord)', 'i');
var theTitle = Array.prototype.slice.call(queryDoc(theDoc, 'form')).map(function (formEl, elIndex) { // get all the docs
var theForms = Array.prototype.slice.call(queryDoc(theDoc, 'form')).map(function (formEl, elIndex) {
var op = {}, var op = {},
formOpId = '__form__' + elIndex; formOpId = '__form__' + elIndex;
formEl.opid = formOpId; formEl.opid = formOpId;
op.opid = formOpId; op.opid = formOpId;
etit(op, 'htmlName', jihid(formEl, 'name')); addProp(op, 'htmlName', getElementAttrValue(formEl, 'name'));
etit(op, 'htmlID', jihid(formEl, 'id')); addProp(op, 'htmlID', getElementAttrValue(formEl, 'id'));
formOpId = jihid(formEl, 'action'); formOpId = getElementAttrValue(formEl, 'action');
formOpId = new URL(formOpId, window.location.href); formOpId = new URL(formOpId, window.location.href);
etit(op, 'htmlAction', formOpId ? formOpId.href : null); addProp(op, 'htmlAction', formOpId ? formOpId.href : null);
etit(op, 'htmlMethod', jihid(formEl, 'method')); addProp(op, 'htmlMethod', getElementAttrValue(formEl, 'method'));
return op; return op;
}); });
var theFields = Array.prototype.slice.call(getFormElements(theDoc)).map(function (tadkak, shoho) { // get all the form fields
var neref = {}, bosna = '__' + shoho, steyquif = -1 == tadkak.maxLength ? 999 : tadkak.maxLength; var theFields = Array.prototype.slice.call(getFormElements(theDoc)).map(function (el, elIndex) {
if (!steyquif || 'number' === typeof steyquif && isNaN(steyquif)) { var field = {},
steyquif = 999; opId = '__' + elIndex,
} elMaxLen = -1 == el.maxLength ? 999 : el.maxLength;
theDoc.elementsByOPID[bosna] = tadkak;
tadkak.opid = bosna;
neref.opid = bosna;
neref.elementNumber = shoho;
etit(neref, 'maxLength', Math.min(steyquif, 999), 999);
neref.visible = ciquod(tadkak);
neref.viewable = blekey(tadkak);
etit(neref, 'htmlID', jihid(tadkak, 'id'));
etit(neref, 'htmlName', jihid(tadkak, 'name'));
etit(neref, 'htmlClass', jihid(tadkak, 'class'));
etit(neref, 'tabindex', jihid(tadkak, 'tabindex'));
etit(neref, 'title', jihid(tadkak, 'title'));
etit(neref, 'userEdited', !!tadkak.dataset['com.agilebits.onepassword.userEdited']);
if ('hidden' != toLowerString(tadkak.type)) { if (!elMaxLen || 'number' === typeof elMaxLen && isNaN(elMaxLen)) {
etit(neref, 'label-tag', kasu(tadkak)); elMaxLen = 999;
etit(neref, 'label-data', jihid(tadkak, 'data-label')); }
etit(neref, 'label-aria', jihid(tadkak, 'aria-label'));
etit(neref, 'label-top', cobu(tadkak)); theDoc.elementsByOPID[opId] = el;
bosna = []; el.opid = opId;
for (steyquif = tadkak; steyquif && steyquif.nextSibling;) { field.opid = opId;
steyquif = steyquif.nextSibling; field.elementNumber = elIndex;
if (quernaln(steyquif)) { addProp(field, 'maxLength', Math.min(elMaxLen, 999), 999);
field.visible = isElementVisible(el);
field.viewable = isElementViewable(el);
addProp(field, 'htmlID', getElementAttrValue(el, 'id'));
addProp(field, 'htmlName', getElementAttrValue(el, 'name'));
addProp(field, 'htmlClass', getElementAttrValue(el, 'class'));
addProp(field, 'tabindex', getElementAttrValue(el, 'tabindex'));
addProp(field, 'title', getElementAttrValue(el, 'title'));
addProp(field, 'userEdited', !!el.dataset['com.agilebits.onepassword.userEdited']);
if ('hidden' != toLowerString(el.type)) {
addProp(field, 'label-tag', getLabelTag(el));
addProp(field, 'label-data', getElementAttrValue(el, 'data-label'));
addProp(field, 'label-aria', getElementAttrValue(el, 'aria-label'));
addProp(field, 'label-top', getLabelTop(el));
var labelArr = [];
for (var sib = el; sib && sib.nextSibling;) {
sib = sib.nextSibling;
if (isKnownTag(sib)) {
break; break;
} }
queka(bosna, steyquif); checkNodeType(labelArr, sib);
} }
etit(neref, 'label-right', bosna.join('')); addProp(field, 'label-right', labelArr.join(''));
bosna = []; labelArr = [];
bozoum(tadkak, bosna); shiftForLeftLabel(el, labelArr);
bosna = bosna.reverse().join(''); labelArr = labelArr.reverse().join('');
etit(neref, 'label-left', bosna); addProp(field, 'label-left', labelArr);
etit(neref, 'placeholder', jihid(tadkak, 'placeholder')); addProp(field, 'placeholder', getElementAttrValue(el, 'placeholder'));
} }
etit(neref, 'rel', jihid(tadkak, 'rel')); addProp(field, 'rel', getElementAttrValue(el, 'rel'));
etit(neref, 'type', toLowerString(jihid(tadkak, 'type'))); addProp(field, 'type', toLowerString(getElementAttrValue(el, 'type')));
etit(neref, 'value', sumu(tadkak)); addProp(field, 'value', getElementValue(el));
etit(neref, 'checked', tadkak.checked, false); addProp(field, 'checked', el.checked, false);
etit(neref, 'autoCompleteType', tadkak.getAttribute('x-autocompletetype') || tadkak.getAttribute('autocompletetype') || tadkak.getAttribute('autocomplete'), 'off'); addProp(field, 'autoCompleteType', el.getAttribute('x-autocompletetype') || el.getAttribute('autocompletetype') || el.getAttribute('autocomplete'), 'off');
etit(neref, 'disabled', tadkak.disabled); addProp(field, 'disabled', el.disabled);
etit(neref, 'readonly', tadkak.b || tadkak.readOnly); addProp(field, 'readonly', el.b || el.readOnly);
etit(neref, 'selectInfo', muri(tadkak)); addProp(field, 'selectInfo', getSelectElementOptions(el));
etit(neref, 'aria-hidden', 'true' == tadkak.getAttribute('aria-hidden'), false); addProp(field, 'aria-hidden', 'true' == el.getAttribute('aria-hidden'), false);
etit(neref, 'aria-disabled', 'true' == tadkak.getAttribute('aria-disabled'), false); addProp(field, 'aria-disabled', 'true' == el.getAttribute('aria-disabled'), false);
etit(neref, 'aria-haspopup', 'true' == tadkak.getAttribute('aria-haspopup'), false); addProp(field, 'aria-haspopup', 'true' == el.getAttribute('aria-haspopup'), false);
etit(neref, 'data-unmasked', tadkak.dataset.unmasked); addProp(field, 'data-unmasked', el.dataset.unmasked);
etit(neref, 'data-stripe', jihid(tadkak, 'data-stripe')); addProp(field, 'data-stripe', getElementAttrValue(el, 'data-stripe'));
etit(neref, 'onepasswordFieldType', tadkak.dataset.onepasswordFieldType || tadkak.type); addProp(field, 'onepasswordFieldType', el.dataset.onepasswordFieldType || el.type);
etit(neref, 'onepasswordDesignation', tadkak.dataset.onepasswordDesignation); addProp(field, 'onepasswordDesignation', el.dataset.onepasswordDesignation);
etit(neref, 'onepasswordSignInUrl', tadkak.dataset.onepasswordSignInUrl); addProp(field, 'onepasswordSignInUrl', el.dataset.onepasswordSignInUrl);
etit(neref, 'onepasswordSectionTitle', tadkak.dataset.onepasswordSectionTitle); addProp(field, 'onepasswordSectionTitle', el.dataset.onepasswordSectionTitle);
etit(neref, 'onepasswordSectionFieldKind', tadkak.dataset.onepasswordSectionFieldKind); addProp(field, 'onepasswordSectionFieldKind', el.dataset.onepasswordSectionFieldKind);
etit(neref, 'onepasswordSectionFieldTitle', tadkak.dataset.onepasswordSectionFieldTitle); addProp(field, 'onepasswordSectionFieldTitle', el.dataset.onepasswordSectionFieldTitle);
etit(neref, 'onepasswordSectionFieldValue', tadkak.dataset.onepasswordSectionFieldValue); addProp(field, 'onepasswordSectionFieldValue', el.dataset.onepasswordSectionFieldValue);
tadkak.form && (neref.form = jihid(tadkak.form, 'opid'));
etit(neref, 'fakeTested', tepe(neref, tadkak), false);
return neref; if (el.form) {
field.form = getElementAttrValue(el.form, 'opid');
}
addProp(field, 'fakeTested', checkIfFakeTested(field, el), false);
return field;
}); });
theFields.filter(function (hefik) { // test form fields
return hefik.fakeTested; theFields.filter(function (f) {
}).forEach(function (kukip) { return f.fakeTested;
var cisuf = theDoc.elementsByOPID[kukip.opid]; }).forEach(function (f) {
cisuf.getBoundingClientRect(); var el = theDoc.elementsByOPID[f.opid];
var jeechgan = cisuf.value; el.getBoundingClientRect();
!cisuf || cisuf && 'function' !== typeof cisuf.click || cisuf.click();
jesceln(cisuf, false); var originalValue = el.value;
cisuf.dispatchEvent(guna(cisuf, 'keydown')); // click it
cisuf.dispatchEvent(guna(cisuf, 'keypress')); !el || el && 'function' !== typeof el.click || el.click();
cisuf.dispatchEvent(guna(cisuf, 'keyup')); focusElement(el, false);
cisuf.value !== jeechgan && (cisuf.value = jeechgan);
cisuf.click && cisuf.click(); el.dispatchEvent(doEventOnElement(el, 'keydown'));
kukip.postFakeTestVisible = ciquod(cisuf); el.dispatchEvent(doEventOnElement(el, 'keypress'));
kukip.postFakeTestViewable = blekey(cisuf); el.dispatchEvent(doEventOnElement(el, 'keyup'));
kukip.postFakeTestType = cisuf.type;
kukip = cisuf.value; el.value !== originalValue && (el.value = originalValue);
var jeechgan = cisuf.ownerDocument.createEvent('HTMLEvents'), jalue = cisuf.ownerDocument.createEvent('HTMLEvents');
cisuf.dispatchEvent(guna(cisuf, 'keydown')); el.click && el.click();
cisuf.dispatchEvent(guna(cisuf, 'keypress')); f.postFakeTestVisible = isElementVisible(el);
cisuf.dispatchEvent(guna(cisuf, 'keyup')); f.postFakeTestViewable = isElementViewable(el);
jalue.initEvent('input', true, true); f.postFakeTestType = el.type;
cisuf.dispatchEvent(jalue);
jeechgan.initEvent('change', true, true); var elValue = el.value;
cisuf.dispatchEvent(jeechgan);
cisuf.blur(); var event1 = el.ownerDocument.createEvent('HTMLEvents'),
cisuf.value !== kukip && (cisuf.value = kukip); event2 = el.ownerDocument.createEvent('HTMLEvents');
el.dispatchEvent(doEventOnElement(el, 'keydown'));
el.dispatchEvent(doEventOnElement(el, 'keypress'));
el.dispatchEvent(doEventOnElement(el, 'keyup'));
event2.initEvent('input', true, true);
el.dispatchEvent(event2);
event.initEvent('change', true, true);
el.dispatchEvent(event);
el.blur();
el.value !== elValue && (el.value = elValue);
}); });
// build out the page details object. this is the final result
var pageDetails = { var pageDetails = {
documentUUID: oneShotId, documentUUID: oneShotId,
title: theDoc.title, title: theDoc.title,
url: theView.location.href, url: theView.location.href,
documentUrl: theDoc.location.href, documentUrl: theDoc.location.href,
tabUrl: theView.location.href, tabUrl: theView.location.href,
forms: function (basas) { forms: function (forms) {
var histstap = {}; var formObj = {};
basas.forEach(function (quavu) { forms.forEach(function (f) {
histstap[quavu.opid] = quavu; formObj[f.opid] = f;
}); });
return histstap; return formObj;
}(theTitle), }(theForms),
fields: theFields, fields: theFields,
collectedTimestamp: new Date().getTime() collectedTimestamp: new Date().getTime()
}; };
// get proper page title. maybe they are using the special meta tag? // get proper page title. maybe they are using the special meta tag?
theTitle = document.querySelector('[data-onepassword-title]') var theTitle = document.querySelector('[data-onepassword-title]')
if (theTitle && theTitle.dataset[DISPLAY_TITLE_ATTRIBUE]) { if (theTitle && theTitle.dataset[DISPLAY_TITLE_ATTRIBUE]) {
pageDetails.displayTitle = theTitle.dataset.onepasswordTitle; pageDetails.displayTitle = theTitle.dataset.onepasswordTitle;
} }
@ -295,9 +379,9 @@
return pageDetails; return pageDetails;
} }
document.elementForOPID = jasu; document.elementForOPID = getElementForOPID;
function guna(kedol, fonor) { function doEventOnElement(kedol, fonor) {
var quebo; var quebo;
isFirefox ? (quebo = document.createEvent('KeyboardEvent'), quebo.initKeyEvent(fonor, true, false, null, false, false, false, false, 0, 0)) : (quebo = kedol.ownerDocument.createEvent('Events'), isFirefox ? (quebo = document.createEvent('KeyboardEvent'), quebo.initKeyEvent(fonor, true, false, null, false, false, false, false, 0, 0)) : (quebo = kedol.ownerDocument.createEvent('Events'),
quebo.initEvent(fonor, true, false), quebo.charCode = 0, quebo.keyCode = 0, quebo.which = 0, quebo.initEvent(fonor, true, false), quebo.charCode = 0, quebo.keyCode = 0, quebo.which = 0,
@ -305,6 +389,7 @@
return quebo; return quebo;
} }
// some useful globals
window.LOGIN_TITLES = [/^\\W*log\\W*[oi]n\\W*$/i, /log\\W*[oi]n (?:securely|now)/i, /^\\W*sign\\W*[oi]n\\W*$/i, 'continue', 'submit', 'weiter', 'accès', 'вход', 'connexion', 'entrar', 'anmelden', 'accedi', 'valider', '登录', 'लॉग इन करें', 'change password']; window.LOGIN_TITLES = [/^\\W*log\\W*[oi]n\\W*$/i, /log\\W*[oi]n (?:securely|now)/i, /^\\W*sign\\W*[oi]n\\W*$/i, 'continue', 'submit', 'weiter', 'accès', 'вход', 'connexion', 'entrar', 'anmelden', 'accedi', 'valider', '登录', 'लॉग इन करें', 'change password'];
window.LOGIN_RED_HERRING_TITLES = ['already have an account', 'sign in with']; window.LOGIN_RED_HERRING_TITLES = ['already have an account', 'sign in with'];
window.REGISTER_TITLES = 'register;sign up;signup;join;create my account;регистрация;inscription;regístrate;cadastre-se;registrieren;registrazione;注册;साइन अप करें'.split(';'); window.REGISTER_TITLES = 'register;sign up;signup;join;create my account;регистрация;inscription;regístrate;cadastre-se;registrieren;registrazione;注册;साइन अप करें'.split(';');
@ -313,110 +398,151 @@
window.REMEMBER_ME_TITLES = ['remember me', 'rememberme', 'keep me signed in']; window.REMEMBER_ME_TITLES = ['remember me', 'rememberme', 'keep me signed in'];
window.BACK_TITLES = ['back', 'назад']; window.BACK_TITLES = ['back', 'назад'];
function loopi(segu) { // clean up the text
var bitou = null; function cleanText(s) {
segu && (bitou = segu.replace(/^\\s+|\\s+$|\\r?\\n.*$/gm, ''), bitou = 0 < bitou.length ? bitou : null); var sVal = null;
return bitou; s && (sVal = s.replace(/^\\s+|\\s+$|\\r?\\n.*$/gm, ''), sVal = 0 < sVal.length ? sVal : null);
return sVal;
} }
function queka(tigap, niela) { // check the node type and adjust the array accordingly
var jahe; function checkNodeType(arr, el) {
jahe = ''; var theText = '';
3 === niela.nodeType ? jahe = niela.nodeValue : 1 === niela.nodeType && (jahe = niela.textContent || niela.innerText); 3 === el.nodeType ? theText = el.nodeValue : 1 === el.nodeType && (theText = el.textContent || el.innerText);
(jahe = loopi(jahe)) && tigap.push(jahe); (theText = cleanText(theText)) && arr.push(theText);
} }
function quernaln(ukag) { function isKnownTag(el) {
var relu; if (el && void 0 !== el) {
ukag && void 0 !== ukag ? (relu = 'select option input form textarea button table iframe body head script'.split(' '), var tags = 'select option input form textarea button table iframe body head script'.split(' ');
ukag ? (ukag = ukag ? (ukag.tagName || '').toLowerCase() : '', relu = relu.constructor == Array ? 0 <= relu.indexOf(ukag) : ukag === relu) : relu = false) : relu = true;
return relu; if (el) {
var elTag = el ? (el.tagName || '').toLowerCase() : '';
return tags.constructor == Array ? 0 <= tags.indexOf(elTag) : elTag === tags;
}
else {
return false;
}
}
else {
return true;
}
} }
function bozoum(edpuk, uday, siru) { function shiftForLeftLabel(el, arr, steps) {
var quoto; var sib;
for (siru || (siru = 0) ; edpuk && edpuk.previousSibling;) { for (steps || (steps = 0) ; el && el.previousSibling;) {
edpuk = edpuk.previousSibling; el = el.previousSibling;
if (quernaln(edpuk)) { if (isKnownTag(el)) {
return; return;
} }
queka(uday, edpuk);
checkNodeType(arr, el);
} }
if (edpuk && 0 === uday.length) { if (el && 0 === arr.length) {
for (quoto = null; !quoto;) { for (sib = null; !sib;) {
edpuk = edpuk.parentElement || edpuk.parentNode; el = el.parentElement || el.parentNode;
if (!edpuk) { if (!el) {
return; return;
} }
for (quoto = edpuk.previousSibling; quoto && !quernaln(quoto) && quoto.lastChild;) { for (sib = el.previousSibling; sib && !isKnownTag(sib) && sib.lastChild;) {
quoto = quoto.lastChild; sib = sib.lastChild;
} }
} }
quernaln(quoto) || (queka(uday, quoto), 0 === uday.length && bozoum(quoto, uday, siru + 1));
// base case and recurse
isKnownTag(sib) || (checkNodeType(arr, sib), 0 === arr.length && shiftForLeftLabel(sib, arr, steps + 1));
} }
} }
function ciquod(hieku) { // is a dom element visible on screen?
var liji = hieku; function isElementVisible(el) {
hieku = (hieku = hieku.ownerDocument) ? hieku.defaultView : {}; var theEl = el;
for (var teesi; liji && liji !== document;) { el = (el = el.ownerDocument) ? el.defaultView : {};
teesi = hieku.getComputedStyle ? hieku.getComputedStyle(liji, null) : liji.style;
if (!teesi) { // walk the dom tree
for (var elStyle; theEl && theEl !== document;) {
elStyle = el.getComputedStyle ? el.getComputedStyle(theEl, null) : theEl.style;
if (!elStyle) {
return true; return true;
} }
if ('none' === teesi.display || 'hidden' == teesi.visibility) {
if ('none' === elStyle.display || 'hidden' == elStyle.visibility) {
return false; return false;
} }
liji = liji.parentNode;
// walk up
theEl = theEl.parentNode;
} }
return liji === document;
return theEl === document;
} }
function blekey(coufi) { // is a dom element "viewable" on screen?
var pudu = coufi.ownerDocument.documentElement, muma = coufi.getBoundingClientRect(), gubuech = pudu.scrollWidth, kosri = pudu.scrollHeight, quophe = muma.left - pudu.clientLeft, pudu = muma.top - pudu.clientTop, temton; function isElementViewable(el) {
if (!ciquod(coufi) || !coufi.offsetParent || 10 > coufi.clientWidth || 10 > coufi.clientHeight) { var theDoc = el.ownerDocument.documentElement,
rect = el.getBoundingClientRect(),
docScrollWidth = theDoc.scrollWidth,
kosri = theDoc.scrollHeight,
leftOffset = rect.left - theDoc.clientLeft,
topOffset = rect.top - theDoc.clientTop,
theRect;
if (!isElementVisible(el) || !el.offsetParent || 10 > el.clientWidth || 10 > el.clientHeight) {
return false; return false;
} }
var aley = coufi.getClientRects();
if (0 === aley.length) { var rects = el.getClientRects();
if (0 === rects.length) {
return false; return false;
} }
for (var sehi = 0; sehi < aley.length; sehi++) {
if (temton = aley[sehi], temton.left > gubuech || 0 > temton.right) { for (var i = 0; i < rects.length; i++) {
if (theRect = rects[i], theRect.left > docScrollWidth || 0 > theRect.right) {
return false; return false;
} }
} }
if (0 > quophe || quophe > gubuech || 0 > pudu || pudu > kosri) {
if (0 > leftOffset || leftOffset > docScrollWidth || 0 > topOffset || topOffset > kosri) {
return false; return false;
} }
for (muma = coufi.ownerDocument.elementFromPoint(quophe + (muma.right > window.innerWidth ? (window.innerWidth - quophe) / 2 : muma.width / 2), pudu + (muma.bottom > window.innerHeight ? (window.innerHeight - pudu) / 2 : muma.height / 2)) ; muma && muma !== coufi && muma !== document;) {
if (muma.tagName && 'string' === typeof muma.tagName && 'label' === muma.tagName.toLowerCase() && coufi.labels && 0 < coufi.labels.length) { // walk the tree
return 0 <= Array.prototype.slice.call(coufi.labels).indexOf(muma); for (var pointEl = el.ownerDocument.elementFromPoint(leftOffset + (rect.right > window.innerWidth ? (window.innerWidth - leftOffset) / 2 : rect.width / 2), topOffset + (rect.bottom > window.innerHeight ? (window.innerHeight - topOffset) / 2 : rect.height / 2)) ; pointEl && pointEl !== el && pointEl !== document;) {
if (pointEl.tagName && 'string' === typeof pointEl.tagName && 'label' === pointEl.tagName.toLowerCase()
&& el.labels && 0 < el.labels.length) {
return 0 <= Array.prototype.slice.call(el.labels).indexOf(pointEl);
} }
muma = muma.parentNode;
// walk up
pointEl = pointEl.parentNode;
} }
return muma === coufi;
return pointEl === el;
} }
function jasu(sebe) { function getElementForOPID(opId) {
var jutuem; var theEl;
if (void 0 === sebe || null === sebe) { if (void 0 === opId || null === opId) {
return null; return null;
} }
try { try {
var paraf = Array.prototype.slice.call(getFormElements(document)), viehi = paraf.filter(function (strukou) { var formEls = Array.prototype.slice.call(getFormElements(document));
return strukou.opid == sebe; var filteredFormEls = formEls.filter(function (el) {
return el.opid == opId;
}); });
if (0 < viehi.length) {
jutuem = viehi[0], 1 < viehi.length && console.warn('More than one element found with opid ' + sebe); if (0 < filteredFormEls.length) {
theEl = filteredFormEls[0], 1 < filteredFormEls.length && console.warn('More than one element found with opid ' + opId);
} else { } else {
var jotun = parseInt(sebe.split('__')[1], 10); var theIndex = parseInt(opId.split('__')[1], 10);
isNaN(jotun) || (jutuem = paraf[jotun]); isNaN(theIndex) || (theEl = formEls[theIndex]);
} }
} catch (beynad) { } catch (e) {
console.error('An unexpected error occurred: ' + beynad); console.error('An unexpected error occurred: ' + e);
} finally { } finally {
return jutuem; return theEl;
} }
} }
@ -429,17 +555,21 @@
return els; return els;
} }
function jesceln(calo, noru) { // focus the element and optionally restore its original value
if (noru) { function focusElement(el, setVal) {
var klebup = calo.value; if (setVal) {
calo.focus(); var initialValue = el.value;
calo.value !== klebup && (calo.value = klebup); el.focus();
if (el.value !== initialValue) {
el.value = initialValue;
}
} else { } else {
calo.focus(); el.focus();
} }
} }
return JSON.stringify(sasrie(document, 'oneshotUUID')); return JSON.stringify(getPageDetails(document, 'oneshotUUID'));
} }
function fill(document, fillScript, undefined) { function fill(document, fillScript, undefined) {