Talk:Bookmarklets Discussion View history

Revision as of 23:01, 30 June 2016 by Timbones (talk | contribs) (Added Pinch Zoom!)
Please bring up comments or questions about this in
 this forum topic.

Expanded views

These expanded view scripts serve as the source for the scripts on Bookmarklets. Be sure when updating any of the scripts on that page that the update is first done with this code and then pass the code through a Javascript compressor like this one and then paste that result into the main page.

Map editing

Open Waze Map Editor from LiveMap

This code is no longer required because it is now built into LiveMap.

Open LiveMap from Waze Map Editor

javascript:(function(){
    var center_lonlat=OpenLayers.Layer.SphericalMercator.inverseMercator(g_map.getCenter().lon,g_map.getCenter().lat);
    var mapZoom=(window.location.hostname=='www.waze.com' ? (g_map.zoom>6 ? (g_map.zoom>7 ? g_map.zoom-5 : g_map.zoom-6) : 0) : (g_map.zoom>10 ? g_map.zoom-11 : 0));
    window.open('http://'+window.location.hostname+'/editor/?zoom='+mapZoom+'&lon='+center_lonlat.lon+'&lat='+center_lonlat.lat,'Waze Map Editor');
})();

Enable Pinch-to-Zoom Navigation

javascript:
    var ol=function(n) {
        var s = document.createElement('script');
        s.setAttribute('src', 'https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.12/lib/OpenLayers/' + n + '.js');
        document.body.appendChild(s);
    }
    ol('Control/PinchZoom');
    ol('Handler/Pinch');
    ol('Control/TouchNavigation');
    window.setTimeout(function() {
        Waze.map.addControl(new OpenLayers.Control.TouchNavigation);
    }, 100)

Reselect Segments from Permalink

To Do: also include Places

javascript:
if (q = window.location.search.match(new RegExp("[?&]segments?=([^&]*)"))) {
    s = q[1].split(',');
    o = [];
    for (i = 0; i < s.length; i++) {
        n = Waze.model.segments.objects[s[i]];
        if (typeof n != 'undefined') o.push(n);
    }
    Waze.selectionManager.select(o);
}

Set segment locks in area

javascript:(function() {

  /* value used is -1 from rank visible in WME */
  /* fwy_lvl = 3 would appear locked at 4 in WME */
  /* can set locks to be null, which will use the auto-lock */
  var fwy_lvl = 4;
  var rmp_lvl = 3;
  var maj_lvl = 2;
  var min_lvl = 1;
  var pri_lvl = 1;
  var rr_lvl  = 1;
  var fer_lvl = 4;
  var absolute = false;
  var count = 0;
  
  var thisUser = Waze.loginManager.user;
  if (thisUser === null) return;
  var usrRank = thisUser.normalizedLevel;
  
  var UpdateObject;
  if (typeof(require) !== "undefined") {
      UpdateObject = require("Waze/Action/UpdateObject");
  } else {
      UpdateObject = Waze.Action.UpdateObject;
  }
  
  if (fwy_lvl > (usrRank - 1)) fwy_lvl = usrRank - 1;
  if (rmp_lvl > (usrRank - 1)) rmp_lvl = usrRank - 1;
  if (maj_lvl > (usrRank - 1)) maj_lvl = usrRank - 1;
  if (min_lvl > (usrRank - 1)) min_lvl = usrRank - 1;
  if (pri_lvl > (usrRank - 1)) pri_lvl = usrRank - 1;
  
  function onScreen(obj) {
    if (obj.geometry) {
      return(W.map.getExtent().intersectsBounds(obj.geometry.getBounds()));
    }
    return(false);
  }
  
  Object.forEach(W.model.segments.objects, function(k, v) {
   if (count < 150 && onScreen(v) && v.isGeometryEditable()) {
	 /* fwy */
      if (v.attributes.roadType == 3 && (v.attributes.lockRank < fwy_lvl || (absolute && v.attributes.lockRank != fwy_lvl))) {
	    count++;
        W.model.actionManager.add(new UpdateObject(v, {lockRank: fwy_lvl}));
      }
      /* ramp */
      if (v.attributes.roadType == 4 && (v.attributes.lockRank < rmp_lvl || (absolute && v.attributes.lockRank != rmp_lvl))) {
        count++;
        W.model.actionManager.add(new UpdateObject(v, {lockRank: rmp_lvl}));
      }
      /* MH */
      if (v.attributes.roadType == 6 && (v.attributes.lockRank < maj_lvl || (absolute && v.attributes.lockRank != maj_lvl))) {
        count++;
        W.model.actionManager.add(new UpdateObject(v, {lockRank: maj_lvl}));
      }
      /* mH */
      if (v.attributes.roadType == 7 && (v.attributes.lockRank < min_lvl || (absolute && v.attributes.lockRank != min_lvl))) {
        count++;
        W.model.actionManager.add(new UpdateObject(v, {lockRank: min_lvl}));
      }
      /* primary */
      if (v.attributes.roadType == 2 && (v.attributes.lockRank < pri_lvl || (absolute && v.attributes.lockRank != pri_lvl))) {
        count++;
        W.model.actionManager.add(new UpdateObject(v, {lockRank: pri_lvl}));
      }
	  /* railroad */
	  if (v.attributes.roadType == 18 && (v.attributes.lockRank < rr_lvl || (absolute && v.attributes.lockRank != rr_lvl))) {
        count++;
        W.model.actionManager.add(new UpdateObject(v, {lockRank: rr_lvl}));
      }
	  /* ferry */
	  if (v.attributes.roadType == 14 && (v.attributes.lockRank < fer_lvl || (absolute && v.attributes.lockRank != fer_lvl))) {
        count++;
        W.model.actionManager.add(new UpdateObject(v, {lockRank: fer_lvl}));
      }
    }
  });
})();

Extraneous node remover

javascript:(function() {
  var count = 0;
  var geo = W.map.getExtent().toGeometry();
  Object.forEach(W.model.nodes.objects, function(k, v) {
    if (count < 10) {
      if (v.areConnectionsEditable() && geo.containsPoint(v.geometry)) {
        if (v.attributes.segIDs.length == 2) {
          var seg1 = W.model.segments.get(v.attributes.segIDs[0]);
          var seg2 = W.model.segments.get(v.attributes.segIDs[1]);
          if (seg1 && seg2 &&
              seg1.attributes.primaryStreetID == seg2.attributes.primaryStreetID &&
              seg1.attributes.roadType == seg2.attributes.roadType &&
              seg1.isOneWay() == seg2.isOneWay() &&
              seg1.isDrivable() && seg2.isDrivable()) {
            var update = true;
            if (seg1.attributes.fwdRestrictions && seg1.attributes.revRestrictions && seg2.attributes.fwdRestrictions && seg2.attributes.revRestrictions && v.attributes.restrictions) {
              if (seg1.attributes.fwdRestrictions.length == 0 && seg1.attributes.revRestrictions.length == 0 &&
                  seg2.attributes.fwdRestrictions.length == 0 && seg2.attributes.revRestrictions.length == 0)
              {
                for (var obj in v.attributes.restrictions) {
                  update = false;
                  break;
                }
                if (seg1.attributes.toNodeID == seg1.attributes.fromNodeID || seg2.attributes.toNodeID == seg2.attributes.fromNodeID) {
                  update = false;
                }
                if (seg1.attributes.toNodeID != v.fid && (seg1.attributes.toNodeID == seg2.attributes.toNodeID || seg1.attributes.toNodeID == seg2.attributes.fromNodeID)) {
                  update = false;
                }
                if (seg1.attributes.fromNodeID != v.fid && (seg1.attributes.fromNodeID == seg2.attributes.toNodeID || seg1.attributes.fromNodeID == seg2.attributes.fromNodeID)) {
                  update = false;
                }
                if (update) {
                  var n1;
                  var n2;
                  if (seg1.attributes.toNodeID == v.fid) {
                    n1 = W.model.nodes.get(seg1.attributes.fromNodeID);
                  } else {
                    n1 = W.model.nodes.get(seg1.attributes.toNodeID);
                  }
                  if (seg2.attributes.toNodeID == v.fid) {
                    n2 = W.model.nodes.get(seg2.attributes.fromNodeID);
                  } else {
                    n2 = W.model.nodes.get(seg2.attributes.toNodeID);
                  }
                  for (var i = 0; i < n1.attributes.segIDs.length; i++) {
                    for (var j = 0; j < n2.attributes.segIDs.length; j++) {
                      if (n1.attributes.segIDs[i] == n2.attributes.segIDs[j]) {
                        console.log("Merge on", v.fid, "would cause two or more segments connected to same nodes.");
                        update = false;
                      }
                      if (update == false) { break; }
                    }
                    if (update == false) { break; }
                  }
                }
                if (update) {
                  W.model.actionManager.add(new W.Action.MergeSegments(null, v));
                  count++;
                  console.log("merged(" + count + ") " + seg1.fid + " with " + seg2.fid + " at " + v.fid);
                }
              }
            }
          }
        }
      }
    }
  });
})();

User information and communication

Create private message for user

javascript:(function(){
    var s = '';
    if (window.getSelection) {
        s = window.getSelection();
    } else if (document.getSelection) {
        s = document.getSelection();
    } else if (document.selection) {
        s = document.selection.createRange().text;
    }
    if (s == "") {
        var s = prompt("Enter Username for sending PM (or highlight name before selecting bookmarklet).");
    }
    if ((s != "") && (s != null)) {
        window.location.href="http://www.waze.com/forum/ucp.php?i=pm&mode=compose&username="+s;
    }
})();

Display user's forum posts

javascript:(function(){
    var s = '';
    if (window.getSelection) {
        s = window.getSelection();
    } else if (document.getSelection) {
        s = document.getSelection();
    } else if (document.selection) {
        s = document.selection.createRange().text;
    }
    if (s == "") {
        var s = prompt("Enter Username to view forum posts (or highlight name before selecting bookmarklet).");
    }
    if ((s != "") && (s != null)) {
        window.location.href="http://www.waze.com/forum/search.php?keywords=&terms=all&sv=0&sc=1&sf=all&sr=posts&sk=t&sd=d&st=0&ch=300&t=0&submit=Search&author="+s;
    }
})();

Display user's Wiki page

javascript:(function(){
    var s = '';
    if (window.getSelection) {
        s = window.getSelection();
    } else if (document.getSelection) {
        s = document.getSelection();
    } else if (document.selection) {
        s = document.selection.createRange().text;
    }
    if (s == "") {
        var s = prompt("Enter Username for Wiki user page (or highlight name before selecting bookmarklet).");
    }
    if ((s != "") && (s != null)) {
        window.location.href="http://wiki.waze.com/wiki/User:"+s;
    }
})();

Display user's Wiki contributions

javascript:(function(){
    var s = "";
    if (window.getSelection) {
        s = window.getSelection();
    } else if (document.getSelection) {
        s = document.getSelection();
    } else if (document.selection) {
        s = document.selection.createRange().text;
    }
    if (s == "") {
        var s = prompt("Enter Username for Wiki contributions (or highlight name before selecting bookmarklet).");
    }
    if ((s != "") && (s != null)) {
        window.location.href="http://wiki.waze.com/wiki/Special:Contributions/"+s;
    }
})();


Wiki and support pages

Purge Current Wiki Page

javascript: (function() /* BM V2 purge wiki page 2015-10-12 */ {
     var url = window.location.href;
     var test = url.search("index.php");
     if (test <1)
          {window.open(url.replace(/\/wiki\//,'\/wiki\/index.php?title=')+'&action=purge');}
          else
          {window.open(url.replace(/&action=.*/,'')+'&action=purge');}
     })();