Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name ASC auto login and signin
- // @namespace http://www.squarefree.com/userscripts
- // @description Automatically submit autofilled sigin forms
- // @include https://idmsa.apple.com/appleauth*
- // @include https://idmsa.apple.com/IDMSWebAuth/login?appIdKey=*
- // @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
- // @grant none
- // @version 15Mar2017
- // ==/UserScript==
- /*
- More dump routines
- http://stackoverflow.com/questions/2934787/view-list-of-all-javascript-variables-in-google-chrome-console
- */
- var signinTries = 0;
- /* ====================================================================== */
- /* login to the old Style ASC password web page */
- /* Code from GreaseMonkey Hacks: Tips & Tools for Remixing the
- Web with Firefox by Mark Pilgrim */
- function submitFirstPasswordForm()
- {
- if (debug) console.log("in submitFirstPasswordForm.")
- for (var elmForm, i=0; elmForm=document.forms[i]; ++i)
- {
- var numPasswordElements = 0;
- for (var j=0; elmFormElement=elmForm.elements[j]; ++j)
- {
- if (debug) console.log("elmFormElement.type is " + elmFormElement.type);
- if (elmFormElement.type == "password" &&
- elmFormElement.value &&
- elmFormElement.value.toLowerCase() != "password")
- {
- ++numPasswordElements;
- }
- } /* of for j */
- if (numPasswordElements != 1)
- { continue; /* not something we are prepared to handle. Next i */}
- if (debug) console.log("found password.")
- /*
- * The obvious way to submit a login form is form.submit().
- * However, this doesn't work with some forms, such as
- * the Google AdWords login, because they do stuff
- * in the onclick handler of the submit button. So we
- * need to find the submit button and simulate a click.
- */
- var elmSubmit = document.evaluate(".//input[@type='image']",
- elmForm,
- null,
- XPathResult.FIRST_ORDERED_NODE_TYPE,
- null).singleNodeValue;
- if (!elmSubmit)
- {
- elmSubmit = document.evaluate(".//input[@type='submit']",
- elmForm,
- null,
- XPathResult.FIRST_ORDERED_NODE_TYPE,
- null).singleNodeValue;
- }
- if (!elmSubmit)
- { continue; }
- /*
- * Give a visual indication that we're logins to web sitesauto-submitting the
- * form, then simulate a click on the submit button.
- */
- var zero = 0;
- if (debug) console.log("clicking...");
- var z = 0;
- elmSubmit.focus();
- /* Doesn't seem to last long enough for use to observe */
- elmSubmit.style.MozOutline = "2px solid purple";
- elmSubmit.click();
- } /* end of for i */
- } /* end of submitFirstPasswordForm */
- /* ====================================================================== */
- /* when ASC signin password is present, click on the arrow icon to signin */
- function submitSignin()
- {
- if (debug) console.log("in function submitSignin...");
- signinTries++
- /* Wait for the iFrame javascript to run and for firefox to fill in the password. */
- if (signinTries> 9)
- {
- if (debug) console.log("done trying.");
- return; // we are done trying. Let the user proced manually.
- }
- if (debug) console.log("signinTries= " + signinTries.toString());
- try
- {
- /* iframe javascript fills in password fields. We wait for pwd. */
- /* firefox fills in password */
- if ( document.getElementById("pwd").value == '')
- {
- /* We know Firefox hasn't filled in password fields in iframe */
- if (debug) console.log("wait on Firefox bit.");
- setTimeout(submitSignin, 100);
- return;
- }
- }
- catch (e)
- {
- /* The signin page uses Javascript code to inject the password. Wait another bit.
- */
- if (debug) console.log("wait a bit.");
- setTimeout(submitSignin, 100);
- return;
- }
- /* All present and accounted for. */
- /* click on the signin icon */
- try
- {
- elmSubmit = document.getElementById("sign-in")
- if (debug) console.log("elmSubmit " + elmSubmit);
- elmSubmit.focus();
- /* Doesn't seem to last long enough for use to observe */
- elmSubmit.style.MozOutline = "2px solid purple";
- if (debug) console.log("'Click' on signin icon");
- elmSubmit.click();
- }
- catch (e)
- {
- console.log("failure with elmSubmit..."+e.message);
- }
- } /* End of function submitSignin */
- /* =================== first line of code ================================ */
- var aDate = new Date();
- console.log ("--> Check for sigin and login with password. " +
- " on " + aDate );
- if (debug<=2) console.log("document.domain is " + document.domain );
- /* Returns the location of the iFrame. */
- if (debug) console.log("window.location.href:\n" + window.location.href );
- // Distinguish between the older ASC login and the newer ASC signin
- // We get the url of the iFrame not the signin url
- /*
- https://idmsa.apple.com/appleauth/auth/signin?widgetKey=
- https://idmsa.apple.com/IDMSWebAuth/login?appIdKey=
- 012345678901234567890123456789012345678901234567890123456789
- 1 2 3 4 5 */
- var res = window.location.href.substr(0, 51);
- if (debug) console.log("page substring:\n" + res );
- if ( res == "https://idmsa.apple.com/appleauth/auth/signin?widge")
- {
- if (debug) console.log ("--> Signin");
- /* The signin page uses Javascript code to inject the password prompt. Wait for the
- code to complet. */
- window.addEventListener("load", function() {
- if (debug) console.log ("--> load event");
- /*
- * Using setTimeout to give Firefox's password manager a chance
- * to autofill the form.
- */
- setTimeout(submitSignin, 100);
- }, false);
- }
- else if (res == "https://idmsa.apple.com/IDMSWebAuth/login?appIdKey=")
- {
- if (debug) console.log ("--> Login");
- window.addEventListener("load", function() {
- /*
- * Using setTimeout to give Firefox's password manager a chance
- * to autofill the form.
- */
- setTimeout(submitFirstPasswordForm, 0);
- }, false);
- }
- else
- {
- console.log ("--> Unsupported web site!");
- alert("--> Unsupported web site! Ignoring.")
- }
- if (debug) console.log("...after sorting web site ... ");
- /* Hocus Pocus */
- var done = 1;
- /* make invoker happy */
- done = 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement