我需要隐藏或显示具有我的扩展名的列。我要隐藏/显示此列
我有这个代码:
- 清单. json**
{
"manifest_version": 2,
"name": "Chat GPT Column Hider",
"description": "This extension allows you to hide the left column in Chat GPT.",
"version": "1.0",
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_popup": "popup.html"
},
"permissions": [
"https://chat.openai.com/"
]
}
- 背景. js**
function hideColumn() {
// Get the left column element and hide it
var column = document.querySelector('div.dark.hidden.bg-gray-900.md\\:fixed.md\\:inset-y-0.md\\:flex.md\\:w-[260px].md\\:flex-col');
column.style.display = 'none';
}
function showColumn() {
// Get the left column element and show it
var column = document.querySelector('div.dark.hidden.bg-gray-900.md\\:fixed.md\\:inset-y-0.md\\:flex.md\\:w-[260px].md\\:flex-col');
column.style.display = 'block';
}
- 弹出窗口. html**
<button id="hide-button">Hide Column</button>
<button id="show-button">Show Column</button>
<script src="popup.js"></script>
- 弹出窗口. js**
// Get the hide and show button elements
var hideButton = document.querySelector('#hide-button');
var showButton = document.querySelector('#show-button');
// Add event listeners to the buttons
hideButton.addEventListener('click', function() {
// When the hide button is clicked, call the hideColumn function
chrome.tabs.executeScript({
code: 'hideColumn();'
});
});
showButton.addEventListener('click', function() {
// When the show button is clicked, call the showColumn function
chrome.tabs.executeScript({
code: 'showColumn();'
});
});
我们得到这个用户界面:
但如果我按下按钮,我会得到一个错误:* 未捕获的引用错误:未定义hideColumn *
1条答案
按热度按时间wwtsj6pe1#
我重写了你的分机号。
manifest.json
popup.html
popup.js