// ==UserScript== // @name GTB4WE // @name:es Herramientas pa Gaia // @version 0.2.2 // @description Gaia ToolBox for Waze Editors. Some funcionalities to make waze map editing a little bit easier. // @description:es Gaia ToolBox for Waze Editors. Algunas funcionalidades pa hacer la edición del mapa mas sencilla. // @author abdielisai // @include http://gaia.inegi.org.mx/mdm6/* // @grant none // @license GPLv3 // @namespace https://greasyfork.org/users/118132 // @downloadURL https://update.greasyfork.icu/scripts/29276/GTB4WE.user.js // @updateURL https://update.greasyfork.icu/scripts/29276/GTB4WE.meta.js // ==/UserScript== (function () { var _debugLevel = 0; function log(message, level) { if (message && level <= _debugLevel) { console.log('GTB4WE: ' + message); } } //> Executes a callback if is valid, if not, it tries again after a time function bootstrap(valid, callback, tries) { tries = tries || 1; log("bootstrap " + tries, 3); if (valid()) { callback(); } else if (tries < 250) { setTimeout(function () { bootstrap(valid, callback, tries + 1); }, 200); } } function init() { log("init", 1); $.fn.exists = function () { return this.length !== 0; }; bootstrap( function () { return $("#mdm6DinamicPanel").exists(); }, initStreetNameObserver ); bootstrap( function () { return $("#mdmToolBar").exists() && $("#mdmToolBar")[0].childNodes.length > 0; }, function () { createLink(); //createHideButton(); } ); console.log("Gaia ToolBox for Waze Editors (GTB4WE) " + GM_info.script.version + " is running."); } function initStreetNameObserver() { log("initStreetNameObserver", 1); var observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { if ($(mutation.target).hasClass("dinamicPanel-detail")) { selectStreetName(); } }); }); observer.observe($("#mdm6DinamicPanel")[0], { childList: true, subtree: true }); } function selectStreetName() { var elements = $(".dinamicPanel-detailMainLabel"); if (elements.length === 0 || elements[0].childNodes.length === 0) return; var sel = window.getSelection(); if (!sel.isCollapsed) return; log("selecting street.", 3); var range = document.createRange(); elements[0].childNodes.forEach(function (child) { if (child.nodeName == "#text") { range.selectNodeContents(child); return; } else if (child.nodeName == "TABLE") { range.selectNodeContents(child.childNodes[0].childNodes[0].childNodes[1]); return; } }); sel.removeAllRanges(); sel.addRange(range); } //> Creates a button to go to WME function createLink() { log("createLink", 1); var $link = $("
"); $("#mdmToolBar").append($link); $link[0].onclick = go2WME; } //> Extracts coords for current position and opens a new waze map editor window function go2WME() { var params = atob(window.location.href.slice(window.location.href.indexOf('=') + 1)).split(','); params.forEach(function (value, i, array) { if (value.includes("lat") || value.includes("lon")) { array[i] = value.replace(":", "="); } else if (value.includes("z")) { //> mdm zoom minus 8 units corresponding to wme zoom var z = parseInt(value.slice(value.indexOf(":") + 1)) - 8; if (z < 0) z = 0; if (z > 10) z = 10; array[i] = "zoom=" + z; } else { array.splice(i, 1); } }); log("params " + params, 3); window.open("https://www.waze.com/editor/?" + params.join("&")); } //> Creates a button to hide header info function createHideButton() { log("createHideButton", 1); var $link = $("
"); $("#mdmToolBar").append($link); $link[0].onclick = function () { log(" hiding headers.", 3); $("#Encabezado").hide(); $("#main").css("top", "0px"); }; } bootstrap( function () { return $; }, init ); })();