Reputation: 9
So far I have this,
// ==UserScript==
// @name Random Creature LevelUP for Avadopts
// @namespace Xaric
// @description Clicks randomcreature for leveling up on Avadopts
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// @include *
//--- Note that the contains() text is case-sensitive.
var TargetLink = $("a:contains('Give a random creature a level!')")
if (TargetLink && TargetLink.length)
window.location.href = TargetLink[0].href
But it doesn't work.
Any thoughts to get it working?
Upvotes: 0
Views: 2477
Reputation: 633
I've never heard of a 'contains' css pseudo class but you can always just loop through the links.
var l = document.getElementsByTagName("a");
var i = l.length;
while (i--) {
if (l[i].innerHTML == "Give a random creature a level!") {
window.location.href = l[i].href;
break;
}
}
For more reliable results you could use a regular expression:
var l = document.getElementsByTagName("a");
var i = l.length;
while (i--) {
if (l[i].innerHTML.match(/random creature/)) {
window.location.href = l[i].href;
break;
}
}
Upvotes: 1
Reputation: 93473
The metadata section must be formatted precisely.
Use:
// ==UserScript==
// @name _Random Creature LevelUP for Avadopts
// @description Clicks randomcreature for leveling up on Avadopts
// @include http://avadopts.com/*
// @include http://www.avadopts.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
// ==/UserScript==
//--- Note that the contains() text is case-sensitive.
var TargetLink = $("a:contains('Give a random creature a level!')");
if (TargetLink && TargetLink.length)
window.location.href = TargetLink[0].href;
Upvotes: 1