WME Segment Messages

changes the styling of the segment messages

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         WME Segment Messages
// @namespace    https://fxzfun.com/
// @version      0.5
// @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';

    function fxzAddLockMessage(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 fxzAddMixedMessage() {
        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 fxzClearMessages() {
        document.querySelector(".segment-details").outerHTML += "<div id='fxzSegmentMessages'></div>";
        document.querySelector(".segment-details").style.display = "none";
    }

    function fxzCheckSegments() {
        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);
                fxzClearMessages();

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

    // bootstrap
    if (location.href.match(/^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/) != null) {
        var i = setInterval(() => {
            if (W.selectionManager.events) {
                clearInterval(i);
                W.selectionManager.events.register('selectionchanged', this, fxzCheckSegments);
                // run preselected from url
                if (W.selectionManager.getSelectedFeatures().length > 0) fxzCheckSegments();
                // add styling
                var style = document.createElement("style");
                style.innerHTML = "#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;}";
                document.body.appendChild(style);
            }
        }, 1000);
    }

})();