Tampermonkey-Script: Disable Modal Search

von Marrei • Feedback & Ideen
Da ich modale Fenster nicht mag, hier ein Tampermonkey-Script, welches die modale Suche disabled und das Suchfeld permanent anzeigt:

// ==UserScript==
// @Name AniWorld - Permanente Schnellsuche
// @namespace Marrei.AniWorld
// @version 1.2.0
// @description Permanente Schnellsuche mit originalem CSS
// @author Marrei
// @match https://aniworld.to/*
// @grant none
// @run-at document-idle
// ==/UserScript==

(function () {
'use strict';

function moveSearch() {

const target = document.querySelector(
'div.home-hero.mb-3.mt-1'
);

const searchInput = document.querySelector('#search-input');
const modal = searchInput?.closest('.modal');

// Benötigte Elemente prüfen
if (!target || !modal) return;

// Mehrfaches Verschieben verhindern
if (modal.classList.contains('mr-inline-search')) return;

// Modal vor Home-Hero verschieben
target.before(modal);

// Eigene CSS-Klasse hinzufügen
modal.classList.add('mr-inline-search');

// Modal-Eigenschaften entfernen
modal.classList.remove('fade');
modal.removeAttribute('aria-hidden');
modal.removeAttribute('aria-modal');
modal.removeAttribute('tabindex');
modal.removeAttribute('role');
modal.setAttribute('role', 'search');

// Ursprüngliche Suchbuttons deaktivieren
document.querySelectorAll('[data-bs-target="#searchModal"]').forEach(button => {
button.removeAttribute('data-bs-toggle');
button.removeAttribute('data-bs-target');
button.disabled = true;
button.classList.add('mr-search-disabled');

});

// Erneutes Öffnen des Bootstrap-Modals verhindern
modal.addEventListener('show.bs.modal', event => { event.preventDefault(); });

console.info( '[Marrei.AniWorld] Permanente Schnellsuche aktiviert.' );
}

// CSS-Formatierung
const style = document.createElement('style');

style.textContent = `

/* Modal in normales Seitenelement umwandeln */
.modal.mr-inline-search {
display: block !important;
position: relative !important;
inset: auto !important;
width: 100% !important;
height: auto !important;
max-height: none !important;
overflow: visible !important;
z-index: auto !important;
opacity: 1 !important;
visibility: visible !important;
padding: 0 !important;
margin: 0 0 1rem 0 !important;
background: transparent !important;
}

/* Ursprünglichen Dialog beibehalten */
.mr-inline-search .modal-dialog {
display: block !important;
position: relative !important;
width: 100% !important;
max-width: none !important;
min-height: 0 !important;
height: auto !important;
margin: 0 !important;
transform: none !important;
pointer-events: auto !important;
}

/* Ursprünglichen Inhalt beibehalten */
.mr-inline-search .modal-content {
width: 100% !important;
height: auto !important;
max-height: none !important;
pointer-events: auto !important;
}

/* Scrollbeschränkung des Modals entfernen */
.mr-inline-search .modal-body {
overflow: visible !important;
max-height: none !important;
}

/* Schließen-Button ausblenden */
.mr-inline-search .btn-close {
display: none !important;
}

/* Tastaturkürzel-Hinweis ausblenden (optional)
.mr-inline-search .search-shortcut-hint {
display: none !important;
}
*/

/* Ursprüngliche Suchbuttons ausblenden */
.mr-search-disabled {
display: none !important;
}

`;

document.head.appendChild(style);

// Dynamische Änderungen der Webseite überwachen
const observer = new MutationObserver(moveSearch);

observer.observe(document.body, { childList: true, subtree: true });

// Schnellsuche initial verschieben
moveSearch();

})();

0 Antworten

Möchtest du antworten?

Melde dich an oder erstelle ein Konto, um eine Antwort zu posten.