Greasy Fork is available in English.
Fixes bad site design issues *and a built in ad blocker
当前为
// ==UserScript==
// @name Fix Aternos Site
// @namespace http://tampermonkey.net/
// @version 0.4
// @description Fixes bad site design issues *and a built in ad blocker
// @author You
// @match https://aternos.org/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=aternos.org
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// Variable to track whether content is already being replaced
let isContentReplaced = false;
let sidebaron = false; // Set this to true if you want to enable the sidebar, false otherwise.
let canClickDivs = true;
// Function to remove elements by class name
function removeElementsByClass(classNames) {
classNames.forEach(className => {
const elements = document.querySelectorAll(`.${className}`);
elements.forEach(element => element.remove());
});
}
// Function to replace the content of an element by class name
function replaceContentByClass(className, newContent) {
const elements = document.querySelectorAll(`.${className}`);
elements.forEach(element => {
// Avoid redundant replacement if the content is already replaced
if (!isContentReplaced) {
element.innerHTML = newContent;
isContentReplaced = true; // Set flag to prevent infinite changes
}
});
}
// Function to click divs that meet a specific condition
function clickDivsBasedOnCondition() {
if (!canClickDivs) return; // Exit the function if clicking is not allowed
const divs = document.querySelectorAll('div');
divs.forEach(div => {
// Condition: For example, click divs that contain specific text or have a certain attribute
//if (div.textContent.includes('Continue with adblocker anyway') || div.hasAttribute('data-action')) {
// div.click();
//}
if (div.textContent.includes('Continue with adblocker anyway')) {
div.click();
}
});
}
// Function to stop clicking divs
function stopClickingDivs() {
canClickDivs = false;
}
// Function to remove an element with exact styles
function removeElementWithExactStyles() {
const allElements = document.querySelectorAll('*');
allElements.forEach((element) => {
const style = window.getComputedStyle(element);
if (
style.display === 'inline' &&
style.position === 'fixed' &&
style.left === '0px' &&
style.bottom === '0px' &&
style.width === '100%' &&
style.minWidth === '100%' &&
style.backdropFilter === 'none' &&
style.backgroundColor === 'rgba(255, 255, 255, 0.83)' &&
style.zIndex === '2147483646' &&
style.textAlign === 'center' &&
style.fontSize === '0px' &&
style.lineHeight === '0' &&
style.pointerEvents === 'none' &&
style.overflow === 'clip' &&
style.overflowClipMargin === 'content-box' &&
style.minHeight === '20px'
) {
element.parentNode.removeChild(element);
}
});
}
// Function to set the height of the header-right element
function adjustHeaderHeight() {
const header = document.querySelector('.header-right');
if (header) {
header.style.height = '100px';
header.style.position = 'fixed'; // Ensure it's fixed
header.style.right = '16px'; // Preserve the right alignment
}
}
// Specify the classes to remove based on sidebaron flag
let classesToRemove = [
'responsive-leaderboard',
'ad-dfp',
'server-b-tutorials',
'header-center'
];
// Remove sidebar-related class if sidebaron is false
if (!sidebaron) {
classesToRemove.push('sidebar'); // Remove the sidebar if sidebaron is false
} else {
// If sidebaron is true, you can modify the sidebar's content or do nothing
let classToModify = 'sidebar';
let newSidebarContent = `
<ul style="list-style-type: none; padding: 0; background-color: black;">
<li style="padding: 8px 16px; text-align: center;"><a href="https://aternos.org/server/" style="color: white; text-decoration: none;">Server</a></li>
<li style="padding: 8px 16px; text-align: center;"><a href="https://aternos.org/options/" style="color: white; text-decoration: none;">Options</a></li>
<li style="padding: 8px 16px; text-align: center;"><a href="https://aternos.org/console/" style="color: white; text-decoration: none;">Console</a></li>
<li style="padding: 8px 16px; text-align: center;"><a href="https://aternos.org/log/" style="color: white; text-decoration: none;">Logs</a></li>
<li style="padding: 8px 16px; text-align: center;"><a href="https://aternos.org/players/" style="color: white; text-decoration: none;">Players</a></li>
<li style="padding: 8px 16px; text-align: center;"><a href="https://aternos.org/files/" style="color: white; text-decoration: none;">Files</a></li>
<li style="padding: 8px 16px; text-align: center;"><a href="https://aternos.org/worlds/" style="color: white; text-decoration: none;">Worlds</a></li>
<li style="padding: 8px 16px; text-align: center;"><a href="https://aternos.org/backups/" style="color: white; text-decoration: none;">Backups</a></li>
<li style="padding: 8px 16px; text-align: center;"><a href="https://aternos.org/access/" style="color: white; text-decoration: none;">Access</a></li>
</ul>`;
replaceContentByClass(classToModify, newSidebarContent); // Replace sidebar content when sidebaron is true
}
// Observe changes in the DOM for the removal of classes and content replacement
const observer = new MutationObserver(mutations => {
mutations.forEach(() => {
adjustHeaderHeight(); // Ensure the header-right height is adjusted dynamically
removeElementsByClass(classesToRemove);
removeElementWithExactStyles(); // Check and remove elements with exact styles
clickDivsBasedOnCondition(); // Check for divs meeting the condition
});
});
// Start observing the body for added nodes (subtree includes all descendants)
observer.observe(document.body, { childList: true, subtree: true });
// Initial cleanup, replacement, and button click in case the elements already exist
adjustHeaderHeight(); // Set header-right height initially
removeElementsByClass(classesToRemove);
removeElementWithExactStyles(); // Check and remove elements with exact styles initially
clickDivsBasedOnCondition(); // Check and click matching divs initially
// Optionally, call stopClickingDivs at a certain time or condition to disable clicking
setTimeout(stopClickingDivs, 20000); // Example: Disable clicking after 20 seconds
})();