我有這個簡單的擴展,它在鉻的工具欄上顯示圖標,並顯示一個啓用/禁用按鈕。我想補充的功能按鈕來禁用或啓用它觸發對訪問谷歌網站的content_script.js
:如何在google擴展中開啓/關閉content_scripts?
popup.js
var setLayout = function(){
var list = document.createElement('ul');
var enable = document.createElement('li');
enable.appendChild(document.createTextNode('Enable Script'));
enable.onclick = function(){toggle(0)};
var disable = document.createElement('li');
disable.appendChild(document.createTextNode('Disable Script'));
disable.onclick = function(){toggle(1)};
list.appendChild(disable);
document.body.appendChild(list);
function toggle(n){
list.removeChild(n == 0 ? enable : disable);
list.appendChild(n == 0 ? disable : enable);
}
};
document.addEventListener('DOMContentLoaded', setLayout, false);
的manifest.json
{
"manifest_version": 2,
"name": "test",
"description": "test",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["https://www.google.co.uk/"],
"js": ["content_scripts.js"]
}
]
}
content_scripts.js
(function(){
alert('hello');
})();
我是新的谷歌擴展,不知道該怎麼做,我想在點擊禁用/啓用按鈕後更改顯示器,但在閱讀Google網站上的文檔後找不到正確的命令。
任何幫助將grely讚賞。
感謝您的回答,但它並沒有多大幫助,我對谷歌的擴展很陌生。如果您可以詳細闡述您的答案或展示如何在您的代碼中應用您的解決方案,那麼它就會變得更加龐大。 – razzak