I'm currently working on a bookmarklet that scans the body of a webpage for a specific text string and triggers a script when it finds a match. My code snippet document.body.search();
is resulting in an error message.
[Error] TypeError: undefined is not a function (evaluating 'document.body.search('application is temporarily over its serving quota')')
What am I doing wrong with the search()
method? Should I be targeting something other than document.body
?
Javascript
var prox='http://proxy-mirror.appspot.com/';
var prox1='http://toproxies.appspot.com/';
var prox2='http://meprxy.appspot.com/';
var prox3='http://i-love-proxy.appspot.com/';
var prox4='http://proxy0server.appspot.com/';
var prox5='http://proxy1server.appspot.com/';
var x=document.body.search('application is temporarily over its serving quota');
var url=window.location.href;
if(x!==-1) {
switch(window.location.hostname) {
case 'proxy-mirror.appspot.com':url.slice(32);window.location.href=prox1+url;
break;
case 'toproxies.appspot.com':url.slice(29);window.location.href=prox2+url;
break;
case 'meprxy.appspot.com':url.slice(26);window.location.href=prox3+url;
break;
case 'i-love-proxy.appspot.com':url.slice(32);window.location.href=prox4+url;
break;
case 'proxy0server.appspot.com':url.slice(32);window.location.href=prox5+url;
break;
case 'proxy1server.appspot.com':alert('Whoops!\n\nIt seems this site is over its quota, and its the last proxy I have on the list\n\nSorry about that, please wait until tomorrow when the servers reset and you\'ll be good to go!');break;
}
} else {
window.location.href=prox+url;
}