-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9bc384
commit d6a64ff
Showing
8 changed files
with
38 additions
and
66 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
chrome.runtime.onInstalled.addListener(function() { | ||
console.log("Extension installed"); | ||
// Perform on install actions, e.g., setting up default values in storage | ||
chrome.tabs.create({ url: 'http://google.com' }); | ||
}); | ||
// chrome.runtime.onInstalled.addListener(function() { | ||
// console.log("Extension installed"); | ||
// // Perform on install actions, e.g., setting up default values in storage | ||
// chrome.tabs.create({ url: 'http://google.com' }); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,19 @@ | ||
// content.js | ||
// This script will change the background color of the Google homepage to lightblue | ||
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { | ||
if (request.action === "fetchData") { | ||
var courseInfoDiv = document.getElementById('app-course-info'); | ||
if (courseInfoDiv) { | ||
var courseTitle = courseInfoDiv.querySelector('.app-text-engage').textContent; | ||
var courseDescription = courseInfoDiv.querySelectorAll('.col-sm-12')[1].textContent.trim(); | ||
|
||
// Check if the current page is Google's homepage | ||
if (window.location.hostname === 'www.google.com' && window.location.pathname === '/') { | ||
// Change the background color to lightblue | ||
document.body.style.backgroundColor = 'lightblue'; | ||
|
||
// Add a custom message to the page | ||
const messageDiv = document.createElement('div'); | ||
messageDiv.textContent = 'This is a message from your Chrome Extension!'; | ||
messageDiv.style.position = 'fixed'; | ||
messageDiv.style.bottom = '10px'; | ||
messageDiv.style.right = '10px'; | ||
messageDiv.style.padding = '10px'; | ||
messageDiv.style.backgroundColor = '#fff'; | ||
messageDiv.style.border = '1px solid #ddd'; | ||
messageDiv.style.borderRadius = '4px'; | ||
messageDiv.style.boxShadow = '0 2px 4px rgba(0,0,0,0.2)'; | ||
document.body.appendChild(messageDiv); | ||
} | ||
|
||
// Listen for messages from the background script or popup | ||
chrome.runtime.onMessage.addListener( | ||
function(request, sender, sendResponse) { | ||
if (request.greeting === "hello") { | ||
console.log("Hello from the background script!"); | ||
// Perform actions based on the message | ||
sendResponse({farewell: "goodbye"}); | ||
// Remove sentences that start with "Credit" or "Prerequisite" | ||
courseDescription = courseDescription.replace(/Credit.*?(\.|\?|!)(?=\s|$)/g, ''); | ||
courseDescription = courseDescription.replace(/Prerequisite.*?(\.|\?|!)(?=\s|$)/g, ''); | ||
|
||
sendResponse({ | ||
courseTitle: courseTitle, | ||
courseDescription: courseDescription.trim() | ||
}); | ||
} | ||
} | ||
); | ||
|
||
// This is just an example and won't necessarily do anything meaningful | ||
// unless it's part of a larger extension that you've configured to work with Google's homepage. | ||
|
||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Popup Example</title> | ||
<title>Popup</title> | ||
<style> | ||
/* Add your styles here */ | ||
body { | ||
width: 200px; | ||
height: 100px; | ||
margin: 10px; | ||
font-family: "Segoe UI", sans-serif; | ||
font-size: 14px; | ||
text-align: center; | ||
} | ||
#status { | ||
margin-top: 20px; | ||
} | ||
button { | ||
margin-top: 10px; | ||
padding: 5px 15px; | ||
width: 300px; | ||
padding: 10px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="status">Click the button below!</div> | ||
<button id="changeColor">Change Color</button> | ||
|
||
<h1>Course Information</h1> | ||
<div id="courseTitle"></div> | ||
<div id="courseDescription"></div> | ||
<script src="popup.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
// popup.js | ||
document.addEventListener('DOMContentLoaded', function() { | ||
var changeColorButton = document.getElementById('changeColor'); | ||
// onClick's logic below: | ||
changeColorButton.addEventListener('click', function() { | ||
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { | ||
// Send a message to the active tab | ||
chrome.tabs.sendMessage(tabs[0].id, {color: "blue"}, function(response) { | ||
console.log('Color changed to blue'); | ||
}); | ||
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { | ||
chrome.tabs.sendMessage(tabs[0].id, {action: "fetchData"}, function(response) { | ||
if(response) { | ||
document.getElementById('courseTitle').textContent = response.courseTitle; | ||
document.getElementById('courseDescription').textContent = response.courseDescription; | ||
} | ||
}); | ||
}, false); | ||
}, false); | ||
}); | ||
}); |