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:
- That is not how you set values for
text
andpassword
<input>
elements. In jQuery, you set them with the.val()
function. EG:$("#fieldAccount").val("foo");
- Requiring jQuery without a
@grant
directive. This will bust the script, or bust the page or bust both. - The
@match
directive does not match the page.gaurdian
is incorrect, the page usesguardian
.
You can tell when your@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. - The
@match
directive does not match the page. The match specifieshttps
, 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. - Improper use of
getElementById
.$('input[type=password]').attr('id')
isundefined
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.
- Unnecessary use of
jQuery(function($) {
. It's normally not needed in a Greasemonkey or Tampermonkey script, and just mildly obfuscates the code in this case. - Using
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.
jQuery approaches also are much more portable and reusable.
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.