Reputation: 7792
I've just started to use Greasemonkey and am trying to make a userscript that will scrape a page -
Before I got into that I tried running a few tests to increase my familiarity with Greasemonkey (for example I tried an userscript that had just an alert, which worked). However, after I added functions, the alert (which is called at the top), failed to work- why is this happening?
//==UserScript==
'//@name stanfordWhoScraper
//@require http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
//==/UserScript==
alert("TEST");
/*Functions*/
function jquerify(jquerified){
if(!(window.jQuery && window.jQuery.fn.jquery == '1.6.2')) {
var s = document.createElement('script');
s.setAttribute('src', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js');
s.setAttribute('type', 'text/javascript');
document.getElementsByTagName('head')[0].appendChild(s);
jquerified = true;
return jquerified;
}
}
function findName(url){
if (!typeof url) return "Enter string url"
var name = $("#PublicProfile h2").load(url);
if (name == "") return "No name found";
return name;
}'
Thanks!
Upvotes: 1
Views: 335
Reputation: 93623
There are multiple problems with that script. The 2 that keep it from running are:
Stray apostrophes as Artyom said.
Change: '//@name stanfordWhoScraper
to // @name stanfordWhoScraper
and
change: }'
to }
.
Malformed metadata block:
Whitespace is required after the leading slashes. This is wrong and fails:
//==UserScript==
//@name stanfordWhoScraper
//@require http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
//==/UserScript==
This is correct:
// ==UserScript==
// @name stanfordWhoScraper
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
// ==/UserScript==
Upvotes: 1
Reputation: 1599
Remove the single quote on line 2. It starts a string that ends when another single quote is encountered (inside your function), and therefore no parsing is made.
Upvotes: 0