diff --git a/.gitignore b/.gitignore index 1d74e21..7aa1a6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ .vscode/ + +_metadata/ +.DS_Store \ No newline at end of file diff --git a/icons/folder.png b/icons/folder.png new file mode 100644 index 0000000..2910c3f Binary files /dev/null and b/icons/folder.png differ diff --git a/images/noise.png b/images/noise.png new file mode 100644 index 0000000..75d77cb Binary files /dev/null and b/images/noise.png differ diff --git a/manifest.json b/manifest.json index 651a309..b944ebf 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,8 @@ { "manifest_version": 3, - "name": "SuperEZ", - "version": "1.3.1", - "description": "Better online HKU experience with SuperEZ", + "name": "SuperEZ BETA", + "version": "1.3.1.3", + "description": "Better online HKU experience with SuperEZ (THIS EXTENSION IS FOR BETA TESTING)", "background": { "service_worker": "scripts/background.js" }, @@ -110,13 +110,24 @@ "tabs", "activeTab", "cookies", - "downloads" + "downloads", + "webRequest", + "declarativeNetRequest" ], "host_permissions": [ "https://hkuportal.hku.hk/*", "https://moodle.hku.hk/*", "https://booking.lib.hku.hk/*" ], + "declarative_net_request": { + "rule_resources": [ + { + "id": "ruleset_1", + "enabled": true, + "path": "rules/moodle_pdf_download_rules.json" + } + ] + }, "icons": { "16": "images/icon16.png", "32": "images/icon32.png", @@ -130,7 +141,8 @@ { "resources": [ "images/setting.svg", - "icons/*.png" + "icons/*.png", + "images/noise.png" ], "matches": [ "" diff --git a/rules/moodle_pdf_download_rules.json b/rules/moodle_pdf_download_rules.json new file mode 100644 index 0000000..3f11828 --- /dev/null +++ b/rules/moodle_pdf_download_rules.json @@ -0,0 +1,18 @@ +[{ + "id": 1, + "priority": 1, + "action": { + "type": "redirect", + "redirect": { + "transform": { + "queryTransform": { + "removeParams": ["forcedownload"] + } + } + } + }, + "condition": { + "urlFilter": "https://moodle.hku.hk/pluginfile.php", + "resourceTypes": ["main_frame", "sub_frame", "object", "xmlhttprequest", "stylesheet", "script"] + } +}] \ No newline at end of file diff --git a/scripts/help/jsx/Help.js b/scripts/help/jsx/Help.js index 6a7ff9c..39df9c2 100644 --- a/scripts/help/jsx/Help.js +++ b/scripts/help/jsx/Help.js @@ -27,7 +27,7 @@ window.popup.HelpPopup = async function (custom, inner) { innerText: "Powered by EZ-HKU with ❤️", }), window.elements.Div({ - innerText: "v1.3.1", + innerText: "v1.3.1.3", }), window.elements.A({ href: "https://github.com/EZ-HKU/SuperEZ/wiki", diff --git a/scripts/moodle/js/content.js b/scripts/moodle/js/content.js index dd8e0e2..b4562a3 100644 --- a/scripts/moodle/js/content.js +++ b/scripts/moodle/js/content.js @@ -126,11 +126,10 @@ function generate() { my_card_btn.addEventListener("click", () => { var parent_node = i.parentNode.parentNode.parentNode.parentNode; - var url = parent_node.querySelector("a").href; - var title = i.parentNode - .querySelector(".sr-only") - .textContent.substring(19); - console.log(i.parentNode.querySelector(".sr-only")); + var a_tag = parent_node.querySelector("a"); + var url = a_tag.href; + var title = a_tag.firstElementChild.firstElementChild.textContent; + console.log({ title }); var code = title.substring(0, 8); var detail = title.substring(9); chrome.storage.sync.get(["course_code_list"], (data) => { @@ -285,6 +284,7 @@ function jumpToExamBase() { const jumpTab = document.createElement("div"); jumpTab.id = "jump-to-exam-base"; + jumpTab.style.display = "none"; jumpTab.style.position = "fixed"; jumpTab.style.left = "50vw"; jumpTab.style.top = "30vh"; diff --git a/scripts/navigator/Navigator.js b/scripts/navigator/Navigator.js index 3834a38..fe05f4f 100644 --- a/scripts/navigator/Navigator.js +++ b/scripts/navigator/Navigator.js @@ -58,6 +58,20 @@ function Navigator(btns, centerCustom, custom, inner) { }); }) ), + window.elements.Div({ + innerHTML: ` + + + + + + + + + + + ` + }) ] ); } @@ -135,6 +149,22 @@ function init() { var navigator = Navigator(btns, { innerText: "🚀" }); document.documentElement.appendChild(navigator); + + chrome.storage.sync.get("LiquidGlass", function (i) { + if (i.LiquidGlass) { + document.getElementById("feImg").setAttribute("href", chrome.runtime.getURL("images/noise.png")); + document.getElementById("ez-navigator-center").classList.add("liquid-glass"); + document.querySelectorAll(".ez-inner").forEach(function (el) { + el.classList.add("liquid-glass"); + }); + } else { + document.getElementById("ez-navigator-center").classList.remove("liquid-glass"); + document.querySelectorAll(".ez-inner").forEach(function (el) { + el.classList.remove("liquid-glass"); + }); + } + }); + } init(); diff --git a/scripts/setting/jsx/Setting.js b/scripts/setting/jsx/Setting.js index eaac405..fdea023 100644 --- a/scripts/setting/jsx/Setting.js +++ b/scripts/setting/jsx/Setting.js @@ -236,6 +236,45 @@ async function ExamBaseButton(custom, inner) { ]) } +async function LiquidGlass(custom, inner) { + return window.elements.Div({ + style: { + textAlign: "left", + marginLeft: "15px", + }, + }, [ + window.elements.Input( + { + type: "checkbox", + id: "ez-liquid-glass-checkbox", + style: { + width: "20px", + height: "20px", + verticalAlign: "middle", + }, + checked: (await window.utils.getStorage('LiquidGlass')).LiquidGlass || false, + onClick: async function (e) { + let isChecked = e.target.checked; + await chrome.storage.sync.set({ + LiquidGlass: isChecked, + }); + + }, + }, [] + ), + window.elements.Label({ + htmlFor: "ez-liquid-glass-checkbox", + innerText: "Liquid Glass", + style: { + fontSize: "15px", + color: "#555555", + verticalAlign: "middle", + marginLeft: "10px", + marginBottom: "0", + }, + }), + ]) +} function SettingBlock(name, element) { return window.elements.Div({ @@ -276,6 +315,7 @@ window.popup.SettingPopup = async function SettingPopup(custom, inner) { SettingBlock("Set User", window.popup.SetUserForm()), SettingBlock("Quick Logout", LogoutButton()), SettingBlock("Exam Base", await ExamBaseButton()), + SettingBlock("UI", await LiquidGlass()), ] ) ) diff --git a/scripts/superload/background.js b/scripts/superload/background.js index 8bd6216..ebf5e60 100644 --- a/scripts/superload/background.js +++ b/scripts/superload/background.js @@ -1,9 +1,14 @@ // background.js chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.action === 'downloadFile') { + // https://moodle.hku.hk/mod/folder/download_folder.php?id=3764675 + // https://moodle.hku.hk/mod/folder/view.php?id=3764676 + if (message.url.includes('/mod/folder/')) { + message.url = message.url.replace('/view.php?id=', '/download_folder.php?id='); + } chrome.downloads.download({ url: message.url, - filename: `SuperLoad/${message.address}/${message.filename}.pdf`, + filename: `SuperLoad/${message.address}/${message.filename}.zip`, saveAs: message.saveAs, conflictAction: message.conflictAction }, (downloadId) => { @@ -15,10 +20,12 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { }); } else if (message.action === 'downloadFiles') { message.downloadFiles.forEach(file => { - + if (file.url.includes('/mod/folder/')) { + file.url = file.url.replace('/view.php?id=', '/download_folder.php?id='); + } chrome.downloads.download({ url: file.url, - filename: `SuperLoad/${file.address}/${file.filename}.pdf`, + filename: `SuperLoad/${file.address}/${file.filename}.zip`, saveAs: message.saveAs, conflictAction: message.conflictAction }, (downloadId) => { diff --git a/scripts/superload/jsx/popup.js b/scripts/superload/jsx/popup.js index ee4f8a6..e5493f1 100644 --- a/scripts/superload/jsx/popup.js +++ b/scripts/superload/jsx/popup.js @@ -2,10 +2,11 @@ function findPDFLinks() { let fileLinks = []; let links = document.getElementsByTagName('a'); // filter links - links = Array.from(links).filter(link => link.href && link.href.includes('https://moodle.hku.hk/mod/resource/') && link.classList.contains('aalink')); + links = Array.from(links).filter(link => link.href && link.href.includes('https://moodle.hku.hk/mod/') && link.classList.contains('aalink')); for (let link of links) { if (link.href && - link.href.includes('https://moodle.hku.hk/mod/resource/')) { + (link.href.includes('https://moodle.hku.hk/mod/resource/')|| + link.href.includes('https://moodle.hku.hk/mod/folder/'))){ let fileType = 'unknown'; let iconSrc = ''; @@ -20,6 +21,8 @@ function findPDFLinks() { const match = iconSrc.match(/\/f\/([^?]+)/); if (match && match[1]) { fileType = match[1].toLowerCase(); + } else { + fileType = 'folder'; } } } @@ -38,7 +41,7 @@ function findPDFLinks() { window.popup.SuperLoadPopup = async function () { let fileLinks = findPDFLinks(); - let posibleFileTypes = ['pdf', 'file', 'powerpoint', 'spreadsheet', 'archive', 'document', 'video', 'image']; + let posibleFileTypes = ['pdf', 'file', 'powerpoint', 'spreadsheet', 'archive', 'document', 'video', 'image', 'folder']; let downloadedFileIDs = (await window.utils.getStorageLocal('downloadedFileIDs')).downloadedFileIDs || []; return ( window.elements.Div({ diff --git a/styles/navigator.css b/styles/navigator.css index 9e4e244..daa9332 100644 --- a/styles/navigator.css +++ b/styles/navigator.css @@ -98,3 +98,8 @@ background-color: #e4eafa; color: #000000; } + +.liquid-glass { + backdrop-filter: url(#frosted) !important; + background: rgba(255, 255, 255, .08) !important; +} \ No newline at end of file