WME OH Scripts

Recommended scripts for editing in Ohio

当前为 2016-10-06 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         WME OH Scripts
// @namespace    https://greasyfork.org/users/30701-justins83-waze
// @version      0.1.1
// @description  Recommended scripts for editing in Ohio
// @include      https://www.waze.com/editor/*
// @include      https://www.waze.com/*/editor/*
// @include      https://beta.waze.com/*
// @author       JustinS83
// @grant        none
// @require      https://greasyfork.org/scripts/9794-wlib/code/wLib.js?version=106259
// @require      https://greasyfork.org/scripts/23614-wlibext/code/wLibExt.js?version=150020
// @license      GPLv3
// ==/UserScript==

/* global W */
/* global wLib */

(function() {
    'use strict';

    // Your code here...
    function bootstrap(tries) {
        tries = tries || 1;

        if (window.W &&
            window.W.map &&
            window.W.model) {
            init();
        } else if (tries < 1000) {
            setTimeout(function () {bootstrap(tries++);}, 200);
        }
    }

    bootstrap();

    function init(){
        var section = document.createElement('div');
        section.style.padding = "8px 16px";
        section.id = "OHScriptsSettings";
        section.innerHTML  = '<div title="OHScriptTitle">Toggling options requires a hard refresh.</div>'
            + '<p><div title="OHValidatorLocalization" class="controls-container"><input type="checkbox" id="_cbOHValidatorLocalizationEnable" /><label for="_cbOHValidatorLocalizationEnable">OH Validator Localization</label></div>'
            +  '<div title="OH Counties 2014" class="controls-container"><input type="checkbox" id="_cbOHCounties2014Enable" /><label for ="_cbOHCounties2014Enable"> OH Counties 2014</label></div>'
            +  '<div title="OH Cities 2014-1" class="controls-container"><input type="checkbox" id="_cbOHCities20141Enable" /><label for ="_cbOHCities20141Enable"> OH Cities 2014-1</label></div>'
            +  '<div title="OH Cities 2014-2" class="controls-container"><input type="checkbox" id="_cbOHCities20142Enable" /><label for ="_cbOHCities20142Enable"> OH Cities 2014-2</label></div>'
            +'</p>';

        new wLib.Interface.Tab('OH Scripts', section.innerHTML);

        if(localStorage.OHScripts){
            console.log("OH Scripts exists!");
            var options = JSON.parse(localStorage.OHScripts);
            alert(options[1]);
            $('#_cbOHValidatorLocalizationEnable').attr('checked', options[1]);
            $('#_cbOHCounties2014Enable').attr('checked', options[2]);
            $('#_cbOHCities20141Enable').attr('checked', options[3]);
            $('#_cbOHCities20142Enable').attr('checked', options[4]);
        }
        else{
            $('#_cbOHValidatorLocalizationEnable').attr('checked', true);
            $('#_cbOHCounties2014Enable').attr('checked', true);
            $('#_cbOHCities20141Enable').attr('checked', false);
            $('#_cbOHCities20142Enable').attr('checked', false);
        }

        /*
        $('#_cbOHValidatorLocalizationEnable').attr('checked', myOptions.get('OHValidatorLocalization'));
        $('#_cbOHCounties2014Enable').attr('checked', myOptions.get('OHCounties'));
        $('#_cbOHCities20141Enable').attr('checked', myOptions.get('OHCities1'));
        $('#_cbOHCities20142Enable').attr('checked', myOptions.get('OHCities2'));*/

        $('#_cbOHValidatorLocalizationEnable').change(function(){
            SaveSettings();
        });
        $('#_cbOHCounties2014Enable').change(function(){
            SaveSettings();
        });
        $('#_cbOHCities20141Enable').change(function(){
            SaveSettings();
        });
        $('#_cbOHCities20142Enable').change(function(){
            SaveSettings();
        });

        if($('#_cbOHValidatorLocalizationEnable').is(':checked'))
            $.getScript("https://greasyfork.org/scripts/11240-wme-counties-ohio-census-2014/code/WME%20Counties%20Ohio%20Census%202014.user.js");

        if($('#_cbOHCounties2014Enable').is(':checked'))
            $.getScript("https://greasyfork.org/scripts/8746-wme-validator-localization-for-ohio/code/WME%20Validator%20Localization%20for%20Ohio.user.js");

        if($('#_cbOHCities20141Enable').is(':checked'))
            $.getScript("https://greasyfork.org/scripts/17391-wme-ohio-cities-census-2014-1/code/WME%20Ohio%20Cities%20Census%202014%20-%201.user.js");

        if($('#_cbOHCities20142Enable').is(':checked'))
            $.getScript("https://greasyfork.org/scripts/17392-wme-ohio-cities-census-2014-2/code/WME%20Ohio%20Cities%20Census%202014%20-%202.user.js");

    }

    function SaveSettings(){
        if (localStorage) {
			var options = [];
			// preserve previous options which may get lost after logout
			if (localStorage.OHScripts) { options = JSON.parse(localStorage.OHScripts); }
			options[1] = $('#_cbOHValidatorLocalizationEnable').is(':checked');
			options[2] = $('#_cbOHCounties2014Enable').is(':checked');
			options[3] = $('#_cbOHCities20141Enable').is(':checked');
			options[4] = $('#_cbOHCities20142Enable').is(':checked');
			localStorage.OHScripts = JSON.stringify(options);
		}
    }
})();