Skip to content

Instantly share code, notes, and snippets.

@jithurjacob
Last active December 1, 2024 10:18
Show Gist options
  • Save jithurjacob/4d572b6e6be193650cdf8bb28536326a to your computer and use it in GitHub Desktop.
Save jithurjacob/4d572b6e6be193650cdf8bb28536326a to your computer and use it in GitHub Desktop.
PluralSight Auto Play Next Module
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type (or see below for non wait option)
//localStorage.setItem("playbackRate", 2.1);
console.log('[start]Pluralsight Continuous Play');
window.setInterval(function(){
$('#next-module').click();
},30000);
@John-Blair
Copy link

This one works for the current player!

https://github.com/John-Blair/pluralsight/blob/master/auto-click-continue-to-next-module-button.js

Just paste the code into the console on the pluralsight video page and it will auto click the button when it appears.

@cemtopkaya
Copy link

cemtopkaya commented Apr 7, 2020

For the nex module:

window.setInterval(function(){

	var xpath = "//span[text()='Continue to next module']";
	var span = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
	var modal = span.parentElement.parentElement.parentElement;
	var isActive = false;
	modal.classList.forEach(c=> isActive = isActive || (c=="is-active"))

	if(isActive){
	  span.click()
	}

},30000)

@John-Blair
Copy link

Updated my repo for new pluralsight player - they annoyingly changed the named of the data attribute used to target the button.

@Fibfractal
Copy link

John-Blair.

I have copied and pasted the js code in the console in both crome and firefox in the Pluralsight tab, and reloaded the page.
I doesn't work, same button "Continue to next module comes up".

The button is still called the same as your last commit, what I can tell.

Is it working for you, and what did I do wrong?

Thanks

@John-Blair
Copy link

@Fibfractal,

The "Continue to next module" button data attribute changed to "data-css-el86ax" I reflected that in my code snippet.
If you just paste it in to the console window and hit return - then after 5 seconds the button should automatically be clicked --- i just tested it works on my Chrome browser. In the first image i have created that code as a snippet under the Sources tab to make it easier to run each time i go to pluralsight.

image

image

Listing the full code I use:

(function () {

if ( !window.jQuery ) {
var dollarInUse = !!window.$;
var s = document.createElement('script');
s.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js');
s.addEventListener('load', function(){
console.log('jQuery loaded!');

  if(dollarInUse) {
    jQuery.noConflict();
    console.log('`$` already in use; use `jQuery`');
  }
});

document.body.appendChild(s);

}

})();
setInterval(function () {jQuery("button[data-css-el86ax]:visible").click();}, 5000);

@Esirei
Copy link

Esirei commented Jun 28, 2020

This wasn't working for me due to some issues with injecting jQuery into the page.
So I created another without the jQuery dependency.

https://gist.github.com/Esirei/1489b95b59b093e223d0cf3c9b2336ef

@John-Blair
Copy link

John-Blair commented Jun 28, 2020

Always good to remove a dependency. Just need to watch out for when they change the text on the Continue button! Yours is a variant of @cemtopkaya

@Ji993
Copy link

Ji993 commented Apr 1, 2021

None of these code samples work in 2021. Any solutions ?

@Esirei
Copy link

Esirei commented Apr 2, 2021

None of these code samples work in 2021. Any solutions ?

Hey @Ji993, I've updated my gist.
The class name on the button had been removed.

@satyendrakumarsingh
Copy link

Check below working script without any external dependency.

https://gist.github.com/satyendrakumarsingh/c2f0b08281c78e95d8db6f74c93ed3eb

@spahbedsuren
Copy link

Yeah. First of all, screw pluralsight for a HORRENDOUS user experience with lacking an OPTION for enabling autoplay, I am switching to tik tok in protest.

Second of all, this method does not work. It runs into an error in my browser stating paused on promise rejection: SyntaxError: Unexpected end of JSON input

I also see a F ton of "Your Appcues account has expired, but you have not uninstalled Appcues. Please contact us at [email protected]." errors and warnings all over the console.

I never do use the console on this browser for anything. I have attempted this with all extensions removed as well and it is still no go.

In conclusion, back to my first line and I will not be renewing the lowered quality platform any time soon. PDF books and e-books are less frustrating than this when give to an atuoreader. What is pluralsight thinking....

@mayanknc
Copy link

mayanknc commented May 1, 2023

@JarkkoLaiho
Copy link

@mayanknc Now that Plularshight UI has been restylished, you script now longer works as the text seems to be changed in button (now format is like 'Start module X'). Could your update your script?

@BoxInABox
Copy link

BoxInABox commented Mar 19, 2024

Here is my own spin on the code. @mayanknc @JarkkoLaiho @John-Blair
This should work since it checks for the key words.


const keyWord = "Start module";

let autoNext = () => {
  Array.from(document.querySelectorAll('button'))
    .filter(b => b.textContent.includes(keyWord))
    .forEach(b => b.click());
};

setInterval(autoNext, 2500);

@patocl
Copy link

patocl commented Nov 30, 2024

Updated PluralSight Auto Play Behavior

const autoClickButton = (xpath) => {
  // Checks if an element is visible on the page.
  const isVisible = (element) => {
    const style = window.getComputedStyle(element);
    return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
  };

  // Set up a MutationObserver to monitor DOM changes.
  const observer = new MutationObserver(() => {
    const button = document.evaluate(
      xpath,
      document,
      null,
      XPathResult.FIRST_ORDERED_NODE_TYPE,
      null
    ).singleNodeValue;

    // If the button exists and is visible, click it.
    if (button && isVisible(button)) {
      button.click();
      console.log(`Button clicked for XPath: ${xpath}`);
    }
  });

  // Start observing the DOM for changes.
  observer.observe(document.body, {
    childList: true, // Monitors addition or removal of child nodes.
    subtree: true,   // Monitors changes in all descendant nodes.
  });
};

// Clicks 'Next Lesson' button dynamically.
autoClickButton("//button[@aria-label='Next Lesson']");

// Clicks 'Start module' button dynamically.
autoClickButton("//button[contains(text(), 'Start module')]"); 

This script is designed to dynamically and repeatedly click buttons on a webpage with frequently updating content, such as in Single Page Applications (SPA). It leverages a MutationObserver to track changes in the DOM and react only when necessary. Here's what it does:

  1. Listens for DOM changes:
    It uses a MutationObserver to detect when the specified button is added to or reappears in the DOM.

  2. Validates button visibility:
    Before clicking, it ensures the button is visible on the page (i.e., not hidden, transparent, or removed).

  3. Continuously handles dynamic content:
    The script works persistently, clicking the button each time it appears or reappears.

  4. Reusability:
    The autoClickButton function accepts an XPath selector, making it adaptable to various buttons.

  5. Why is it more efficient than setInterval?
    Unlike setInterval, which repeatedly executes code at fixed intervals regardless of whether a button appears, MutationObserver reacts only when the DOM changes. This minimizes CPU usage, avoids unnecessary checks, and ensures the script works in sync with the dynamic updates of the page.


Enjoy it 😊

@patocl
Copy link

patocl commented Dec 1, 2024

Maximize your learning experience with ease!

I’m thrilled to introduce Pluralsight™ Autoplay, designed to enhance your productivity on Pluralsight.

What does it do?

This extension adds an Auto Play feature for Pluralsight courses, providing a seamless, uninterrupted learning experience.

Key Benefits:

1.- Automatically advances to the next video in a course.
2.- Keeps your learning flow smooth and distraction-free.
3.- Helps you stay focused and engaged during long study sessions.
4.- Ideal for learners who want a hands-free, continuous experience.

Try it now and take your productivity to the next level: Pluralsight™ Autoplay

Your feedback means the world to me! Let me know how it works for you. 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment