簡體   English   中英

加載 chrome 擴展並查找當前網站 javascript

[英]Load a chrome extension and find current website javascript

我目前正在嘗試制作 chrome 擴展,但我有點迷茫-_-

我有兩個問題,我的第一個問題是如何查看用戶是否在某個網站上並執行代碼?

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

我的第二個問題是如何添加 chrome 擴展程序,我遵循了教程,但我看不到他們看到的內容

第一個問題回答

至於您的第一個問題,“href ==”不起作用,您需要window.location.hrefmatch ,如下所示:

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.comhttps://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/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM