Skip to content

Commit

Permalink
Update test chrome extension
Browse files Browse the repository at this point in the history
  • Loading branch information
WavJaby committed May 9, 2024
1 parent 9a7923b commit 3e934ff
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions NCKUpp.iml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<orderEntry type="library" name="WebSocket" level="project" />
<orderEntry type="library" name="SVGBuilder" level="project" />
<orderEntry type="library" name="@types/chrome" level="application" />
<orderEntry type="library" name="@types/chrome" level="application" />
</component>
</module>
55 changes: 54 additions & 1 deletion extension/background.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,56 @@
chrome.runtime.onInstalled.addListener(() => {
chrome.action.setBadgeText({text: null});
chrome.action.setBadgeText({text: null});
});

chrome.tabs.onActivated.addListener(async function (tab) {
// chrome.scripting.executeScript({
// target: {tabId: tab.tabId},
// file: 'inject.js'
// });

});

function findStringBetween(input, where, from, end, includeFromEnd) {
let startIndex = input.indexOf(where), endIndex = -1;
if (startIndex !== -1) startIndex = input.indexOf(from, startIndex + where.length());
if (startIndex !== -1) endIndex = input.indexOf(end, startIndex + from.length());
return startIndex === -1 || endIndex === -1 ? null : includeFromEnd
? input.substring(startIndex, endIndex + end.length())
: input.substring(startIndex + from.length(), endIndex);
}

async function openLoginPage() {
const response = await fetch('https://course.ncku.edu.tw/index.php?c=auth&m=oauth&time=' +
(Date.now() / 1000), {redirect: 'follow'});
if (!response.url.startsWith('https://fs.ncku.edu.tw'))
return;
const tab = await chrome.tabs.create({url: response.url});
tab
}

chrome.webNavigation.onCompleted.addListener(async function (details) {
if (details.url !== 'https://course.ncku.edu.tw/index.php?c=portal')
return;
console.log(details);
}, {url: [{hostContains: 'course.ncku.edu.tw'}]});

// Main page
chrome.webNavigation.onCompleted.addListener(async function (details) {
const response = await fetch('https://course.ncku.edu.tw/index.php?c=auth')
const pageRaw = await response.text();

const login = pageRaw.indexOf('./index.php?c=auth&m=logout') !== -1;
if (!login) {
await openLoginPage();
}
console.log(login);
}, {url: [{hostContains: 'localhost'}]});









8 changes: 7 additions & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
"name": "NCKU++",
"description": "解鎖NCKU++的更多功能",
"version": "1.0",
"permissions": ["activeTab"],
"permissions": [
"webNavigation"
],
"host_permissions": [
"https://course.ncku.edu.tw/",
"https://fs.ncku.edu.tw/"
],
"icons": {
"64": "images/icon_64.png",
"128": "images/icon_128.png"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/wavjaby/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public class Main {
logger.log("Ready in " + (System.currentTimeMillis() - start) + "ms");
server.printStructure();

historySearch.fetchCourse(112, 112);
// historySearch.fetchCourse(112, 112);

// Stop
Scanner scanner = new Scanner(System.in);
Expand Down

0 comments on commit 3e934ff

Please sign in to comment.