In my project, I have created an extension file named github.js
jQuery(document).ready(function($) {
console.log('github.js');
// btn btn-primary shelf-cta
var button = $('.btn.btn-primary.shelf-cta');
console.log('button.html() = ', button.html());
button.click();
});
The next file is popup.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8>
<title>Document</title>
</head>
<body>
<button id="send_messages">Send Messages</button>
<script src="libs/jquery-v3.3.1.js"></script>
<script src="popup.js"></script>
</body>
</html>
Now we move on to the file popup.js
jQuery(document).ready(function($) {
console.log('popup.js');
$('#send_messages').click(function(event) {
console.log('github test');
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.executeScript(
tabs[0].id,
{file: "libs/jquery-v3.3.1.js"},
function(){
chrome.tabs.executeScript(
tabs[0].id,
{file: "github.js"}
);
}
);
});
});
});
Lastly, there's a file named manifest.json
{
"name": "test the extension",
"version": "1.0",
"description": "Automatically send the message to the opened projects in the browser",
"permissions": [
"tabs",
"activeTab",
"declarativeContent",
"storage",
"<all_urls>"
],
"options_page": "options.html",
"background": {
"scripts": ["background.js"],
"persistent": false
},
"browser_action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
}
},
"icons": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
},
"manifest_version": 2
}
When visiting the github page at https://github.com/, you may notice a button titled "read the guide" that you want to click. Upon clicking the browser action button for the extension, a pop-up window appears. However, clicking the "send a message" button does not trigger any action. Despite being able to locate and display the title of the "read the guide" button, the functionality of button.click(); remains non-functional. Any suggestions on how to effectively interact with buttons or links on the webpage?