您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Lists all turn instructions defined within the current map view
当前为
// ==UserScript== // @name TISWAS // @namespace http://greasemonkey.chizzum.com // @description Lists all turn instructions defined within the current map view // @include https://*.waze.com/*editor* // @include https://editor-beta.waze.com/* // @include https://beta.waze.com/* // @exclude https://www.waze.com/user/*editor/* // @exclude https://www.waze.com/*/user/*editor/* // @grant none // @version 0.4 // ==/UserScript== /* JSHint Directives */ /* globals W: true */ /* globals trustedTypes: */ /* jshint bitwise: false */ /* jshint eqnull: true */ /* jshint esversion: 11 */ const TISWAS = { graphEntries: [], ModifyHTML: function(htmlIn) { if(typeof trustedTypes === "undefined") { return htmlIn; } else { const escapeHTMLPolicy = trustedTypes.createPolicy("forceInner", {createHTML: (to_escape) => to_escape}); return escapeHTMLPolicy.createHTML(htmlIn); } }, AddEventListener: function(elm,eventType,eventFn,eventBool) { try { document.getElementById(elm).addEventListener(eventType, eventFn, eventBool); } catch(err) { TISWAS.AddLog('AddEventListener() - '+elm+' not found!'); } }, AddLog: function(logtext) { console.log('TISWAS: '+Date()+' '+logtext); }, GraphEntry: function(segID, es, rs, t, vi) { this.segID = segID; this.es = es; this.rs = rs; this.t = t; this.vi = vi; }, StripShieldIDs: function(textIn) { let retval = ""; if(textIn !== null) { while(textIn.indexOf("$RS") !== -1) { let start = textIn.indexOf("$RS"); let end = textIn.indexOf(" ", start); if(end === -1) { textIn = textIn.slice(0, start); } else { textIn = textIn.slice(0, start) + textIn.slice(end + 1); } } retval = textIn; } return retval; }, PushGraphEntry: function(e) { for(let i in e) { if(e.hasOwnProperty(i)) { let tg = e[i].turnGuidance; if(tg !== null) { let segID = i; segID = segID.replace("f",""); segID = segID.replace("r",""); let es = []; let rs = []; let t = ""; let vi = ""; if(tg.exitSigns !== null) { for(let j = 0; j < tg.exitSigns.length; ++j) { es.push(TISWAS.StripShieldIDs(tg.exitSigns[j].text)); } } if(tg.roadShields !== null) { for(let j in tg.roadShields) { if(tg.roadShields.hasOwnProperty(j)) { rs.push(TISWAS.StripShieldIDs(tg.roadShields[j].direction)); } } } if(tg.towards !== "") { t = TISWAS.StripShieldIDs(tg.towards); } if(tg.visualInstruction !== null) { vi = TISWAS.StripShieldIDs(tg.visualInstruction); } let entry = new TISWAS.GraphEntry(segID, es, rs, t, vi); TISWAS.graphEntries.push(entry); } } } }, SegSelect: function(e) { let segID = e.currentTarget.attributes.tag.value; let segObj = W.model.segments.objects[segID]; let segCenter = segObj.attributes.geometry.getBounds().getCenterLonLat(); W.selectionManager.setSelectedModels(segObj); W.map.setCenter(segCenter); }, FormatTI: function(ge, idx) { let resHTML = '<div id="_tdiv-' + idx + '" tag="' + ge.segID + '" style="padding:2px; margin:6px; cursor:pointer;">'; resHTML += '<b>Seg: ' + ge.segID + '</b><br>'; if(ge.es.length !== 0) { resHTML += ' ES: '; for(let j = 0; j < ge.es.length; ++j) { resHTML += ge.es[j] + ' '; } resHTML += '<br>'; } if(ge.rs.length !== 0) { resHTML += ' RS: '; for(let j = 0; j < ge.rs.length; ++j) { resHTML += ge.rs[j] + ' '; } resHTML += '<br>'; } if(ge.t !== "") { resHTML += ' T: ' + ge.t + '<br>'; } if(ge.vi !== "") { resHTML += ' VI: ' + ge.vi + '<br>'; } resHTML += '</div>'; return resHTML; }, SurfaceTIs: function() { let resHTML = ''; TISWAS.graphEntries = []; let nEntries = 0; if(W.map.getZoom() >= 17) { W.model.turnGraph.reverseAdjacencyList.forEach(TISWAS.PushGraphEntry); nEntries = TISWAS.graphEntries.length; if(nEntries > 0) { for(let i = 0; i < TISWAS.graphEntries.length; ++i) { let ge = TISWAS.graphEntries[i]; resHTML += TISWAS.FormatTI(ge, i); } } else { resHTML += "No TIs here..."; } } else { resHTML += "TIs only available at zoom 17+"; } document.querySelector('#_tisOutput').innerHTML = TISWAS.ModifyHTML(resHTML); if(nEntries > 0) { for(let i = 0; i < nEntries; ++i) { let linkID = "_tdiv-" + i; TISWAS.AddEventListener(linkID, "click", TISWAS.SegSelect, true); } } }, PopulateUI: function() { var iHTML = ''; iHTML += '<div id="_tisOutput" />'; return iHTML; }, Initialise: function() { TISWAS.AddLog("Initialise"); if(document.getElementsByClassName("sandbox").length > 0) { TISWAS.AddLog('WME practice mode detected, script is disabled...'); return; } if(document.location.href.indexOf('user') !== -1) { TISWAS.AddLog('User profile page detected, script is disabled...'); return; } TISWAS.WaitForW(); }, WaitForW: function() { if(window.W === undefined) { window.setTimeout(TISWAS.WaitForW, 100); return; } if (W.userscripts?.state?.isReady) { TISWAS.AddTab_API(); } else { document.addEventListener("wme-ready", TISWAS.AddTab_API, {once: true}); } }, AddTab_API: async function() { TISWAS.AddLog("Registering with sidepanel..."); let {tabLabel, tabPane} = W.userscripts.registerSidebarTab("TISWAS"); tabLabel.innerText = "TISWAS"; tabPane.innerHTML = TISWAS.ModifyHTML(TISWAS.PopulateUI()); await W.userscripts.waitForElementConnected(tabPane); TISWAS.CompleteUISetup(); }, CompleteUISetup: function() { W.map.events.register("moveend", null, TISWAS.SurfaceTIs); W.map.events.register("zoomend", null, TISWAS.SurfaceTIs); } }; TISWAS.Initialise();