Я пытаюсь запустить код jquery с кнопки в моем расширении Chrome.
Я помещаю свой код во множество различных файлов, из background.js, content.js и т. Д., Но каждый раз это "$ не определено".
manifest.json
{
"manifest_version": 2,
"name": "add title via Click",
"description": "Be able to add titles",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": ["tabs", "<all_urls>"]
}
popup.html
<!doctype html>
<html>
<head><title>Title</title></head>
<body>
<button id="press">Add title</button>
<script src="popup.js"></script>
</body>
</html>
popup.js
function injectTheScript() {
// Gets all tabs that have the specified properties, or all tabs if no properties are specified (in our case we choose current active tab)
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
// Injects JavaScript code into a page
chrome.tabs.executeScript(tabs[0].id, {file: "utilities.js"});
});
}
// adding listener to your button in popup window
document.getElementById('press').addEventListener('click', injectTheScript);
.js
/**
* Gets the desired element on the client page and add extra title on it
*/
function extraTitle() {
$("h5").append(" - Extra title works");
}
extraTitle();
Я просто хочу запускать код, нажимая мои всплывающие кнопки, как будто я запускаю их из консоли.