Remove specific elements with MutationObserver.
当前为
// ==UserScript==
// @name ComicK - Cleanup ComicK
// @namespace https://github.com/BreezeSpark
// @match https://comick.io/*
// @icon https://comick.io/favicon.ico
// @version 3.2.2025.2
// @description Remove specific elements with MutationObserver.
// @author BreezeSpark
// @run-at document-start
// @grant none
// @supportURL https://github.com/BreezeSpark/Userscripts/issues
// @homepageURL https://github.com/BreezeSpark/Userscripts
// @license GPL-3.0-or-later
// ==/UserScript==
(function () {
//------------------------------- Settings ----------------------------------\\
const SETTINGS = {
removeCommentSection: true, // Set to false to keep the comment section
removeHomepageSidePanel: true // Set to false to keep the homepage side panel
};
//---------------------------------------------------------------------------\\
const removeElement = (selector) => {
const element = document.querySelector(selector);
if (element) element.remove();
};
const removeElementByText = (selector, text) => {
const element = document.querySelector(selector);
if (element && element.textContent.includes(text)) element.remove();
};
const ELEMENTS_TO_REMOVE = [
{ selector: 'div.rounded.dark\\:border-gray-700.text-xs' },
{ selector: 'div.text-center.text-xs.py-2', condition: (el) => el.textContent.includes('ADVERTISEMENT') },
{ selector: 'div.pl-3.pb-1.lg\\:pl-4.lg\\:pb-3.pr-0.float-right.w-4\\/12.xl\\:w-3\\/12.space-y-5.overflow-hidden', condition: () => SETTINGS.removeHomepageSidePanel },
{ selector: '#comment-section', condition: () => SETTINGS.removeCommentSection }
];
const removeTargetElements = () => {
ELEMENTS_TO_REMOVE.forEach(({ selector, condition }) => {
const element = document.querySelector(selector);
if (element && (!condition || condition(element))) {
element.remove();
}
});
};
const centerMainElement = () => {
if (!SETTINGS.removeHomepageSidePanel) return;
const mainElement = document.querySelector('main#main');
if (mainElement) {
Object.assign(mainElement.style, {
marginLeft: 'auto',
marginRight: 'auto',
float: 'none',
display: 'block'
});
}
};
removeTargetElements();
centerMainElement();
const observer = new MutationObserver(() => {
removeTargetElements();
centerMainElement();
});
observer.observe(document.documentElement, {
childList: true,
subtree: true
});
})();