Skip to content

Commit

Permalink
fix: courseName logic
Browse files Browse the repository at this point in the history
  • Loading branch information
harsilspatel committed Apr 29, 2021
1 parent 651df59 commit 92409be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"name": "Moodle Downloader",
"description": "A chrome extension for downloading Moodle resources",
"version": "1.5.2",
"version": "1.5.3",
"icons": {
"16": "assets/icon16.png",
"24": "assets/icon24.png",
Expand Down
19 changes: 11 additions & 8 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,17 @@ function getFilesUnderResources(sesskey, tableBody) {
}

function getFiles() {
const courseName =
document.getElementsByClassName("header-title")[0].innerText ||
document.getElementsByClassName("breadcrumb-item")[2].firstElementChild
.title ||
document
.querySelector("header#page-header .header-title")
.textContent.trim() ||
"";
const h1s = document.getElementsByTagName("h1");
const headerTitles = document.getElementsByClassName("header-title");
const breadcrumbItems = document.getElementsByClassName("breadcrumb-item");
const pageHeader = document.querySelector("header#page-header .header-title")
const courseName = (
h1s.length && h1s[0].innerText ||
headerTitles.length && headerTitles[0].innerText ||
pageHeader.textContent ||
breadcrumbItems.length > 2 && breadcrumbItems[2].firstElementChild.title ||
""
).trim();

// The session key should normally be accessible through window.M.cfg.sesskey,
// but getting the window object is hard.
Expand Down

0 comments on commit 92409be

Please sign in to comment.