Close Ads

Closes ads on LookMovie and removes specific reCAPTCHA, banner ads from the page

< Feedback on Close Ads

Review: Good - script works

§
Posted: 2024-10-11

// ==UserScript==
// @name Close Ads
// @namespace https://www.lookmovie2.to/
// @version 0.6
// @description Close ads on LookMovie
// @author JJJ
// @match https://www.lookmovie2.to/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=lookmovie2.to
// @grant none
// @license MIT
// @downloadURL https://update.greasyfork.org/scripts/495537/Close%20Ads.user.js
// @updateURL https://update.greasyfork.org/scripts/495537/Close%20Ads.meta.js
// ==/UserScript==

(function () {
'use strict';

// Configuration
const config = {
closeButtonSelector: '#PlayerZone > section > a.close-icon.player-ads-summer-2024--close',
stayFreeButtonSelector: 'button.no.stay-free[data-notify-html="buttonStayFree"]',
notifyButtonSelector: 'body > div.notifyjs-corner > div > div.notifyjs-container > div > div.buttons > button',
maxAttempts: 100,
continuousCheck: true,
checkInterval: 500 // Time in milliseconds to wait between checks
};

let attempts = 0;
let observer = null;

// Helper function to check if an element is visible
function isElementVisible(el) {
return el && el.offsetParent !== null;
}

// Function to close ads or click relevant buttons
function handleAds() {
try {
// Try to close the ad
const closeButton = document.querySelector(config.closeButtonSelector);
if (isElementVisible(closeButton)) {
closeButton.click();
console.log('Ad closed');
return true; // Ad was closed
} else {
console.log('Close button not found or not visible');
}

// Try to click "I Prefer Ads" button
const stayFreeButton = document.querySelector(config.stayFreeButtonSelector);
if (isElementVisible(stayFreeButton)) {
stayFreeButton.click();
console.log('"I Prefer Ads" button clicked');
return true; // Button was clicked
} else {
console.log('"I Prefer Ads" button not found or not visible');
}

// Try to click the notify button
const notifyButton = document.querySelector(config.notifyButtonSelector);
if (isElementVisible(notifyButton)) {
notifyButton.click();
console.log('Notify button clicked');
return true; // Notify button clicked
} else {
console.log('Notify button not found or not visible');
}
} catch (error) {
console.error('Error while handling ads or buttons:', error);
}
return false; // No button was handled
}

// Function to handle mutations
function handleMutations(mutations) {
mutations.forEach(() => {
if (handleAds()) {
attempts = 0; // Reset attempts on success
} else {
attempts++;
}

if (!config.continuousCheck && attempts >= config.maxAttempts) {
stopObserver();
console.log('Ad handling process finished');
}
});
}

// Function to start the MutationObserver
function startObserver() {
if (observer) return; // Prevent multiple observers

observer = new MutationObserver(handleMutations);
observer.observe(document.body, { childList: true, subtree: true });
console.log('MutationObserver started');
}

// Function to stop the MutationObserver
function stopObserver() {
if (observer) {
observer.disconnect();
observer = null;
console.log('MutationObserver stopped');
}
}

// Function to initialize the process
function initAdCloser() {
console.log('Ad closer initialized');
if (handleAds()) {
attempts = 0; // Reset attempts on success
}

startObserver();

// Fallback to periodically check for buttons
const intervalId = setInterval(() => {
if (handleAds() || attempts >= config.maxAttempts) {
clearInterval(intervalId);
console.log('Ad handling process finished with interval');
}
}, config.checkInterval);

window.addEventListener('beforeunload', stopObserver); // Cleanup on unload
}

// Start the process as soon as possible
if (document.readyState === 'complete' || document.readyState === 'interactive') {
initAdCloser();
} else {
document.addEventListener('DOMContentLoaded', initAdCloser);
}

// Fallback: If DOMContentLoaded doesn't fire, start after a short delay
setTimeout(initAdCloser, 1000);

// Listen for errors and log them
window.addEventListener('error', (e) => {
console.error('Error in Close Ads script:', e.error);
});

// Polyfill for MutationObserver for older browsers
(function () {
if (!window.MutationObserver) {
window.MutationObserver = window.WebKitMutationObserver || window.MozMutationObserver || class {
constructor(callback) {
this.callback = callback;
}
observe() {
console.warn('MutationObserver not supported by this browser.');
}
disconnect() { }
};
}
})();
})();

§
Posted: 2024-10-11

thêm đóng I Prefer Ads

JaredJomarAuthor
§
Posted: 2024-10-12

Thanks for the recommendation to remove the I Prefer Ads. I updated it to implement that using mutation instead of intervals, which reduces resource consumption and improves performance. Additionally, I added the capability to remove the annoying captcha that pops up in front of the video player and eliminated the banner ad. I am still testing it, but if you want to try it, let me know and I can send it to you.

§
Posted: 2024-10-13

Thanks for the recommendation to remove the I Prefer Ads. I updated it to implement that using mutation instead of intervals, which reduces resource consumption and improves performance.
Additionally, I added the capability to remove the annoying captcha that pops up in front of the video player and eliminated the banner ad. I am still testing it, but if you want to try it, let me know and I can send it to you.

tôi sẽ rất vui khi bạn đã cho tôi thử nghiệm trước, cái đoạn code tôi gửi bạn không nên sử dụng toàn bộ vì tôi chỉ mới tập viết thôi, cái tôi đề xuất là cái stayFreeButtonSelector: 'button.no.stay-free[data-notify-html="buttonStayFree"]',
notifyButtonSelector: 'body > div.notifyjs-corner > div > div.notifyjs-container > div > div.buttons > button',
cám ơn bạn. <3

JaredJomarAuthor
§
Posted: 2024-10-13
Edited: 2024-10-13

Feedback is always welcome to continue improving it.

JaredJomarAuthor
§
Posted: 2024-10-19

The new version has been uploaded.

Post reply

Sign in to post a reply.