Created
January 2, 2026 21:59
-
-
Save motionharvest/7b8a9123cc0e4e875aa981ba064dec2c to your computer and use it in GitHub Desktop.
If a user is on a course/view page and is viewing it for the first time, arrange the UI to the ideal state
This file contains hidden or 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
| if (window.location.href.includes('course/view.php')) { | |
| const courseKey = `${window.location.pathname}${window.location.search}`; | |
| const lsKey = `courseViewAutoClicks::${courseKey}`; | |
| if (!localStorage.getItem(lsKey)) { | |
| const clickIfExists = (selector) => { | |
| const el = document.querySelector(selector); | |
| if (el) el.click(); | |
| return !!el; | |
| }; | |
| // collapse all course index links | |
| clickIfExists('[data-action="collapseallcourseindexsections"]'); | |
| // collapse all sections | |
| const hasCollapseSections = clickIfExists('#collapsesections'); | |
| // only open the course index sidebar if it isn't already open | |
| const courseIndexDrawer = document.querySelector('#theme_boost-drawers-courseindex'); | |
| if (!courseIndexDrawer || !courseIndexDrawer.classList.contains('show')) { | |
| clickIfExists('.drawer-toggler button'); | |
| } | |
| // open first section after 500ms ONLY if #collapsesections existed | |
| if (hasCollapseSections) { | |
| setTimeout(() => { | |
| clickIfExists('#section-0>div a'); | |
| }, 500); | |
| } | |
| // mark as done for this specific course URL | |
| localStorage.setItem(lsKey, '1'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment