Creating a custom bookmarklet that utilizes document.body.search()

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;
}

Answer №1

Always remember to check for:

document.body.textContent.indexOf('application is temporarily over its serving quota') > -1

It's important to note that there is no document.body.search function, but rather location.search(). Avoid confusion by carefully reading through the documentation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Learn the process of retrieving JSON objects through AJAX using jQuery

When making a jQuery call to an API website, I receive the results in JSON format: { "results":[ { "user":{ "gender":"female", "name":{ "title":"mrs", "first":"linda", "last":"diaz" }, ...

What causes the truncation of the backslash in the string "videos1_visualisation.mp4"?

Check out this example of AngularJS code I've created. The factory contains a list of video sources. var videoPlayer=angular.module('videoPlayer',[]) videoPlayer.controller("videoplayer",["$scope","videolist",function($scope,videolist) ...

Tips for incorporating MUI into your Redwood JS project

Trying to integrate MUI into Redwood JS has been a challenge for me. I attempted to run the following command in the project directory: yarn add @mui/material Unfortunately, an error message appeared in the console stating: An error Running this command w ...

What methods can be used to automatically direct users to a specific page in my app once they have completed the registration process?

It's possible that I'm not placing the second router.replace('/contact'); line correctly. However, it seems strange because the redirect works fine when a user logs in. Any help would be greatly appreciated. if (isLogin) { const r ...

Using the push method on a global object array will replace all existing values within the array

After researching various solutions to this issue, I have not been successful in implementing the commonly suggested fix. The variable evtList holds a collection of global objects labeled as "Event". Previous discussions advised creating a local object ( ...

Error occurred during the Uglify process: Unable to access the 'kind' property as it is undefined

I developed a project using TypeScript (version 3.9.3) and Node (version 10.16.3), but now I want to minify the code by converting it to JavaScript and running UglifyJS. However, after going through this process, the services that were functioning properly ...

Arrangement of Bootstrap card components

Each card contains dynamic content fetched from the backend. <div *ngFor="let cardData of dataArray"> <div class="card-header"> <div [innerHtml]="cardData.headerContent"></div> </div> <d ...

Transferring user inputs to the server through jQuery-AJAX

I've encountered some issues when trying to send form data inputs to the server. Despite alerting each form input, I keep getting empty alerts. Here's my code snippet: With my current code, it only alerts 0. However, posting normally seems to wor ...

Retrieve data from an array within the user Collection using Meteor and React Native

I need assistance with retrieving the entire array [votes] stored within the User Collection. Below is the JSON structure { "_id" : "pziqjwGCd2QnNWJjX", "createdAt" : ISODate("2017-12-21T22:06:41.930Z"), "emails" : [ { "a ...

Automatically customizable CSS border thickness

Consider the following example of a div element: <div style="height: 10%; width: 20%; border: 1px solid black"> Div Content </div> The div above has its height and width specified in percentages. I would like the border width to adjust a ...

Encountering issues with creating a session in Selenium/webdriver while utilizing Safari 12

Ever since making the update to Safari 12, my automated scripts have been encountering a new error: SessionNotCreatedError: Request body does not contain required parameter 'capabilities'. (Interestingly, this error is exclusive to Safari and d ...

Include a fresh attribute in the Interface

How can I include a boolean property isPhotoSelected: boolean = false; in an API interface that I cannot modify? The current interface looks like this: export interface LibraryItem { id: string; photoURL: string; thumbnailURL: string; fi ...

When a controller includes Axios or Node HTTPS requests, Express fails to send a response

Currently, I am in the process of integrating with an external webhook through Wix.com's API. However, I have encountered a problem where the presence of an Axios request or a raw Node HTTP/HTTPS request is causing issues with sending the response. B ...

The TypeError thrown by Mongo .updateMany() indicates that the property 'updateMany' of the object is not a valid function

Currently, I have a collection named users, which contains the following documents: Document 1: { "_id": { "$oid": "5934fd84d6ba4c241259bed1" }, "first_name": "Joe", "last_name": "Smith", "username": "jsmith", "email": "&l ...

Issue with document.referrer in Firefox: Unexpected behavior

I attempted to utilize the document.referrer function. It functions correctly in Google Chrome, however it does not yield the expected results in Mozilla Firefox. if (document.referrer.indexOf('stringToCheck') > 0) { //insert code here ...

Troubleshoot: Inline Styling Problem with Bootstrap 4 Popover

Is there a way to dynamically change the color of the Bootstrap 4 popover title using inline HTML style attributes? It seems that the plugin is removing them without any logical reason. Below is an example demonstrating this issue: $('#test'). ...

Why might the Bootstrap menu be malfunctioning?

The reality is that Bootstrap is functional and widely used. Sharing the code could make a big difference in getting assistance! <ul class="top-header-contact-info secondary-menu"> <li class="nav-item dropdown-toggle"> ...

Tips for consolidating all language locales into a single JSON file using Angular Translate

Is there a way to link all English variants ('en-AS', 'en-BE') to one file called 'en' (en.json)? .registerAvailableLanguageKeys( [ 'en_US', 'de_DE' ...

Having difficulty extracting data from FormData() object and encountering difficulty sending it through the frontend

Whenever I use Postman to send data, the Title, description, and image are successfully transmitted. This is how my post array looks like: router.post('/', uploadS3.array('meme',3),(req, res, next)=>{ // res.json(req.file.locatio ...

What's the best way to generate a hyperlink to Facebook and post a message?

Instead of sharing my PAGE, I'd like to share a brief message along with a shortened URL link to something. ...