Bypass login on mature posts

Bypass login on specific websites that block access to mature content without logging in.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Bypass login on mature posts
// @match       *://*.artstation.com/*
// @match       *://*.deviantart.com/*
// @grant       none
// @version     1.6
// @author      -
// @license      MIT
// @description Bypass login on specific websites that block access to mature content without logging in.
// @namespace Violentmonkey Scripts
// ==/UserScript==

(function() {
    'use strict';
    var done = false;
    function uncensor() {
        if (window.location.hostname.endsWith('artstation.com')) {
            document.querySelector('mature-content')?.remove();
            document.querySelector('.matureContent')?.remove();
            document.querySelector('.matureContent-hide')?.classList.remove('matureContent-hide');
        }
        if (window.location.hostname.endsWith('deviantart.com')) {
            if (done==false) {
                done = true;

                function replaceBackgroundWithImage(selector) {
					let element = document.querySelector(selector);
					if (!element) return;
					if (!(element.tagName === "DIV" && /^background-image\s*:\s*url/i.test(element.getAttribute("style") || ""))) {
						return;
					}


					//There are images without <figure> element
					document.querySelector('body > main > div > div > div > div > div:nth-child(2) > div > div:nth-child(2)')?.remove();
					//And with <figure> element
					document.querySelector('body > main > div > div > div > div > figure > div > div > div:nth-child(2)')?.remove();

					element.classList.remove(element.classList.item(1));

					element.style.backgroundImage = element.style.backgroundImage.replace(
					/w_\d+,h_\d+/,
					"w_800,h_800"
					);

					const imageUrl = element.style.backgroundImage.slice(4, -1).replace(/['"]/g, '');

					const img = document.createElement('img');
					img.src = imageUrl;
					img.className = element.className;
					element.replaceWith(img);
					img.parentElement.classList.remove(img.parentElement.classList.item(0));
                }

				replaceBackgroundWithImage('body > main > div > div > div > div > div:nth-child(2) > div > div > div');
				replaceBackgroundWithImage('body > main > div > div > div > div > figure > div > div > div > div');
		    }
        }
    }

    // Observe DOM changes in case elements load dynamically
    const observer = new MutationObserver(uncensor);
    observer.observe(document.body, { childList: true, subtree: true });
})();