Suppose you've ever been deep into an educational video only to have your focus shattered by an unexpected popup or an abrupt video pause when you switch tabs. In that case, you know how frustrating the online learning experience can be. But worry not, dear reader, for today, we bring you a solution that promises to enhance your learning journey on platforms like MedMasterTH.
Understanding the Culprits
Before we dive into the solution, let's understand the issue at hand. Many educational websites use engagement tactics like popups or auto-pausing videos when you're not actively on their tab. While these features aim to keep you focused, they can sometimes detract from the learning experience, especially if you're multitasking or referencing other materials.
Enter Tampermonkey
Tampermonkey is a powerful browser extension that allows you to run your own JavaScript on any website, giving you control over your browsing experience. With a few lines of code, we can eliminate those pesky popups and ensure our videos continue playing in the background, uninterrupted.
The Magic Scripts
We've crafted three Tampermonkey scripts to address these issues:
1. Removing Annoying Popups on the Video Tab Out
This script hides popups that appear when you switch tabs during video playback. It waits for the page to load and then executes a function to remove any popups identified by its CSS class.
// ==UserScript==
// @name Remove Annoying Popup on Video Tab Out
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.medmasterth.co/classroom/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Function to remove the popup
function removePopup() {
const popups = document.querySelectorAll('.jconfirm.jconfirm-modern.jconfirm-open');
popups.forEach(popup => {
popup.style.display = 'none'; // Hide the popup
});
// Optional: Stop the video player if needed
// document.querySelector('your-video-selector').pause();
}
// Run the removePopup function when the document is fully loaded
document.addEventListener('DOMContentLoaded', () => {
// You might need to adjust this timeout depending on how the site loads the popup
setTimeout(removePopup, 1000); // Wait for 1 second after page load to remove the popup
});
// Optional: Re-run the removePopup function if the popup reappears upon certain actions
// This might be necessary if the site uses AJAX to dynamically display popups
document.addEventListener('click', removePopup);
})();
2. Detect and Prevent Popup Before It Shows
To preemptively stop popups, this script monitors changes to the webpage and removes any newly added popups before they can interrupt your viewing.
// ==UserScript==
// @name Detect and Prevent Popup
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Detect and remove popup before it shows
// @author You
// @match https://www.medmasterth.co/classroom/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.nodeType === 1 && node.matches('.jconfirm')) { // Check if the added node is the popup
node.remove(); // Remove the popup
}
});
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
})();
3. Advanced Video Play Control
Lastly, to keep your video playing even when you click away (but allow manual pausing), this script cleverly overrides the video's pause function, only permitting pauses initiated by you, the user.
// ==UserScript==
// @name Advanced Video Play Control
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Keep video playing on focus loss but allow manual pause on MedMasterTH Classroom.
// @author You
// @match https://www.medmasterth.co/classroom/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
let userInitiatedPause = false;
window.addEventListener('load', function() {
const videoPlayer = document.querySelector('video');
if (videoPlayer) {
// Override the pause function to check for user-initiated pauses
const originalPause = videoPlayer.pause.bind(videoPlayer);
videoPlayer.pause = function() {
if (!userInitiatedPause) {
console.log("Auto-pause prevented.");
return; // Prevent auto-pause
}
console.log("Pause allowed.");
originalPause(); // Allow pause if user-initiated
};
// Listen for user interactions that should enable pausing
videoPlayer.addEventListener('click', function() {
userInitiatedPause = true;
videoPlayer.pause(); // Trigger pause, which is now allowed
setTimeout(() => { userInitiatedPause = false; }, 500); // Reset after a short delay to prevent auto-pause
});
// Optionally, listen for other events that indicate user-initiated pause
videoPlayer.addEventListener('play', function() {
userInitiatedPause = false; // Assume any play action means auto-pause should be prevented next
});
}
});
})();
Implementing the Solution
To use these scripts:
Install the Tampermonkey extension for your browser.
Create a new script for each code snippet above.
Tailor the @match directive to the specific website you wish to apply the script to, if necessary.
Save and enable the scripts in Tampermonkey.
Conclusion
With these scripts, you're now equipped to tackle the common distractions of popups and video auto-pauses, making your online learning experience smoother and more enjoyable. Remember, while these scripts offer a workaround, always consider website policies and copyright laws when using custom scripts.
We hope this guide empowers you to take control of your learning environment. Happy learning!
Comments
No comments yet. Be the first to share your thoughts.
Comments
No comments yet. Be the first to share your thoughts.
Sign in to comment