Skip to content

Commit

Permalink
11/15
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhaohuang committed Nov 16, 2023
1 parent d9bc384 commit d6a64ff
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 66 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file added Project Progress Report.pdf
Binary file not shown.
10 changes: 5 additions & 5 deletions background.js
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' });
// });
49 changes: 16 additions & 33 deletions content.js
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.

}
});
1 change: 1 addition & 0 deletions course_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ def is_valid_wikipedia_page(title, lang='en'):
print("Keywords (SpaCy):", keywords_spacy)
print("Wikipedia Links:", wikipedia_links)
print("Wikipedia Links (SpaCy):", wikipedia_links_spacy)

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"matches": ["https://courses.illinois.edu/schedule/*"],
"js": ["content.js"]
}
]
Expand Down
24 changes: 7 additions & 17 deletions popup.html
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>
18 changes: 8 additions & 10 deletions popup.js
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);
});
});

0 comments on commit d6a64ff

Please sign in to comment.