From 203e96e9db42cfaac1234abb20ef1f9611c065cc Mon Sep 17 00:00:00 2001 From: Chris Meek Date: Mon, 9 Feb 2015 14:59:49 -0500 Subject: [PATCH] Update collect fields script --- OnePasswordExtension.m | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/OnePasswordExtension.m b/OnePasswordExtension.m index b37ec8c..6e56a4e 100644 --- a/OnePasswordExtension.m +++ b/OnePasswordExtension.m @@ -516,18 +516,18 @@ - (void)executeFillScript:(NSString *)fillScript inWebView:(id)webView completio #pragma mark - WebView field collection and filling scripts -static NSString *const OPWebViewCollectFieldsScript = @"document.collect=p;document.elementsByOPID={};\ -function p(e,d){function f(a,b){var c=a[b];return'string'==typeof c||'function'==typeof a.getAttribute&&(c=a.getAttribute(b),'string'==typeof c)?c:null}function g(a){var b,c;if(!a)return'';if(a._idCache)return a._idCache;if('BODY'==a.tagName)return a.tagName;b=a.parentNode;if(!b)return'';c=b.childNodes;for(b=0;b<=c.length;b++)if(c[b]==a)return b=g(a.parentNode)+'/'+a.tagName+'['+b+']',a._idCache=b;return''}function q(a){return a.options?(a=Array.prototype.slice.call(a.options).map(function(a){return[k(a.text),a.value]}),\ -{options:a}):null}function s(a){var b;for(a=a.parentElement||a.parentNode;a&&'td'!=l(a.tagName);)a=a.parentElement||a.parentNode;if(!a||void 0===a)return null;b=a.parentElement||a.parentNode;if('tr'!=b.tagName.toLowerCase())return null;b=b.previousElementSibling;if(!b||'tr'!=(b.tagName+'').toLowerCase()||b.cells&&a.cellIndex>=b.cells.length)return null;a=b.cells[a.cellIndex];return k(a.innerText||a.textContent)}function w(a){var b=e.documentElement,c=a.getBoundingClientRect(),f=b.getBoundingClientRect(),\ -d=c.left-b.clientLeft,b=c.top-b.clientTop;return a.offsetParent?0>d||d>f.width||0>b||b>f.height?t(a):(f=a.ownerDocument.elementFromPoint(d+3,b+3))?'label'===l(f.tagName)?f===x(a):f.tagName===a.tagName:!1:!1}function t(a){for(var b;a!==e&&a;a=a.parentNode)if(b=u.getComputedStyle?u.getComputedStyle(a,null):a.style,'none'===b.display||'hidden'==b.visibility)return!1;return a===e}function x(a){var b=e.querySelector(\"label[for='\"+String.prototype.replace.call(a.id,\"'\",\"\\\\'\")+\"']\")||e.querySelector(\"label[for='\"+\ -String.prototype.replace.call(a.name,\"'\",\"\\\\'\")+\"']\");if(b)return b.innerText;for(;a&&a!=e;a=a.parentNode)if('label'===l(a.tagName))return a.innerText;return null}function k(a){return(a=a?l(a).replace(/\\s/mg,'').replace(/[~`!@$%^&*()\\-_+=:;'\"\\[\\]|\\\\,<.>\\/?]/mg,''):null)?a:null}function h(a,b,c){null!==c&&void 0!==c&&(a[b]=c)}function l(a){return'string'===typeof a?a.toLowerCase():(''+a).toLowerCase()}var u=e.defaultView?e.defaultView:window,m=RegExp('(pin|password|passwort|kennwort|passe|contraseña|senha|密码|adgangskode|hasło|wachtwoord)',\ -'i'),C=Array.prototype.slice.call(e.querySelectorAll('form')).map(function(a,b){var c={},e='__form__'+b;a.opid=e;c.opid=e;h(c,'htmlName',f(a,'name'));h(c,'htmlID',f(a,'id'));h(c,'htmlAction',r(f(a,'action')));h(c,'htmlMethod',f(a,'method'));return c}),z=Array.prototype.slice.call(e.querySelectorAll('input, select')).map(function(a,b){var c={},d='__'+b;e.elementsByOPID[d]=a;a.opid=d;c.opid=d;c.elementNumber=b;c.maxLength=-1==a.maxLength?999:a.maxLength;c.visible=t(a);c.viewable=w(a);c.parentId=g(a.parentNode);\ -h(c,'htmlID',f(a,'id'));h(c,'htmlName',f(a,'name'));h(c,'htmlClass',f(a,'class'));if('hidden'!=l(a.type)){h(c,'label-tag',k(x(a)));h(c,'label-data',k(f(a,'data-label')));h(c,'label-aria',k(f(a,'aria-label')));h(c,'label-top',s(a));for(var d=[],n=a;n&&n.nextSibling;){n=n.nextSibling;if(v(n))break;y(d,n)}d=k(d.join(''));h(c,'label-right',d);d=[];A(a,d);d=k(d.reverse().join(''));h(c,'label-left',d);h(c,'placeholder',f(a,'placeholder'))}h(c,'rel',f(a,'rel'));h(c,'type',l(f(a,'type')));a:switch(l(a.type)){case 'checkbox':d=\ -a.checked?'✓':'';break a;default:d=a.value}h(c,'value',d);h(c,'checked',a.checked);h(c,'autoCompleteType',a.getAttribute('x-autocompletetype')||a.getAttribute('autocompletetype')||a.getAttribute('autocomplete'));h(c,'selectInfo',q(a));h(c,'aria-hidden','true'==a.getAttribute('aria-hidden'));h(c,'aria-disabled','true'==a.getAttribute('aria-disabled'));h(c,'aria-haspopup','true'==a.getAttribute('aria-haspopup'));a.form&&(c.form=a.form.opid);d=(m.test(c.value)||m.test(c.htmlID)||m.test(c.htmlName)||\ -m.test(c.placeholder)||m.test(c['label-tag'])||m.test(c['label-data'])||m.test(c['label-aria']))&&('text'==c.type||'password'==c.type&&!c.visible);c.fakeTested=d;return c});z.filter(function(a){return a.fakeTested}).forEach(function(a){var b=e.elementsByOPID[a.opid];b.getBoundingClientRect();!b||b&&'function'!==typeof b.click||b.click();b.focus();B(b,'keydown');B(b,'keyup');B(b,'keypress');b.click&&b.click();a.postFakeTestVisible=t(b);a.postFakeTestViewable=w(b);a=b.ownerDocument.createEvent('HTMLEvents');\ -var c=b.ownerDocument.createEvent('HTMLEvents');B(b,'keydown');B(b,'keyup');B(b,'keypress');c.initEvent('input',!0,!0);b.dispatchEvent(c);a.initEvent('change',!0,!0);b.dispatchEvent(a);b.blur()});return{documentUUID:d,title:e.title,url:u.location.href,forms:function(a){var b={};a.forEach(function(a){b[a.opid]=a});return b}(C),fields:z,collectedTimestamp:(new Date).getTime()}};document.elementForOPID=D;function B(e,d){var f;f=e.ownerDocument.createEvent('KeyboardEvent');f.initKeyboardEvent?f.initKeyboardEvent(d,!0,!0):f.initKeyEvent&&f.initKeyEvent(d,!0,!0,null,!1,!1,!1,!1,0,0);e.dispatchEvent(f)}function y(e,d){var f;f='';3===d.nodeType?f=d.nodeValue:1===d.nodeType&&(f=d.innerText||d.textContent);var g=null;f&&(g=f.toLowerCase().replace(/\\s/mg,'').replace(/[~`!@$%^&*()\\-_+=:;'\"\\[\\]|\\\\,<.>\\/?]/mg,''),g=0\\/?]/mg,''):null;return[b?b:null,a.value]}),{options:a}):null}function r(a){var c;for(a=a.parentElement||a.parentNode;a&&'td'!=k(a.tagName);)a=a.parentElement||a.parentNode;if(!a||void 0===a)return null;c=a.parentElement||a.parentNode;if('tr'!=c.tagName.toLowerCase())return null;c=c.previousElementSibling;if(!c||'tr'!=(c.tagName+'').toLowerCase()||c.cells&&a.cellIndex>=c.cells.length)return null;a=c.cells[a.cellIndex];return a.innerText||\ +a.textContent}function v(a){var c=d.documentElement,b=a.getBoundingClientRect(),f=c.getBoundingClientRect(),e=b.left-c.clientLeft,c=b.top-c.clientTop;return a.offsetParent?0>e||e>f.width||0>c||c>f.height?s(a):(f=a.ownerDocument.elementFromPoint(e+3,c+3))?'label'===k(f.tagName)?f===w(a):f.tagName===a.tagName:!1:!1}function s(a){for(var c;a!==d&&a;a=a.parentNode)if(c=t.getComputedStyle?t.getComputedStyle(a,null):a.style,'none'===c.display||'hidden'==c.visibility)return!1;return a===d}function w(a){function c(a){return String.prototype.replace.call(a,\ +\"'\",\"\\\\'\")}var b;if(c(a.id)&&(b=d.querySelector(\"label[for='\"+c(a.id)+\"']\"))||c(a.name)&&(b=d.querySelector(\"label[for='\"+c(a.name)+\"']\")))return b.innerText;for(;a&&a!=d;a=a.parentNode)if('label'===k(a.tagName))return a.innerText;return null}function h(a,c,b){null!==b&&void 0!==b&&(a[c]=b)}function k(a){return'string'===typeof a?a.toLowerCase():(''+a).toLowerCase()}var t=d.defaultView?d.defaultView:window,l=RegExp('(pin|password|passwort|kennwort|passe|contraseña|senha|密码|adgangskode|hasło|wachtwoord)',\ +'i'),B=Array.prototype.slice.call(d.querySelectorAll('form')).map(function(a,c){var b={},d='__form__'+c;a.opid=d;b.opid=d;h(b,'htmlName',f(a,'name'));h(b,'htmlID',f(a,'id'));h(b,'htmlAction',q(f(a,'action')));h(b,'htmlMethod',f(a,'method'));return b}),y=Array.prototype.slice.call(d.querySelectorAll('input, select')).map(function(a,c){var b={},e='__'+c;d.elementsByOPID[e]=a;a.opid=e;b.opid=e;b.elementNumber=c;b.maxLength=-1==a.maxLength?999:a.maxLength;b.visible=s(a);b.viewable=v(a);b.parentId=g(a.parentNode);\ +h(b,'htmlID',f(a,'id'));h(b,'htmlName',f(a,'name'));h(b,'htmlClass',f(a,'class'));if('hidden'!=k(a.type)){h(b,'label-tag',w(a));h(b,'label-data',f(a,'data-label'));h(b,'label-aria',f(a,'aria-label'));h(b,'label-top',r(a));for(var e=[],m=a;m&&m.nextSibling;){m=m.nextSibling;if(u(m))break;x(e,m)}h(b,'label-right',e.join(''));e=[];z(a,e);e=e.reverse().join('');h(b,'label-left',e);h(b,'placeholder',f(a,'placeholder'))}h(b,'rel',f(a,'rel'));h(b,'type',k(f(a,'type')));a:switch(k(a.type)){case 'checkbox':e=\ +a.checked?'✓':'';break a;default:e=a.value}h(b,'value',e);h(b,'checked',a.checked);h(b,'autoCompleteType',a.getAttribute('x-autocompletetype')||a.getAttribute('autocompletetype')||a.getAttribute('autocomplete'));h(b,'selectInfo',p(a));h(b,'aria-hidden','true'==a.getAttribute('aria-hidden'));h(b,'aria-disabled','true'==a.getAttribute('aria-disabled'));h(b,'aria-haspopup','true'==a.getAttribute('aria-haspopup'));a.form&&(b.form=a.form.opid);e=(l.test(b.value)||l.test(b.htmlID)||l.test(b.htmlName)||\ +l.test(b.placeholder)||l.test(b['label-tag'])||l.test(b['label-data'])||l.test(b['label-aria']))&&('text'==b.type||'password'==b.type&&!b.visible);b.fakeTested=e;return b});y.filter(function(a){return a.fakeTested}).forEach(function(a){var c=d.elementsByOPID[a.opid];c.getBoundingClientRect();!c||c&&'function'!==typeof c.click||c.click();c.focus();A(c,'keydown');A(c,'keyup');A(c,'keypress');c.click&&c.click();a.postFakeTestVisible=s(c);a.postFakeTestViewable=v(c);a=c.ownerDocument.createEvent('HTMLEvents');\ +var b=c.ownerDocument.createEvent('HTMLEvents');A(c,'keydown');A(c,'keyup');A(c,'keypress');b.initEvent('input',!0,!0);c.dispatchEvent(b);a.initEvent('change',!0,!0);c.dispatchEvent(a);c.blur()});return{documentUUID:e,title:d.title,url:t.location.href,forms:function(a){var c={};a.forEach(function(a){c[a.opid]=a});return c}(B),fields:y,collectedTimestamp:(new Date).getTime()}};document.elementForOPID=C;function A(d,e){var f;f=d.ownerDocument.createEvent('KeyboardEvent');f.initKeyboardEvent?f.initKeyboardEvent(e,!0,!0):f.initKeyEvent&&f.initKeyEvent(e,!0,!0,null,!1,!1,!1,!1,0,0);d.dispatchEvent(f)}function x(d,e){var f;f='';3===e.nodeType?f=e.nodeValue:1===e.nodeType&&(f=e.innerText||e.textContent);var g=null;f&&(g=f.trim(),g=0