Replace 404 Image

Заменяет изображение и текст 404 на кастомное

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Replace 404 Image
// @namespace    https://shikimori.one/
// @version      1.1
// @description  Заменяет изображение и текст 404 на кастомное
// @author       LifeH
// @match        *://shikimori.org/*
// @match        *://shikimori.one/*
// @match        *://shikimori.me/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const imgURL = "https://i.ibb.co/QXgRz6p/rkn-2x.jpg";
    const targetIMG = "/images/static/404.jpg";

    function replaceImage() {
        const img = document.querySelector(`img.image[src="${targetIMG}"]`);
        if (img) {
            img.src = imgURL;
            img.srcset = `${imgURL} 2x`;
        }
    }

    function replaceText() {
        const errorText = document.querySelector('.dialog');
        if (errorText) {
            errorText.innerHTML = `
                <p class="error-404">Заблокировано \n Роскомнадзором</p>
                <h1>Эта страница содержала запрещённый контент.</h1>
                <p><a href="/">на главную</a></p>
                <img class="image" src="${imgURL}" srcset="${imgURL} 2x">
            `;
        }
    }

    function main() {
        replaceImage();
        replaceText();
    }

    function ready(fn) {
        window.addEventListener("load", fn);
        document.addEventListener("page:load", fn);
        document.addEventListener("turbolinks:load", fn);
        if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
            fn();
        } else {
            document.addEventListener("DOMContentLoaded", fn);
        }
    }

    ready(main);
})();