Skip to content

Instantly share code, notes, and snippets.

@ahmedazhar05
Last active July 19, 2023 15:33
Show Gist options
  • Select an option

  • Save ahmedazhar05/861d742560bcf6d4cf5a49e4fa4695ac to your computer and use it in GitHub Desktop.

Select an option

Save ahmedazhar05/861d742560bcf6d4cf5a49e4fa4695ac to your computer and use it in GitHub Desktop.

Revisions

  1. ahmedazhar05 revised this gist Jul 19, 2023. 1 changed file with 4 additions and 6 deletions.
    10 changes: 4 additions & 6 deletions udemy_ff.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,4 @@
    javascript:(function forwarder(toggle_script_execution = false) {
    console.log("getCurrentItem()");

    const start_alert = () => console.log("%c Forwarder script started running...", "color: green");
    const stop_alert = () => console.log("%c Forwarder script stopped running!", "color: red");

    @@ -33,7 +31,7 @@ javascript:(function forwarder(toggle_script_execution = false) {
    forwarder();
    } else {
    setTimeout(() => {
    document.querySelector('[data-purpose="go-to-next"].item-link.ud-heading-sm')?.click();
    document.querySelector('[data-purpose="go-to-next"].item-link')?.click();
    forwarder();
    }, EXERCISE_LOAD_TIME);
    }
    @@ -65,9 +63,9 @@ javascript:(function forwarder(toggle_script_execution = false) {
    const icon_type = icon_element.getAttribute('xlink:href');

    const current_element_is_completed = currentItem.firstElementChild.firstElementChild.firstElementChild.firstElementChild.firstElementChild.checked;
    const current_element_is_an_exercise = !icon_type && icon_element?.nodeName.toUpperCase() == 'SPAN';
    if(current_element_is_completed || current_element_is_an_exercise) {
    goToNextItem(!current_element_is_an_exercise);
    const current_element_is_not_a_lecture = !icon_type && icon_element?.nodeName.toUpperCase() == 'SPAN';
    if(current_element_is_completed || current_element_is_not_a_lecture) {
    goToNextItem(!current_element_is_not_a_lecture);
    return;
    }
    if(icon_type.endsWith('video')){
  2. ahmedazhar05 revised this gist Jul 19, 2023. 1 changed file with 9 additions and 6 deletions.
    15 changes: 9 additions & 6 deletions udemy_ff.js
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,19 @@
    javascript:(function forwarder(toggle = false) {
    javascript:(function forwarder(toggle_script_execution = false) {
    console.log("getCurrentItem()");

    const start_alert = () => console.log("%c Forwarder script started running...", "color: green");
    const stop_alert = () => console.log("%c Forwarder script stopped running!", "color: red");

    /* toggling the execution of this whole script */
    if(toggle && 'ff_set' in window) {
    if(toggle_script_execution && 'ff_set' in window) {
    window.ff_set = !window.ff_set;
    if(window.ff_set) start_alert();
    } else if(!('ff_set' in window)) {
    window.ff_set = true;
    start_alert();
    }
    if(!window.ff_set) {
    if(toggle) stop_alert();
    if(toggle_script_execution) stop_alert();
    return;
    }

    @@ -22,7 +24,7 @@ javascript:(function forwarder(toggle = false) {
    /* the duration to read the article, for it to be considered 'read', before moving to the next item in the course */
    const ARTICLE_READ_TIME = 12000;
    /* time to wait for the exercise(non-lecture) to load before moving to the next item in the course */
    const EXERCISE_LOAD_TIME = 5000;
    const EXERCISE_LOAD_TIME = 3000;

    function goToNextItem(is_gotoNext_button_available = true) {
    if (!window.ff_set) return;
    @@ -41,7 +43,7 @@ javascript:(function forwarder(toggle = false) {
    const get_li = () => document.querySelector('li[class*="curriculum-item-link--is-current"]');
    const fix1 = () => document.querySelector('div[data-purpose="curriculum-section-container"]')?.querySelectorAll('.ud-accordion-panel-toggler').forEach(x => x.click());
    const fix2 = () => document.querySelector('button[class*="course-content-toggle"].ud-heading-md')?.click();

    let li = get_li();
    if(li) return li;
    /* else */
    @@ -63,7 +65,7 @@ javascript:(function forwarder(toggle = false) {
    const icon_type = icon_element.getAttribute('xlink:href');

    const current_element_is_completed = currentItem.firstElementChild.firstElementChild.firstElementChild.firstElementChild.firstElementChild.checked;
    const current_element_is_an_exercise = !icon_type && icon_element?.nodeName.toUpperCase() == 'SPAN'
    const current_element_is_an_exercise = !icon_type && icon_element?.nodeName.toUpperCase() == 'SPAN';
    if(current_element_is_completed || current_element_is_an_exercise) {
    goToNextItem(!current_element_is_an_exercise);
    return;
    @@ -72,6 +74,7 @@ javascript:(function forwarder(toggle = false) {
    setTimeout(() => {
    if (!window.ff_set) return;
    let video = document.querySelector('video');
    if(video.paused) video.play();
    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;
  3. ahmedazhar05 revised this gist Jul 19, 2023. 1 changed file with 42 additions and 16 deletions.
    58 changes: 42 additions & 16 deletions udemy_ff.js
    Original file line number Diff line number Diff line change
    @@ -1,55 +1,81 @@
    javascript:(function forwarder(toggle = false) {
    const start_alert = () => console.log("%c Forwarder script started running...", "color: green");
    const stop_alert = () => console.log("%c Forwarder script stopped running!", "color: red");

    /* 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");
    if(window.ff_set) start_alert();
    } else if(!('ff_set' in window)) {
    window.ff_set = true;
    console.log("%c Forwarder script started running...", "color: green");
    start_alert();
    }
    if(!window.ff_set) {
    if(toggle) console.log("%c Forwarder script stopped running!", "color: red");
    if(toggle) stop_alert();
    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 */
    /* the duration to watch the video, for it to be considered 'watched', 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 */
    /* the duration to read the article, for it to be considered 'read', before moving to the next item in the course */
    const ARTICLE_READ_TIME = 12000;
    /* time to wait for the exercise(non-lecture) to load before moving to the next item in the course */
    const EXERCISE_LOAD_TIME = 5000;

    function goToNextItem() {
    function goToNextItem(is_gotoNext_button_available = true) {
    if (!window.ff_set) return;
    document.getElementById('go-to-next-item')?.click();
    forwarder();
    if(is_gotoNext_button_available) {
    document.getElementById('go-to-next-item')?.click();
    forwarder();
    } else {
    setTimeout(() => {
    document.querySelector('[data-purpose="go-to-next"].item-link.ud-heading-sm')?.click();
    forwarder();
    }, EXERCISE_LOAD_TIME);
    }
    }

    function getCurrentItem(){
    let li = document.querySelector('li[class*="curriculum-item-link--is-current"]');
    const get_li = () => document.querySelector('li[class*="curriculum-item-link--is-current"]');
    const fix1 = () => document.querySelector('div[data-purpose="curriculum-section-container"]')?.querySelectorAll('.ud-accordion-panel-toggler').forEach(x => x.click());
    const fix2 = () => document.querySelector('button[class*="course-content-toggle"].ud-heading-md')?.click();

    let li = get_li();
    if(li) return li;
    /* else */
    fix1();
    li = get_li();
    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"]');
    fix2();
    li = get_li();
    if(li) return li;
    /* else */
    fix1();
    li = get_li();
    return li;
    }
    const currentItem = getCurrentItem();

    const icon_element = currentItem.firstElementChild.lastElementChild.lastElementChild.firstElementChild.firstElementChild.firstElementChild.firstElementChild;
    const icon_type = icon_element.getAttribute('xlink:href');

    const current_element_is_completed = currentItem.firstElementChild.firstElementChild.firstElementChild.firstElementChild.firstElementChild.checked;
    if(current_element_is_completed) {
    goToNextItem();
    const current_element_is_an_exercise = !icon_type && icon_element?.nodeName.toUpperCase() == 'SPAN'
    if(current_element_is_completed || current_element_is_an_exercise) {
    goToNextItem(!current_element_is_an_exercise);
    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");
    console.log('video-item forwarded at:', last_second_of_the_video + "s");
    }, VIDEO_LOAD_TIME);
    setTimeout(goToNextItem, VIDEO_LOAD_TIME + VIDEO_WATCH_TIME);
    } else {
  4. ahmedazhar05 revised this gist Jul 19, 2023. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions udemy_ff.js
    Original file line number Diff line number Diff line change
    @@ -20,6 +20,7 @@ javascript:(function forwarder(toggle = false) {
    const ARTICLE_READ_TIME = 12000;

    function goToNextItem() {
    if (!window.ff_set) return;
    document.getElementById('go-to-next-item')?.click();
    forwarder();
    }
    @@ -43,6 +44,7 @@ javascript:(function forwarder(toggle = false) {
    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);
  5. ahmedazhar05 revised this gist Jul 19, 2023. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions udemy_ff.js
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,16 @@
    javascript:(function forwarder(toggle = false) {
    // toggling the execution of this whole script
    /* 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 stopped running!", "color: red");
    return;
    }
    console.log("%c Forwarder script started running...", "color: green");
    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;
  6. ahmedazhar05 revised this gist Jul 19, 2023. 1 changed file with 49 additions and 49 deletions.
    98 changes: 49 additions & 49 deletions udemy_ff.js
    Original file line number Diff line number Diff line change
    @@ -1,56 +1,56 @@
    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 stopped running!", "color: red");
    return;
    }
    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");
    }
    // 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 stopped running!", "color: red");
    return;
    }
    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");
    }

    /* 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;
    /* 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() {
    document.getElementById('go-to-next-item')?.click();
    forwarder();
    }
    function goToNextItem() {
    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();
    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 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(() => {
    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);
    }
    const icon_type = currentItem.firstElementChild.lastElementChild.lastElementChild.firstElementChild.firstElementChild.firstElementChild.firstElementChild.getAttribute('xlink:href');
    if(icon_type.endsWith('video')){
    setTimeout(() => {
    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);
  7. ahmedazhar05 revised this gist Jul 19, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion udemy_ff.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    (function forwarder(toggle = false) {
    javascript:(function forwarder(toggle = false) {
    // toggling the execution of this whole script
    if(toggle && 'ff_set' in window) {
    window.ff_set = !window.ff_set;
  8. ahmedazhar05 created this gist Jul 19, 2023.
    56 changes: 56 additions & 0 deletions udemy_ff.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    (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 stopped running!", "color: red");
    return;
    }
    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");
    }

    /* 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() {
    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(() => {
    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);