Home > Blockchain >  Load a chrome extension and find current website javascript
Load a chrome extension and find current website javascript

Time:11-04

I'm currently trying to make a chrome extension but i'm a bit lost -_-

I have two questions, my first one is how do i go about seeing is a user is on a certain website and execute code ?

i have this so far:
if(href == "instagram") {
    console.warn("You are on instagram !!")
}
but it doesn't seem to be working ...

my second question is how do i add a chrome extension, i followed a tutorial but i can't see what they see

CodePudding user response:

First question answer

As for your first question, "href == " doesn't work, you need window.location.href and match, like so:

if(window.location.href.match("www.instagram") {
    console.warn("You are on instagram !!")
}

If you're going to be using this a lot I recommend putting it into a variable like url = window.location.href, so then you can just use url.match

Second question answer

To add your chrome extension, go to chrome://extensions and click "developer mode" in the top right. Then you should see something called "load unpacked" - once you press this locate the folder for your chrome extension and add it.

CodePudding user response:

At the moment, you are doing href == "instagram". What this does, is compare them directly. But the href is actually going to be something like instagram.com or https://instagram.com/something, so the statement won't work.

You probably want to do

if (window.location.href.includes('instagram') {
    console.log('You are on Instagram!');
}

For your second question, it's a longer answer than SO is really meant for. Try taking a look at this: https://webkul.com/blog/how-to-install-the-unpacked-extension-in-chrome/

  • Related