I\'m new to javascript and tampermonkey, try to remember that in your explanations please.
This is the site I\'m trying to work with
As you can see it\'s pretty
For tutorials and questions, you can search for Greasemonkey topics. With only a few exceptions, if it works for Greasemonkey, it works for Tampermonkey by design.
As for the the question code, there are numerous issues:
text
and password
elements. In jQuery, you set them with the .val() function. EG: $("#fieldAccount").val("foo");
@grant
directive. This will bust the script, or bust the page or bust both.@match
directive does not match the page. gaurdian
is incorrect, the page uses guardian
.@match
directives are correct by looking at the Tampermonkey icon in the upper-right. If any scripts are active on that page, it will show a red icon with the number of active scripts.@match
directive does not match the page. The match specifies https
, but that site does not support SSL (!!!). You need to match the unsecure page, as that's the only one offered, and then yell at the site owners to stop broadcasting your sensitive information.getElementById
. $('input[type=password]').attr('id')
is undefined
for this target page.Storing username and password in a script file! This is one the the oldest mistakes, and exploits, in the book. If you do this, it is just a matter of time before you get pwned.
After you get the rough idea working, Incorporate a "sensitive information" framework like this one into the script.
jQuery(function($) {
. It's normally not needed in a Greasemonkey or Tampermonkey script, and just mildly obfuscates the code in this case.getElementById
when you have jQuery.document.getElementById("foo")
is the same as $("#foo")
, but the latter is easier to type, read, and maintain. True, getElementById
might be infinitesimally faster, but by such a small amount that it will never be a factor for anything practical that you are trying to do.
Putting it all together, this complete script will work:
// ==UserScript==
// @name Powerschool Memory
// @version 0.1
// @description Makes PowerSchool remember your username and password.
// @match http://powerschool.avon.k12.ct.us/guardian/home.html
// @match https://powerschool.avon.k12.ct.us/guardian/home.html
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
//-- If/when SSL becomes available, switch to only using the https pages.
$("#fieldAccount").val ("username_here");
$("#login-inputs input[name='pw']").val ("password_here");
BUT, use the framework linked in issue 6, above, instead.