Just starting out with chrome extensions and looking to create one that appends an external class to a selected tag.
For example, let's say we have the following tag:
<h1>extension</h1>
When the user clicks on this element, I want to add an external class to it in the DOM. The tag should not be empty.
To achieve this, I am working on a chrome extension. I need to have a fixed popup or canvas similar to using CSS Selectors.
I want my popup.html to remain open only when I click on the close button, not when I interact with elements on the page. Currently, I am facing issues as the popup closes every time I click on the webpage.
This is the code from my manifest file:
{
"manifest_version": 2,
"name":"Spider_Extension",
"version":"1.0",
"permissions": [
"tabs"
],
"content_scripts":[{
"matches":[
"<all_urls>"
],
"js":["Content.js"]
}],
"background": {
"scripts": ["background.js"]
},
"browser_action":{
"default_icon":"get_started16.png"
}
}
This is the content of my background.js file:
function button_clicked(tab){
let msg={
txt:"hello"
}
console.log(tab)
chrome.tabs.sendMessage(tab.id,msg);
}
Here is the code from my popup.html file:
<html>
<head>
<title>Spider extension</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<label for="cars">Select Level:</label>
<select id="levels">
<option value="l1">L1</option>
<option value="l2">L2</option>
<option value="l3">L3</option>
<option value="l4">L4</option>
</select>
<br>
<button id="addLevel" style="margin:5px;">Add level</button>
<br>
<button id="break" style="margin:5px;">Break</button>
<br>
<button id="deselect" style="margin:5px;">Deselect</button>
<br>
<button id="nd__close">X</button>
<script src="popup.js"></script>
</body>
</html>
If anyone has any insights or solutions on how to tackle this issue, I would greatly appreciate it!
Thank you in advance