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)