WME Segment Messages

changes the styling of the segment messages

目前為 2022-08-17 提交的版本,檢視 最新版本

// ==UserScript==
// @name         WME Segment Messages
// @namespace    https://fxzfun.com/
// @version      0.4
// @description  changes the styling of the segment messages
// @author       FXZFun
// @match        https://*.waze.com/*/editor*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=waze.com
// @grant        none
// @license      GNU GPL v3
// ==/UserScript==

/* global W */

(function() {
    'use strict';

    // add styling
    document.body.innerHTML += "<style>#fxzSegmentMessages {margin-top: 5px; margin-left: 10px;} .fxzMessage {padding: 7px 10px; border-radius: 10px; width: fit-content; margin-left: 5px;} .locked {background-color: #FE5F5D;} .mixed {background-color: #42A5F5;}</style>";

    function addLockMessage(maxLock) {
        document.querySelector("#fxzSegmentMessages").innerHTML += `<span class="fxzMessage locked"><img src="https://fxzfun.com/res/images/other/wme-lock.svg" style="width: 24px;"> Locked to L${maxLock}</span>`;
    }

    function addMixedMessage() {
        document.querySelector("#fxzSegmentMessages").innerHTML += `<span class="fxzMessage mixed"><img src="https://fxzfun.com/res/images/other/wme-mixed.svg" style="width: 24px;"> Mixed A/B</span>`;
    }

    function clearMessages() {
        document.querySelector(".segment-details").outerHTML = "<div id='fxzSegmentMessages'></div>";
    }

    function checkSegments() {
        if (W.selectionManager.getSelectedFeatures().length > 0 && W.selectionManager.getSelectedFeatures()[0].model.type === 'segment') {

            // wait for panel to open
            var i2 = setInterval(()=>{
                if (document.querySelector(".inconsistent-direction")) clearInterval(i2);
                clearMessages();

                // locked segments
                var maxLock = Math.max(...Array.from(W.selectionManager.getSelectedFeatures()).map(item => item.model.attributes.lockRank));
                if (W.loginManager.user.rank < maxLock) {
                    addLockMessage(maxLock + 1);
                }
                // mixed segments
                var incdir = document.querySelector(".inconsistent-direction")
                if (incdir.style.display != "none") {
                    addMixedMessage();
                    incdir.remove();
                }
            }, 100);
        }
    }

    // bootstrap
    var i = setInterval(() => {
        if (W.selectionManager.events) {
            clearInterval(i);
            W.selectionManager.events.register('selectionchanged', this, checkSegments);
            // run preselected from url
            if (W.selectionManager.getSelectedFeatures().length > 0) checkSegments();
        }
    }, 1000);

})();

QingJ © 2025

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