derewith / Mobbin Design VIP by jdc

// ==UserScript==
// @name         Mobbin Design VIP by jdc
// @namespace    http://tampermonkey.net/
// @version      2024-06-26
// @description  try to take over the world!
// @author       You
// @match        *://mobbin.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=mobbin.com
// @updateURL    https://openuserjs.org/meta/derewith/Mobbin_Design_VIP_by_jdc.meta.js
// @downloadURL  https://openuserjs.org/install/derewith/Mobbin_Design_VIP_by_jdc.user.js
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function removeStickyAsideElement() {
        const stickyAside = document.querySelector('aside.sticky');
        if (stickyAside) {
            stickyAside.remove();
        }
    }

    function modifyImgTags() {
        const imgElements = document.getElementsByTagName('img');
        for (let i = 0; i < imgElements.length; i++) {
            let img = imgElements[i];
            let src = img.getAttribute('src');

            if (src && src.includes('png') && src.includes('app_screens')) {
                const modifiedUrl = new URL(src);
                modifiedUrl.searchParams.set('f', 'webp');
                modifiedUrl.searchParams.set('w', '2000');
                modifiedUrl.searchParams.set('q', '85');
                modifiedUrl.searchParams.set('fit', 'shrink-cover');
                modifiedUrl.searchParams.delete('extend-bottom');
                modifiedUrl.searchParams.delete('image');
                modifiedUrl.searchParams.delete('gravity');
                modifiedUrl.searchParams.delete('layer-h');
                modifiedUrl.searchParams.delete('padding-y');
                modifiedUrl.searchParams.delete('padding-right');
                modifiedUrl.searchParams.delete('text');
                modifiedUrl.searchParams.delete('font');
                modifiedUrl.searchParams.delete('padding-top');
                modifiedUrl.searchParams.delete('padding-bottom');
                modifiedUrl.searchParams.delete('color');
                modifiedUrl.searchParams.delete('extend-color');

                img.setAttribute('src', modifiedUrl.toString());
                console.log('Modified <img> tag:', modifiedUrl.toString());

                let parentDiv = img.parentNode; // First parent div
                if (parentDiv && parentDiv.tagName.toLowerCase() === 'div') {
                    parentDiv.className = ''; // Clear all classes
                    parentDiv = parentDiv.parentNode; // Second parent div
                    if (parentDiv && parentDiv.tagName.toLowerCase() === 'div') {
                        parentDiv.className = ''; // Clear all classes
                    }
                }
            }
        }
    }

    document.addEventListener('DOMContentLoaded', function() {
        modifyImgTags();
        removeStickyAsideElement();
    });

    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            if (mutation.type === 'childList') {
                modifyImgTags();
                removeStickyAsideElement();
            }
        });
    });

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