WME RTC Improvements

Adds several helpful features to RTC handling in the Waze Map Editor

目前為 2016-04-19 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            WME RTC Improvements
// @description     Adds several helpful features to RTC handling in the Waze Map Editor
// @namespace       vaindil
// @version         1.0.3
// @grant           none
// @include         https://www.waze.com/editor/*
// @include         https://www.waze.com/*/editor/*
// @include         https://editor-beta.waze.com/editor/*
// @include         https://editor-beta.waze.com/*/editor/*
// @exclude         https://www.waze.com/user/*
// @author          vaindil
// ==/UserScript==

function yoloswag() {
    try {
        var element = $('#sidebar');
        if ($(element).length) {
            letsAGo();
        } else {
            setTimeout(yoloswag, 1000);
        }
    } catch (err) {
        console.log("RTCENH - " + err);
        setTimeout(yoloswag, 1000);
    }
}

yoloswag();

function letsAGo() {
    $(document).on('mouseover', 'div.add-closure-button.btn.btn-primary', function() {
        $(document).off('mouseover.RTCXdays');
        $(document).on('mouseover.RTCXdays', 'div.edit-closure.new', function() {
            justDewIt();
            $(document).off('mouseover.RTCXdays');
        });
    });

    $(document).on('input.RTCXdaysfield keyup.RTCXdaysfield', 'input#expireinXdays', timeAndRelativeDimensionInSpace);
    $(document).on('click.RTCXdayscrash', 'div#RTCXdayscrash', ohNoes);
}

function justDewIt() {
    $('div.edit-closure.new > form.form > div.checkbox').before(
        '<div class="form-group">' +
            '<label class="control-label">Expire in X days</label>' +
            '<div class="controls">' +
                '<input type="number" length="3" maxlength="4" class="form-control" id="expireinXdays" />' +
            '</div>' +
        '</div>'
    );

    $('div.action-buttons').append(
        '<div class="btn btn-danger" id="RTCXdayscrash" style="float:right"><i class="fa fa-exclamation-triangle"></i>Crash</div>'
    );

    $('input[name="closure_endDate"]').datepicker('remove');
    $('input[name="closure_endDate"]').datepicker({ format: 'yyyy-mm-dd', todayHighlight: true, autoclose: true });
}

function timeAndRelativeDimensionInSpace() {
    var newdate = new Date();
    if ($('input[name="closure_startDate"]').val() !== '') {
        var p = $('input[name="closure_startDate"]').val().split('-');
        var y = parseInt(p[0], 10);
        var m = parseInt(p[1], 10);
        var d = parseInt(p[2], 10);
        if (isNaN(y) || isNaN(m) || isNaN(d))
            return;

        newdate = new Date(y, m - 1, d);
    }

    var v = parseInt($('#expireinXdays').val(), 10);
    if (isNaN(v))
        return;

    newdate.setDate(newdate.getDate() + v);
    //var newmonth = ('0' + (newdate.getMonth() + 1)).slice(-2);
    //var newday = ('0' + (newdate.getDate())).slice(-2);
    //var newstring = newdate.getFullYear() + '-' + newmonth + '-' + newday;
    $('input[name="closure_endDate"]').datepicker('update', newdate);
    if ($('input[name="closure_endTime"]').val() === '')
        $('input[name="closure_endTime"]').timepicker('setTime', '05:00');
}

function ohNoes() {

    $('input[name="closure_reason"]').val('Crash');

    var cur = new Date();
    cur.setHours(cur.getHours() + 2);
    $('input[name="closure_endDate"]').datepicker('update', cur);
    $('input[name="closure_endTime"]').timepicker('setTime', (('0' + cur.getHours()).slice(-2)) + ':' + (('0' + cur.getMinutes()).slice(-2)));
}