加载 chrome 扩展并找到当前网站 javascript
Load a chrome extension and find current website javascript
我目前正在尝试 chrome 延期,但我有点迷茫 -_-
我有两个问题,第一个是如何查看用户是否在某个网站上并执行代码?
到目前为止我有这个:
if(href == "instagram") {
console.warn("You are on instagram !!")
}
但是好像没有效果。
我的第二个问题是如何添加 chrome 扩展,我遵循了教程,但它与我在屏幕上看到的不匹配
第一个问题回答
关于您的第一个问题,“href ==”不起作用,您需要 window.location.href
和 match
,例如:
if(window.location.href.match("www.instagram") {
console.warn("You are on instagram !!")
}
如果您要经常使用它,我建议将它放入一个变量中,例如 url = window.location.href
,这样您就可以使用 url.match
第二题答案
要添加 chrome 扩展程序,请转至 chrome://extensions 并单击右上角的“开发者模式”。然后你应该看到一个叫做“加载解压”的东西 - 一旦你按下这个按钮找到你的 chrome 扩展的文件夹并添加它。
目前,您正在做 href == "instagram"
。它的作用是直接比较它们。但是 href
实际上会变成 instagram.com
或 https://instagram.com/something
之类的东西,所以该语句将不起作用。
你可能想做
if (window.location.href.includes('instagram') {
console.log('You are on Instagram!');
}
对于你的第二个问题,它的答案比 SO 的真正含义要长。试着看看这个:https://webkul.com/blog/how-to-install-the-unpacked-extension-in-chrome/
我目前正在尝试 chrome 延期,但我有点迷茫 -_-
我有两个问题,第一个是如何查看用户是否在某个网站上并执行代码?
到目前为止我有这个:
if(href == "instagram") {
console.warn("You are on instagram !!")
}
但是好像没有效果。
我的第二个问题是如何添加 chrome 扩展,我遵循了教程,但它与我在屏幕上看到的不匹配
第一个问题回答
关于您的第一个问题,“href ==”不起作用,您需要 window.location.href
和 match
,例如:
if(window.location.href.match("www.instagram") {
console.warn("You are on instagram !!")
}
如果您要经常使用它,我建议将它放入一个变量中,例如 url = window.location.href
,这样您就可以使用 url.match
第二题答案
要添加 chrome 扩展程序,请转至 chrome://extensions 并单击右上角的“开发者模式”。然后你应该看到一个叫做“加载解压”的东西 - 一旦你按下这个按钮找到你的 chrome 扩展的文件夹并添加它。
目前,您正在做 href == "instagram"
。它的作用是直接比较它们。但是 href
实际上会变成 instagram.com
或 https://instagram.com/something
之类的东西,所以该语句将不起作用。
你可能想做
if (window.location.href.includes('instagram') {
console.log('You are on Instagram!');
}
对于你的第二个问题,它的答案比 SO 的真正含义要长。试着看看这个:https://webkul.com/blog/how-to-install-the-unpacked-extension-in-chrome/