Last active
July 19, 2023 15:33
-
-
Save ahmedazhar05/861d742560bcf6d4cf5a49e4fa4695ac to your computer and use it in GitHub Desktop.
Udemy Fast-forward bookmarklet
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
| javascript:(function forwarder(toggle = false) { | |
| /* toggling the execution of this whole script */ | |
| if(toggle && 'ff_set' in window) { | |
| window.ff_set = !window.ff_set; | |
| if(window.ff_set) console.log("%c Forwarder script started running...", "color: green"); | |
| } else if(!('ff_set' in window)) { | |
| window.ff_set = true; | |
| console.log("%c Forwarder script started running...", "color: green"); | |
| } | |
| if(!window.ff_set) { | |
| if(toggle) console.log("%c Forwarder script stopped running!", "color: red"); | |
| return; | |
| } | |
| /* time to wait for the video to load before moving to the end of the video */ | |
| const VIDEO_LOAD_TIME = 9000; | |
| /* watching time of the video before moving to the next item in the course */ | |
| const VIDEO_WATCH_TIME = 3000; | |
| /* reading time of the article before moving to the next item in the course */ | |
| const ARTICLE_READ_TIME = 12000; | |
| function goToNextItem() { | |
| if (!window.ff_set) return; | |
| document.getElementById('go-to-next-item')?.click(); | |
| forwarder(); | |
| } | |
| function getCurrentItem(){ | |
| let li = document.querySelector('li[class*="curriculum-item-link--is-current"]'); | |
| if(li) return li; | |
| /* else */ | |
| document.querySelector('div[data-purpose="curriculum-section-container"]')?.querySelectorAll('.ud-accordion-panel-toggler').forEach(x=>x.click()); | |
| li = document.querySelector('li[class*="curriculum-item-link--is-current"]'); | |
| return li; | |
| } | |
| const currentItem = getCurrentItem(); | |
| const current_element_is_completed = currentItem.firstElementChild.firstElementChild.firstElementChild.firstElementChild.firstElementChild.checked; | |
| if(current_element_is_completed) { | |
| goToNextItem(); | |
| return; | |
| } | |
| const icon_type = currentItem.firstElementChild.lastElementChild.lastElementChild.firstElementChild.firstElementChild.firstElementChild.firstElementChild.getAttribute('xlink:href'); | |
| if(icon_type.endsWith('video')){ | |
| setTimeout(() => { | |
| if (!window.ff_set) return; | |
| let video = document.querySelector('video'); | |
| const video_time = "0:" + document.querySelector('span[data-purpose="duration"]').textContent; | |
| const last_second_of_the_video = video_time.split(":").slice(-3).map(Number).reverse().reduce((t, x, i) => t + x * Math.pow(60, i), 0); | |
| video.currentTime = last_second_of_the_video - (VIDEO_WATCH_TIME + 2000) / 1000; | |
| console.log('video forwarded! played at', last_second_of_the_video + "s"); | |
| }, VIDEO_LOAD_TIME); | |
| setTimeout(goToNextItem, VIDEO_LOAD_TIME + VIDEO_WATCH_TIME); | |
| } else { | |
| setTimeout(goToNextItem, ARTICLE_READ_TIME); | |
| } | |
| })(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment