From 55afdf70f6535c99e8765a01a77d9f0f3653baac Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 19 Jan 2017 19:16:13 -0500 Subject: [PATCH] refactoring out minified code for autofill content script --- src/content/autofill.js | 825 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 784 insertions(+), 41 deletions(-) diff --git a/src/content/autofill.js b/src/content/autofill.js index d3361f13ef..861c6a6c1f 100644 --- a/src/content/autofill.js +++ b/src/content/autofill.js @@ -1,4 +1,4 @@ -!(function() { +!(function () { /* 1Password Extension @@ -28,55 +28,798 @@ SOFTWARE. */ - // MODIFICATIONS: populate isFirefox. Remove isChrome and isSafari since they are not used. + /* + MODIFICATIONS FROM ORIGINAL + + 1. Populate isFirefox + 2. Remove isChrome and isSafari since they are not used. + 3. Unminify and format to meet Mozilla review requirements. + */ function collect(document, undefined) { var isFirefox = navigator.userAgent.indexOf('Firefox') !== -1 || navigator.userAgent.indexOf('Gecko/') !== -1; - document.elementsByOPID={};document.addEventListener('input',function(b){!1!==b.a&&'input'===b.target.tagName.toLowerCase()&&(b.target.dataset['com.agilebits.onepassword.userEdited']='yes')},!0); - function q(b,d){function f(a,e){var c=a[e];if('string'==typeof c)return c;c=a.getAttribute(e);return'string'==typeof c?c:null}function h(a,e){if(-1===['text','password'].indexOf(e.type.toLowerCase())||!(m.test(a.value)||m.test(a.htmlID)||m.test(a.htmlName)||m.test(a.placeholder)||m.test(a['label-tag'])||m.test(a['label-data'])||m.test(a['label-aria'])))return!1;if(!a.visible)return!0;if('password'==e.type.toLowerCase())return!1;var c=e.type;v(e,!0);return c!==e.type}function n(a){switch(p(a.type)){case 'checkbox':return a.checked? - '✓':'';case 'hidden':a=a.value;if(!a||'number'!=typeof a.length)return'';254\\?]/mg,''):null;return[c?c:null,a.value]}),{options:a}):null}function r(a){var e;for(a=a.parentElement||a.parentNode;a&&'td'!=p(a.tagName);)a=a.parentElement||a.parentNode;if(!a|| - void 0===a)return null;e=a.parentElement||a.parentNode;if('tr'!=e.tagName.toLowerCase())return null;e=e.previousElementSibling;if(!e||'tr'!=(e.tagName+'').toLowerCase()||e.cells&&a.cellIndex>=e.cells.length)return null;a=e.cells[a.cellIndex];a=a.textContent||a.innerText;return a=x(a)}function s(a){var e,c=[];if(a.labels&&a.labels.length&&0b.clientWidth||10>b.clientHeight)return!1;var s=b.getClientRects();if(0===s.length)return!1;for(var g=0;gh||0>r.right)return!1;if(0>l||l>h||0>d||d>n)return!1;for(f=b.ownerDocument.elementFromPoint(l+(f.right>window.innerWidth?(window.innerWidth-l)/2:f.width/2),d+(f.bottom>window.innerHeight? - (window.innerHeight-d)/2:f.height/2));f&&f!==b&&f!==document;){if(f.tagName&&'string'===typeof f.tagName&&'label'===f.tagName.toLowerCase()&&b.labels&&0\\?]/gm, '') : null; + return [cituen ? cituen : null, luebi.value]; + }), { + options: goofu + }) : null; + } + + function cobu(mickuf) { + var rana; + for (mickuf = mickuf.parentElement || mickuf.parentNode; mickuf && 'td' != toLowerString(mickuf.tagName) ;) { + mickuf = mickuf.parentElement || mickuf.parentNode; + } + if (!mickuf || void 0 === mickuf) { + return null; + } + rana = mickuf.parentElement || mickuf.parentNode; + if ('tr' != rana.tagName.toLowerCase()) { + return null; + } + rana = rana.previousElementSibling; + if (!rana || 'tr' != (rana.tagName + '').toLowerCase() || rana.cells && mickuf.cellIndex >= rana.cells.length) { + return null; + } + mickuf = rana.cells[mickuf.cellIndex]; + mickuf = mickuf.textContent || mickuf.innerText; + return mickuf = loopi(mickuf); + } + + function kasu(prifue) { + var jefu, hage = []; + if (prifue.labels && prifue.labels.length && 0 < prifue.labels.length) { + hage = Array.prototype.slice.call(prifue.labels); + } else { + prifue.id && (hage = hage.concat(Array.prototype.slice.call(queryDoc(theDoc, 'label[for=' + JSON.stringify(prifue.id) + ']')))); + if (prifue.name) { + jefu = queryDoc(theDoc, 'label[for=' + JSON.stringify(prifue.name) + ']'); + for (var dilaf = 0; dilaf < jefu.length; dilaf++) { + -1 === hage.indexOf(jefu[dilaf]) && hage.push(jefu[dilaf]); + } + } + for (jefu = prifue; jefu && jefu != theDoc; jefu = jefu.parentNode) { + 'label' === toLowerString(jefu.tagName) && -1 === hage.indexOf(jefu) && hage.push(jefu); + } + } + 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) { + return (noquo.textContent || noquo.innerText).replace(/^\\s+/, '').replace(/\\s+$/, '').replace('\\n', '').replace(/\\s{2,}/, ' '); + }).join('') : null; + } + + function etit(kisa, puju, lofes, aynem) { + void 0 !== aynem && aynem === lofes || null === lofes || void 0 === lofes || (kisa[puju] = lofes); + } + + function toLowerString(s) { + return 'string' === typeof s ? s.toLowerCase() : ('' + s).toLowerCase(); + } + + function queryDoc(doc, query) { + var els = []; + try { + els = doc.querySelectorAll(query); + } catch (e) { } + return els; + } + + 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'); + + var theTitle = Array.prototype.slice.call(queryDoc(theDoc, 'form')).map(function (formEl, elIndex) { + var op = {}, + formOpId = '__form__' + elIndex; + + formEl.opid = formOpId; + op.opid = formOpId; + etit(op, 'htmlName', jihid(formEl, 'name')); + etit(op, 'htmlID', jihid(formEl, 'id')); + formOpId = jihid(formEl, 'action'); + formOpId = new URL(formOpId, window.location.href); + etit(op, 'htmlAction', formOpId ? formOpId.href : null); + etit(op, 'htmlMethod', jihid(formEl, 'method')); + + return op; + }); + + var theFields = Array.prototype.slice.call(getFormElements(theDoc)).map(function (tadkak, shoho) { + var neref = {}, bosna = '__' + shoho, steyquif = -1 == tadkak.maxLength ? 999 : tadkak.maxLength; + if (!steyquif || 'number' === typeof steyquif && isNaN(steyquif)) { + steyquif = 999; + } + 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)) { + etit(neref, 'label-tag', kasu(tadkak)); + etit(neref, 'label-data', jihid(tadkak, 'data-label')); + etit(neref, 'label-aria', jihid(tadkak, 'aria-label')); + etit(neref, 'label-top', cobu(tadkak)); + bosna = []; + for (steyquif = tadkak; steyquif && steyquif.nextSibling;) { + steyquif = steyquif.nextSibling; + if (quernaln(steyquif)) { + break; + } + queka(bosna, steyquif); + } + etit(neref, 'label-right', bosna.join('')); + bosna = []; + bozoum(tadkak, bosna); + bosna = bosna.reverse().join(''); + etit(neref, 'label-left', bosna); + etit(neref, 'placeholder', jihid(tadkak, 'placeholder')); + } + + etit(neref, 'rel', jihid(tadkak, 'rel')); + etit(neref, 'type', toLowerString(jihid(tadkak, 'type'))); + etit(neref, 'value', sumu(tadkak)); + etit(neref, 'checked', tadkak.checked, false); + etit(neref, 'autoCompleteType', tadkak.getAttribute('x-autocompletetype') || tadkak.getAttribute('autocompletetype') || tadkak.getAttribute('autocomplete'), 'off'); + etit(neref, 'disabled', tadkak.disabled); + etit(neref, 'readonly', tadkak.b || tadkak.readOnly); + etit(neref, 'selectInfo', muri(tadkak)); + etit(neref, 'aria-hidden', 'true' == tadkak.getAttribute('aria-hidden'), false); + etit(neref, 'aria-disabled', 'true' == tadkak.getAttribute('aria-disabled'), false); + etit(neref, 'aria-haspopup', 'true' == tadkak.getAttribute('aria-haspopup'), false); + etit(neref, 'data-unmasked', tadkak.dataset.unmasked); + etit(neref, 'data-stripe', jihid(tadkak, 'data-stripe')); + etit(neref, 'onepasswordFieldType', tadkak.dataset.onepasswordFieldType || tadkak.type); + etit(neref, 'onepasswordDesignation', tadkak.dataset.onepasswordDesignation); + etit(neref, 'onepasswordSignInUrl', tadkak.dataset.onepasswordSignInUrl); + etit(neref, 'onepasswordSectionTitle', tadkak.dataset.onepasswordSectionTitle); + etit(neref, 'onepasswordSectionFieldKind', tadkak.dataset.onepasswordSectionFieldKind); + etit(neref, 'onepasswordSectionFieldTitle', tadkak.dataset.onepasswordSectionFieldTitle); + etit(neref, 'onepasswordSectionFieldValue', tadkak.dataset.onepasswordSectionFieldValue); + tadkak.form && (neref.form = jihid(tadkak.form, 'opid')); + etit(neref, 'fakeTested', tepe(neref, tadkak), false); + + return neref; + }); + + theFields.filter(function (hefik) { + return hefik.fakeTested; + }).forEach(function (kukip) { + var cisuf = theDoc.elementsByOPID[kukip.opid]; + cisuf.getBoundingClientRect(); + var jeechgan = cisuf.value; + !cisuf || cisuf && 'function' !== typeof cisuf.click || cisuf.click(); + jesceln(cisuf, false); + cisuf.dispatchEvent(guna(cisuf, 'keydown')); + cisuf.dispatchEvent(guna(cisuf, 'keypress')); + cisuf.dispatchEvent(guna(cisuf, 'keyup')); + cisuf.value !== jeechgan && (cisuf.value = jeechgan); + cisuf.click && cisuf.click(); + kukip.postFakeTestVisible = ciquod(cisuf); + kukip.postFakeTestViewable = blekey(cisuf); + kukip.postFakeTestType = cisuf.type; + kukip = cisuf.value; + var jeechgan = cisuf.ownerDocument.createEvent('HTMLEvents'), jalue = cisuf.ownerDocument.createEvent('HTMLEvents'); + cisuf.dispatchEvent(guna(cisuf, 'keydown')); + cisuf.dispatchEvent(guna(cisuf, 'keypress')); + cisuf.dispatchEvent(guna(cisuf, 'keyup')); + jalue.initEvent('input', true, true); + cisuf.dispatchEvent(jalue); + jeechgan.initEvent('change', true, true); + cisuf.dispatchEvent(jeechgan); + cisuf.blur(); + cisuf.value !== kukip && (cisuf.value = kukip); + }); + + var pageDetails = { + documentUUID: oneShotId, + title: theDoc.title, + url: theView.location.href, + documentUrl: theDoc.location.href, + tabUrl: theView.location.href, + forms: function (basas) { + var histstap = {}; + basas.forEach(function (quavu) { + histstap[quavu.opid] = quavu; + }); + return histstap; + }(theTitle), + fields: theFields, + collectedTimestamp: new Date().getTime() + }; + + // get proper page title. maybe they are using the special meta tag? + theTitle = document.querySelector('[data-onepassword-title]') + if (theTitle && theTitle.dataset[DISPLAY_TITLE_ATTRIBUE]) { + pageDetails.displayTitle = theTitle.dataset.onepasswordTitle; + } + + return pageDetails; + } + + document.elementForOPID = jasu; + + function guna(kedol, fonor) { + var quebo; + 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.srcElement = kedol, quebo.target = kedol); + return quebo; + } + + 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.REGISTER_TITLES = 'register;sign up;signup;join;create my account;регистрация;inscription;regístrate;cadastre-se;registrieren;registrazione;注册;साइन अप करें'.split(';'); + window.SEARCH_TITLES = 'search find поиск найти искать recherche suchen buscar suche ricerca procurar 検索'.split(' '); + window.FORGOT_PASSWORD_TITLES = 'forgot geändert vergessen hilfe changeemail español'.split(' '); + window.REMEMBER_ME_TITLES = ['remember me', 'rememberme', 'keep me signed in']; + window.BACK_TITLES = ['back', 'назад']; + + function loopi(segu) { + var bitou = null; + segu && (bitou = segu.replace(/^\\s+|\\s+$|\\r?\\n.*$/gm, ''), bitou = 0 < bitou.length ? bitou : null); + return bitou; + } + + function queka(tigap, niela) { + var jahe; + jahe = ''; + 3 === niela.nodeType ? jahe = niela.nodeValue : 1 === niela.nodeType && (jahe = niela.textContent || niela.innerText); + (jahe = loopi(jahe)) && tigap.push(jahe); + } + + function quernaln(ukag) { + var relu; + ukag && void 0 !== ukag ? (relu = '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; + } + + function bozoum(edpuk, uday, siru) { + var quoto; + for (siru || (siru = 0) ; edpuk && edpuk.previousSibling;) { + edpuk = edpuk.previousSibling; + if (quernaln(edpuk)) { + return; + } + queka(uday, edpuk); + } + if (edpuk && 0 === uday.length) { + for (quoto = null; !quoto;) { + edpuk = edpuk.parentElement || edpuk.parentNode; + if (!edpuk) { + return; + } + for (quoto = edpuk.previousSibling; quoto && !quernaln(quoto) && quoto.lastChild;) { + quoto = quoto.lastChild; + } + } + quernaln(quoto) || (queka(uday, quoto), 0 === uday.length && bozoum(quoto, uday, siru + 1)); + } + } + + function ciquod(hieku) { + var liji = hieku; + hieku = (hieku = hieku.ownerDocument) ? hieku.defaultView : {}; + for (var teesi; liji && liji !== document;) { + teesi = hieku.getComputedStyle ? hieku.getComputedStyle(liji, null) : liji.style; + if (!teesi) { + return true; + } + if ('none' === teesi.display || 'hidden' == teesi.visibility) { + return false; + } + liji = liji.parentNode; + } + return liji === document; + } + + function blekey(coufi) { + 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; + if (!ciquod(coufi) || !coufi.offsetParent || 10 > coufi.clientWidth || 10 > coufi.clientHeight) { + return false; + } + var aley = coufi.getClientRects(); + if (0 === aley.length) { + return false; + } + for (var sehi = 0; sehi < aley.length; sehi++) { + if (temton = aley[sehi], temton.left > gubuech || 0 > temton.right) { + return false; + } + } + if (0 > quophe || quophe > gubuech || 0 > pudu || pudu > kosri) { + 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) { + return 0 <= Array.prototype.slice.call(coufi.labels).indexOf(muma); + } + muma = muma.parentNode; + } + return muma === coufi; + } + + function jasu(sebe) { + var jutuem; + if (void 0 === sebe || null === sebe) { + return null; + } + try { + var paraf = Array.prototype.slice.call(getFormElements(document)), viehi = paraf.filter(function (strukou) { + return strukou.opid == sebe; + }); + if (0 < viehi.length) { + jutuem = viehi[0], 1 < viehi.length && console.warn('More than one element found with opid ' + sebe); + } else { + var jotun = parseInt(sebe.split('__')[1], 10); + isNaN(jotun) || (jutuem = paraf[jotun]); + } + } catch (beynad) { + console.error('An unexpected error occurred: ' + beynad); + } finally { + return jutuem; + } + } + + // get all the form elements that we care about + function getFormElements(theDoc) { + var els = []; + try { + els = theDoc.querySelectorAll('input, select, button'); + } catch (e) { } + return els; + } + + function jesceln(calo, noru) { + if (noru) { + var klebup = calo.value; + calo.focus(); + calo.value !== klebup && (calo.value = klebup); + } else { + calo.focus(); + } + } + + return JSON.stringify(sasrie(document, 'oneshotUUID')); } function fill(document, fillScript, undefined) { var isFirefox = navigator.userAgent.indexOf('Firefox') !== -1 || navigator.userAgent.indexOf('Gecko/') !== -1; - var g=!0,k=!0; - function n(a){var b=null;return a?0===a.indexOf('https://')&&'http:'===document.location.protocol&&(b=document.querySelectorAll('input[type=password]'),0