0

I'm pretty new to Javascript and writing extensions. Right now I have a bookmarklet that I want to convert to into a Tampermonkey/Greasemonkey script so that it can be applied to every webpage / webpage of my choosing instead of having to be clicked. The bookmarklet has the following code:

javascript:(function()%7Bvar W=%5B%5D,V=Math.random,U=Math.floor,T,S,R,Q,P='password',O=U(V()*9e6),N=O+'@example.com';function M(L,H)%7Btry%7BH=L.document.getElementsByTagName(H)%7Dcatch(e)%7BH=%5B%5D%7Dfor(i=0;i<H.length;i++)%7BT=H%5Bi%5D;if(T.readOnly%7C%7CT.disabled)continue;S=T.name;R=T.type;Q=T.value;if('checkbox'==R)T.checked=V()>.5;if(P==R)Q=O;if('text'==R)%7BQ=U(V()*9e6);if(S.match(/mail/i))Q=N%7DT.value=Q;if('radio'==R)%7Bif(!++W%5BS%5D)W%5BS%5D=1;T.checked=V()<(1/W%5BS%5D)%7Dif(R.match(/%5Eselect/))T.selectedIndex=V()*(T.options.length-1)+1%7Dif(T)try%7BT.focus()%7Dcatch(e)%7B%7D%7Dfunction G(L)%7BM(L,P);M(L,'select');M(L,'input');for(var i=0;i<L.frames.length;i++)%7BG(L.frames%5Bi%5D)%7D%7DG(window)%7D());void(0)

I was told that running the bookmarklet through a JS decoder would help get the job done, such as that found here: http://meyerweb.com/eric/tools/dencoder/

Unfortunately, I'm not really sure what to do with the decoded script. I know that I have to remove the "javascript:" bit when placing the new script into tampermonkey/greasemonkey, but still, the code will not work. There's clearly steps I seem to be missing. Could anybody point me in the right direction? The resulting decoded JS script is:

javascript:(function(){var W=[],V=Math.random,U=Math.floor,T,S,R,Q,P='password',O=U(V()*9e6),N=O '@example.com';function M(L,H){try{H=L.document.getElementsByTagName(H)}catch(e){H=[]}for(i=0;i<H.length;i ){T=H[i];if(T.readOnly||T.disabled)continue;S=T.name;R=T.type;Q=T.value;if('checkbox'==R)T.checked=V()>.5;if(P==R)Q=O;if('text'==R){Q=U(V()*9e6);if(S.match(/mail/i))Q=N}T.value=Q;if('radio'==R){if(! W[S])W[S]=1;T.checked=V()<(1/W[S])}if(R.match(/^select/))T.selectedIndex=V()*(T.options.length-1) 1}if(T)try{T.focus()}catch(e){}}function G(L){M(L,P);M(L,'select');M(L,'input');for(var i=0;i<L.frames.length;i ){G(L.frames[i])}}G(window)}());void(0)

wbhyatt
  • 43
  • 2
  • 5
  • 12
  • Also here is your code de-obscured http://pastebin.com/mxveHasu – GramThanos Feb 18 '17 at 00:45
  • thank you so much, the way you broke it down was incredibly informative and helpful. cheers! – wbhyatt Feb 18 '17 at 03:17
  • So the script works and automatically loads autofilled information on some sites, but doesn't on other sites. However, the bookmarklet works on every site I've used it on (when pressed, of course). Is there a way to have your decoded script automatically load at every page? Perhaps using @include? Or does the fact that it's not working on some sites mean there's a serve-side barrier? – wbhyatt Feb 18 '17 at 03:45
  • 1
    The problem with the script is that it is not so good. It fails to detect all inputs. Only passwords are always an `input` with a `password` type. You can improve it by checking more attributes. For example you can check if `mail` match the `id` or the `type` attributes of the input. – GramThanos Feb 18 '17 at 09:17
  • Again, thanks for your help. You've been awesome. So from doing a little research I found that some sites, like Qualtrics (a survey site) have a function that sets autocomplete=off, coded into their pages. Do you know of any way to bypass this? – wbhyatt Feb 21 '17 at 00:17
  • ... remove it? `input.removeAttribute('autocomplete');`. But I don't think this attribute blocks the javascript from inserting a value. It just disable suggestions https://www.w3schools.com/Tags/att_input_autocomplete.asp – GramThanos Feb 21 '17 at 00:30

0 Answers0