WME Link Layer Settings Blocker

Prevent WME links from changing your layer settings

当前为 2024-01-26 提交的版本,查看 最新版本

// ==UserScript==
// @name            WME Link Layer Settings Blocker
// @description     Prevent WME links from changing your layer settings
// @version         2024.01.26.03
// @namespace       https://gf.qytechs.cn/en/scripts/485691-wme-link-layer-settings-blocker
// @author          Brandon28AU
// @license         MIT
// @match           *://*.waze.com/*editor*
// @exclude         *://*.waze.com/user/editor*
// @grant           none
// ==/UserScript==

(function() {
    'use strict';
    let url = window.location.href;

    function insertRestoreButton() {
        let layerSwitcherElement = document.getElementsByClassName('layer-switcher-button overlay-button')[0];

        if (layerSwitcherElement === undefined) {
            window.setTimeout(insertRestoreButton, 2000);
            return;
        }

        layerSwitcherElement.style.zIndex = '1';

        const restoreButton = document.createElement('div');
        restoreButton.style.position = 'absolute';
        restoreButton.style.top = '0';
        restoreButton.style.right = `${layerSwitcherElement.parentNode.offsetWidth / 2}px`;
        restoreButton.style.height = `${layerSwitcherElement.parentNode.offsetWidth}px`;
        restoreButton.style.color = '#333';
        restoreButton.style.border = "solid 1px #3b82f6";
        restoreButton.style.borderRadius = '9999px 0 0 9999px';
        restoreButton.style.display = 'flex';
        restoreButton.style.alignItems = 'center';
        restoreButton.style.cursor = 'pointer';
        restoreButton.classList.add('wme-llsb-restore');
        restoreButton.onclick = restoreLinkLayerSettings;

        restoreButton.innerHTML = `<style>.wme-llsb-restore{background-color: #fff; width: 0px; box-sizing: border-box; overflow: hidden; transition: background-color 0.25s linear, width 0.5s ease-in;}.wme-llsb-restore:hover{background-color: #eff6ff;}.wme-llsb-restore-content{white-space: nowrap; padding: 0 ${layerSwitcherElement.parentNode.offsetWidth / 2 + 10}px 0 15px;}.layer-switcher-button.overlay-button:hover ~ .wme-llsb-restore, .wme-llsb-restore:hover, .wme-llsb-restore.visible{width: 256px; transition: width 0.5s ease-out;}</style><div class="wme-llsb-restore-content">Restore layer settings from link</div>`;

        layerSwitcherElement.parentNode.insertBefore(restoreButton, layerSwitcherElement.nextSibling);

    }

    function restoreLinkLayerSettings() {
        window.location.replace(url.replace(/([&?])(llsblocked=)([a-z0-9]+)/i, function(match, prefix, key, value) {return prefix + "s=" + value + "&llsblocked=restored"}));

    }

    function showToast(color, message, icon) {
        // If user has been redirected, notify

        const toastContainer = document.createElement('div');
        toastContainer.style.position = 'fixed';
        toastContainer.style.bottom = '50px';
        toastContainer.style.left = '50%';
        toastContainer.style.transform = 'translate(-50%, 50%)';
        toastContainer.style.backgroundColor = '#fff';
        toastContainer.style.color = '#333';
        toastContainer.style.padding = '2px 15px 2px 10px';
        toastContainer.style.borderRadius = '9999px';
        toastContainer.style.display = 'flex';
        toastContainer.style.gap = '5px';
        toastContainer.style.border = `solid 1px ${color}`;
        toastContainer.style.alignItems = 'center';
        toastContainer.style.opacity = '0';
        toastContainer.style.zIndex = '1500';
        toastContainer.style.height = '25px';
        toastContainer.style.boxSizing = 'content-box';
        toastContainer.style.transition = 'opacity 0.5s ease-out, transform 0.5s ease-out';

        toastContainer.innerHTML = icon + '<span style="line-height: 25px">' + message + '</span';

        document.body.appendChild(toastContainer);

        // Trigger a reflow to apply styles and initiate the fade-in animation
        toastContainer.offsetHeight;

        // Show the toast
        toastContainer.style.opacity = '1';
        toastContainer.style.transform = 'translate(-50%, 0%)';

        // Automatically hide after 5 seconds
        setTimeout(() => {
            // Initiate the fade-out animation
            toastContainer.style.transition = 'opacity 0.5s ease-in, transform 0.5s ease-in';
            toastContainer.style.opacity = '0';
            toastContainer.style.transform = 'translate(-50%, 50%)';

            // Remove the element from the DOM after the animation completes
            setTimeout(() => {
                document.body.removeChild(toastContainer);
            }, 500);
        }, 5000);

    }

    if (url.match(/([&?]s=[a-z0-9]+)/i) && url.match(/([&?]llsblocked=restored)/) === null) {
        // If URL contains settings, redirect
        window.location.replace(url.replace(/([&?])(s=)([a-z0-9]+)/i, function(match, prefix, key, value) {return prefix + "llsblocked=" + value}));

    } else if (url.match(/([&?]llsblocked=[a-z0-9]+)/i) && url.match(/([&?]llsblocked=restored)/) === null) {
        // If user has been redirected, notify
        showToast('#10b981', 'Blocked layer settings from link', '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="#10b981" width="25px" height="25px"><path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75 11.25 15 15 9.75m-3-7.036A11.959 11.959 0 0 1 3.598 6 11.99 11.99 0 0 0 3 9.749c0 5.592 3.824 10.29 9 11.623 5.176-1.332 9-6.03 9-11.622 0-1.31-.21-2.571-.598-3.751h-.152c-3.196 0-6.1-1.248-8.25-3.285Z" /></svg>');

        // Insert restore button
        insertRestoreButton();

    } else if (url.match(/([&?]llsblocked=restored)/)) {
        // If user has been restored, notify
        showToast('#3b82f6', 'Restored layer settings from link', '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="#3b82f6" width="20px" height="20px"><path fill-rule="evenodd" d="M7.793 2.232a.75.75 0 0 1-.025 1.06L3.622 7.25h10.003a5.375 5.375 0 0 1 0 10.75H10.75a.75.75 0 0 1 0-1.5h2.875a3.875 3.875 0 0 0 0-7.75H3.622l4.146 3.957a.75.75 0 0 1-1.036 1.085l-5.5-5.25a.75.75 0 0 1 0-1.085l5.5-5.25a.75.75 0 0 1 1.06.025Z" clip-rule="evenodd" /></svg>');

    }

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址