我目前正在嘗試制作 chrome 擴展,但我有點迷茫-_-
我有兩個問題,我的第一個問題是如何查看用戶是否在某個網站上并執行代碼?
i have this so far:
if(href == "instagram") {
console.warn("You are on instagram !!")
}
but it doesn't seem to be working ...
我的第二個問題是如何添加 chrome 擴展程式,我遵循了教程,但我看不到他們看到的內容
uj5u.com熱心網友回復:
第一個問題回答
至于你的第一個問題,“href ==”不起作用,你需要window.location.hrefand match,像這樣:
if(window.location.href.match("www.instagram") {
console.warn("You are on instagram !!")
}
如果您要經常使用它,我建議將其放入像 一樣的變數中url = window.location.href,這樣您就可以使用url.match
第二題答案
要添加您的 chrome 擴展程式,請轉到 chrome://extensions 并單擊右上角的“開發人員模式”。然后你應該看到一個叫做“加載解包”的東西 - 一旦你按下這個,找到你的 chrome 擴展程式的檔案夾并添加它。
uj5u.com熱心網友回復:
目前,你正在做href == "instagram"。這樣做的目的是直接比較它們。但href實際上將類似于instagram.comor 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/
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/346907.html
標籤:javascript html 谷歌浏览器
上一篇:如何在Chrome開發工具上關閉元素的新大小指示器?[復制]
下一篇:具有縮放功能的一致CSS邊框寬度
