// ==UserScript==
// @name WME UR Comments
// @description This script is for replying to UR comments with a single click. Based off Chat Jumper and URO+
// @namespace [email protected]
// @grant none
// @grant GM_info
// @version 0.0.91
// @match https://editor-beta.waze.com/*editor/*
// @match https://www.waze.com/*editor/*
/// @author Rick Zabel '2014
// @license MIT/BSD/X11
// ==/UserScript==
/* Changelog
* 0.0.91 - changed generic error wording from can to would
* 0.0.9 - Now working in FireFox
* 0.0.8 - changed the code to look for the user tab instead of the buggy chat window before loading the ur comment tab
* 0.0.8 - changed the code to look for the user tab instead of the buggy chat window before loading the ur comment tab
* 0.0.7 - added code to set preset filters in URO+ (new / ur replies, 4day followup, 7 day close, uro clear ur filters)
* 0.0.6 - rewrote majority of the code to pull comments out of an array and reuseable functions to generate the list / mouse clicks. also changed all instances of "rickzabelcomments" to "URComments"
* 0.0.5 - added tool tips with the text of that comment
* 0.0.4 - added Valid Route
* 0.0.3 - added HawkeyGoals slightly edited Ur-comments
* 0.0.2 - initial version
*/
//set global comment var and array
//this is the array used to store the ur comments the format is name, comment, name, comment...
window.myArray = [ "Errors with no descriptive text",
"Would you provide more information about the problem you reported here? Thanks!",
"4 day Follow-Up",
"Just a reminder: We haven't received a response on your report. If we don't hear back from you we'll have to infer everything is okay and close the report. Thanks!",
"7th day With No Response",
"The problem was unclear and volunteers didn't receive a response. As you travel, please feel welcome to report any map issues you encounter. Thanks!",
"Fixed",
"Thanks to your report we've found and fixed a problem with the map. The fix should reach handheld devices within a week, but on rare occasions it can take closer to two weeks. ",
"Missing Exit Report",
"Would you please let us know what exit you believe is missing? Thanks!",
"Turn Not Allowed Report",
"Would you please let us know what turn was not, or should not be, allowed and the street names at the intersection? Thanks!",
"Wrong Driving Direction Report",
"Would you please let us know what went wrong with the route Waze gave you? Would you tell us your destination as you entered it into Waze? Thanks!",
"Chicago Alleys",
"Waze doesn't tell volunteer editors where you were going, although it was probably adjacent to the alley. If you would, please supply your destination as you entered it into Waze it may be helpful in correcting the route. Thanks!",
"Road Closed",
"Would you please let us know the following, what road is closed; between which intersections is this road closed; do you know how long this road is scheduled to be closed? Thanks!",
"48 Hour Reply",
"Please allow 48 hours for changes to be reflected in the live map.",
"Clear Saved Locations",
"You should remove the location from your favorites and recent searches and then re-search for the location to update the result.",
"Address - Incorrect Position",
"Thank you for your report. Would you please let us know what address you're reporting the problem with? You can also use the Report -> Places feature in Waze to mark the location. It is helpful that after taking a picture, if you move near the location your marking to save the place. Also, please do not submit pictures containing faces, license plates, or similar personal details. Thanks!",
"Address - Missing from Map",
"Thank you for your report. Would you please let us know where the address you're reporting is? The live map doesn't have all the street numbers for that street and Waze is interpolating in error. You can also use the Report -> Places feature in Waze to mark the location. It is helpful that after taking a picture, if you move near the location you’re marking to save the place. Also, please do not submit pictures containing faces, license plates, or similar personal details. Thanks!",
"Address - Search Results Bad",
"Thank you for your report. The search feature retrieves results from a number of locations, including Google. Scrolling to the bottom the Navigate screen, you'll see more results for 'name.' Select that and Waze will list locations Around You. From there, you can also select results from other search engines.",
"Detours / Odd-Routing",
"We can't find anything in the map to explain route Waze gave you. Waze wants to save you time every way it can and sometimes it suggests complex detours just to shave a few seconds off your trip. Waze may recommend a detour even after the traffic has cleared up because: it doesn't know yet, other Wazers may have reported a temporary street closure, or daily traffic patterns. In any event, we are very sorry to say that the volunteer map editors can't be much help here. Thanks!",
"House Number Adjustment",
"I've forced Waze to re-register the house number for your destination. I believe this should correct your issue. Please allow 48 hours for changes to be reflected in the live map. If the location is in your saved searches or favorites, please remove them and search for them again to pick up the change in the live map. Please let me know if you continue to experience the problem. Thanks!",
"Missing Roads / Roads Not Displaying",
"The roads here have been pretty thoroughly mapped and we volunteers can't see anything missing that should ordinarily be there. Waze probably simply chose not to show you the road in question. When moving at highway speeds, Waze deliberately chooses not to display some nearby roads to avoid cluttering the screen. If you are certain a road is missing from the map, please reply and tell us as much as possible about the missing road. Thanks!",
"Road Closure Request - Temporary",
"How long is the road going to be closed? For closures of only a few days, we volunteer map editors can't be much help. It takes at least that long for our edits to make it to devices! When you encounter short-term road closures in the future, please use the Report->Closure feature in the Waze app. If this is a long-term closure please respond and let us know as much as you can. Thanks!",
"Traffic - Stale Information",
"Volunteer map editors can't do anything about Waze's traffic reporting. Waze relies on data from people using Waze to assess traffic. In the case of a fresh accident or slowdown, Waze may not yet have any data on the situation. Once Waze has detected a traffic situation, it can remember it for awhile, sometimes long after the situation changes.",
"Traffic - Jams ",
"To report traffic jam conditions, please use the Report -> Traffic Jam options in the Waze app. This will tell Waze about the problem in real-time. Traffic Jam reports can help route you and other Wazers around traffic problems.",
"Valid Route",
"We reviewed the issue and did not find any map errors. It looks like Waze had a valid route. If you feel yours is correct keep driving that way. If it is indeed faster Waze will learn from your drives and route you and others the faster route. Thanks!"
];
console.log("ur comments - generate var list");
//generate the variables to hold each item in the array
var tempstring = "tempstring";
for (URCommentsIndex = 0; URCommentsIndex < myArray.length ; URCommentsIndex = URCommentsIndex + 1 ) {
//i2 = i +1; //this is the count used to create the 2nd variable name
// eval("tempstring" + URCommentsIndex + "= myArray[ URCommentsIndex ];");
// window['tempstring' + URCommentsIndex ] = myArray[ URCommentsIndex ];
// console.log("URComments concat - " + tempstring0);
// console.log("URComments test - " + 'tempstring' + URCommentsIndex);
/*
console.log("URComments concat - " + tempstring1);
console.log("URComments concat - " + tempstring2);
console.log("URComments concat - " + tempstring3);
console.log("URComments concat - " + tempstring4);
console.log("URComments concat - " + tempstring5);
console.log("URComments concat - " + tempstring6);
console.log("URComments concat - " + tempstring7);
console.log("URComments concat - " + tempstring8);
console.log("URComments concat - " + tempstring9);
console.log("URComments concat - " + tempstring10);
console.log("URComments concat - " + tempstring11);
console.log("URComments concat - " + tempstring12);
console.log("URComments concat - " + tempstring13);
*/
}
/////////////////////////////////////
function URComments_bootstrap() {
console.log("URComments start of boot strap");
var bGreasemonkeyServiceDefined = false;
try {
var ver = window.navigator.appVersion.match(/Chrome\/(.*?) /)[1];
} catch(err) {
var ver = null;
}
if (null !== ver) {
var itschrome = true;
///ver = "27.0.1438.7"; // last old working version
// example: 32.0.1700.107
// [0] - major versin
// [2] - minor version
ver = ver.split(".");
ver[0] = parseInt(ver[0]);
ver[2] = parseInt(ver[2]);
if (ver[0] > 27) {
var newmethod = true;
} else if (ver[0] == 27) {
if (ver[2] <= 1438) {
var newmethod = false;
} else {
var newmethod = true;
}
} else {
var newmethod = false;
}
} else {
var itschrome = false;
var newmethod = false;
}
try {
if ("object" === typeof Components.interfaces.gmIGreasemonkeyService) // Firefox tells that "Components" is deprecated
{
bGreasemonkeyServiceDefined = true;
}
} catch (err) { };
try
{
if ("object" === typeof GM_info)
{
bGreasemonkeyServiceDefined = true;
}
} catch (err) { };
if ( "undefined" === typeof unsafeWindow || ! bGreasemonkeyServiceDefined)
{
try {
unsafeWindow = ( function ()
{
var dummyElem = document.createElement('p');
dummyElem.setAttribute ('onclick', 'return window;');
return dummyElem.onclick ();
} ) ();
}
catch (err)
{
//Ignore.
}
}
/* FIX IT !!!! */
var itschrome = true;
var newmethod = true;
var bGreasemonkeyServiceDefined = false;
//And check again for new chrome, and no tamper(grease)monkey
if ( itschrome && newmethod && !bGreasemonkeyServiceDefined)
{
//use "dirty" but effective method with injection to document
var DLscript = document.createElement("script");
DLscript.textContent ='unsafeWindow=window; \n'+ // need this for compatibility
URComments_init.toString()+' \n'+
'URComments_init();';
DLscript.setAttribute("type", "application/javascript");
document.body.appendChild(DLscript);
document.body.removeChild(DLscript);
} else {
/* begin running the code! */
console.log("URComments end of boot strap");
URComments_init();
///setTimeout(URComments_init,200);
}
}
function URComments_init() {
console.log("URComments start init 1");
URComments = {
last: new Array(),
isLast: false,
isLSsupported: false,
zoom: false
};
URComments.init = function() {
console.log("URComments init 2");
console.log("URComments add urcomments tab");
//add comments tab
var b = $('<li> <a data-toggle="tab" href="#sidepanel-Comments">UrComments</a> </li> ');
$(".nav-tabs").append(b);
//add the content to the comments tab
//Comment tab header
var c = $('<div class="tab-pane" id="sidepanel-Comments"> <div class="result-list-container"><p class="message"><b>This script is used for replying to UR requests.</b></p></div></div><br><br>');
$(".tab-content").append(c);
//lets try to mess with the settings in uro+ to make one click presets
/*
show new ur
with more thant 0 comments
show no responses for 4 days
(optional) with comments from me 'no'
it last cimment made by UR reporter 'no'
last comment less than 4 days ago
last comment more that 6 days ago
close after 7 days with no response
(optional) with comments from me 'no'
last comment less than 7 days ago
*/
console.log("ur comments - start adding uro filters to the comment tab");
//uro+ new ur
var d = $('<div style="margin:1px;"><a id="URCommentURONEW" class="URComments" style="float:none;color:#000000" title="Use URO+ to only show new requests or UR replies">URO+ New Requests / UR Replies</a></div>');
//d.click (URComments.comment1);
$("#sidepanel-Comments").append(d);
//create the callback function
document.getElementById("URCommentURONEW").addEventListener("click", URCommentUROClicked('UroShowNew'), false);
//uro+ reporter last comment
//var d = $('<div style="margin:1px;"><a id="URCommentUROLastCommentReporter" class="URComments" style="float:none;color:#000000" title="Use URO+ to only show URs where the reporter made the last comment">URO+ Comment made by UR reporter</a></div>');
//d.click (URComments.comment1);
// $("#sidepanel-Comments").append(d);
//create the callback function
//document.getElementById("URCommentUROLastCommentReporter").addEventListener("click", URCommentUROClicked('UROLastCommentReporter'), false);
//show no responses for 4 days
var d = $('<div style="margin:1px;"><a id="URCommentURO4DayFollowUp" class="URComments" style="float:none;color:#000000" title="Use URO+ to only show URs that need a 4 day follow up">URO+ 4 Day Follow Up</a></div>');
//d.click (URComments.comment1);
$("#sidepanel-Comments").append(d);
//create the callback function
document.getElementById("URCommentURO4DayFollowUp").addEventListener("click", URCommentUROClicked('URO4DayFollowUp'), false);
//show no responses for 7 days needs closing
var d = $('<div style="margin:1px;"><a id="URCommentURO7DayClose" class="URComments" style="float:none;color:#000000" title="Use URO+ to only show URs that are older then 7days and need to be closed">URO+ 7 Day Close</a></div>');
//d.click (URComments.comment1);
$("#sidepanel-Comments").append(d);
//create the callback function
document.getElementById("URCommentURO7DayClose").addEventListener("click", URCommentUROClicked('URO7DayClose'), false);
//uro+ clear
var d = $('<div style="margin:1px;"><a id="URCommentUROclearUROFiltrs" class="URComments" style="float:none;color:#000000" title="Clear URO+ UR Filters">URO+ Clear UR Filters</a></div><br>');
//d.click (URComments.comment1);
$("#sidepanel-Comments").append(d);
//create the callback function
document.getElementById("URCommentUROclearUROFiltrs").addEventListener("click", URCommentUROClicked('UROclearUROFiltrs'), false);
/*
UroShowNew
URO4DayFollowUp
URO7DayClose
UROLastCommentReporter
UROclearUROFiltrs
$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);
*/
console.log("ur comments - start adding comments to the comment tab");
//comments setup
//CurrentIndex isused to keep count of total arrays pairs which is used on the div's id tags
var CurrentIndex = 1
console.log("ur comments - make div 1");
//go over the array and generate divs
for ( var i = 0; i < myArray.length ; i = i + 2 ) {
console.log("ur comments - make div for - " + myArray[ i ]);
var d = $('<div style="margin:1px;"><a id="URComments-comment' + CurrentIndex + '" class="URComments" style="float:none;color:#000000" title="'+ myArray[ i + 1] +' ">' + myArray[ i ] + '</a></div>');
//d.click (URComments.comment1);
$("#sidepanel-Comments").append(d);
console.log("ur comments -create callback for - " + 'URComments-comment' + CurrentIndex);
//create the callback function in order to pass text we need to pass it trough 2 even handlers
// document.getElementById('URComments-comment' + CurrentIndex).addEventListener("click", getClickFunction(eval("tempstring" + i) ,eval("tempstring" + (i + 1))), false);
document.getElementById('URComments-comment' + CurrentIndex).addEventListener("click", getClickFunction( myArray[ i ] ,myArray[ i + 1 ]), false);
//test capturing the send comment button
// document.getElementsByClassName('btn-default').addEventListener("click", getsendcommentbutton( ), false);
// btn btn-default
//inc the CurrentIndex
CurrentIndex++;
}
console.log("URComments Tab Added");
}
getsendcommentbutton = function () {
console.log("trash");
//console.log("ur comments - click function");
return function () {
// PostURComment(a, b);
}
}
//on click pass text to the PostURComment function
getClickFunction = function(a, b) {
console.log("ur comments - click function");
return function () {
PostURComment(a, b);
}
}
function URCommentAutoReloadMapOnComment () {
//right now this is buggy i think i might have to close the comment window before reloading the map, the pin ends up getting stuck on for all uro filters
// it takes a page reload to fix it.
// i am thinking it might be better to reapply the uro filter
// i will have to add a var to remember what filter preset was on
//looks like the pin stays until map reload i will have to try the close and reload method
//alert("send clicked");
//look for the map reload button
// var x = document.getElementsByClassName("icon-repeat reload-button");
//alert(x[0]);
//x[0].innerHTML = "Hello World!";
//this clicks x0 in our case it is the reload button for the maps
// x[0].click();
}
PostURComment = function(title, comment) {
//test getting things by class
var x = document.getElementsByClassName("btn-default");
//go trough all of the eletemnts that match the requested class
for(var i = 0, j=x.length; i<j; i++){
if( x[i].innerHTML == "Send" ) {
console.log(i + " - " + x[i].innerHTML);
x[i].addEventListener("click", URCommentAutoReloadMapOnComment, true);
}
}
console.log('PostURComment set comment box to "' + title + ' - "' + comment + '"' );
if ($(".new-comment-text")[0]){
$(".new-comment-text").val(comment);
} else {
alert("Can not find the comment box! In order for this scrip to work you need to have a user request open");
}
}
URCommentUROClicked = function(a) {
return function () {
URCommentUROClearClicked(a);
}
}
URCommentUROClearClicked = function(a) {
// alert(a);
console.log("ur comments - uro clear");
//this is the array used to store the uro id tags
var URCommentUROCheckboxesArray = [ "_cbFilterWazeAuto",
"_cbFilterIncorrectTurn",
"_cbFilterIncorrectAddress",
"_cbFilterIncorrectRoute",
"_cbFilterMissingRoundabout",
"_cbFilterGeneralError",
"_cbFilterTurnNotAllowed",
"_cbFilterIncorrectJunction",
"_cbFilterMissingBridgeOverpass",
"_cbFilterWrongDrivingDirection",
"_cbFilterMissingExit",
"_cbFilterMissingRoad",
"_cbFilterBlockedRoad",
"_cbFilterMissingLandmark",
"_cbFilterUndefined",
"_cbFilterCryosphere",
"_cbFilterRoadworks",
"_cbFilterConstruction",
"_cbFilterClosure",
"_cbFilterEvent",
"_cbFilterNote",
"_cbInvertURFilter",
"_cbFilterOpenUR",
"_cbFilterClosedUR",
"_cbFilterSolved",
"_cbFilterUnidentified",
"_cbEnableMinAgeFilter",
"_cbEnableMaxAgeFilter",
"_cbURDescriptionMustBePresent",
"_cbURDescriptionMustBeAbsent",
"_cbEnableKeywordMustBePresent",
"_cbEnableKeywordMustBeAbsent",
"_cbCaseInsensitive",
"_cbHideMyComments",
"_cbHideAnyComments",
"_cbHideIfLastCommenter",
"_cbHideIfNotLastCommenter",
"_cbHideIfReporterLastCommenter",
"_cbHideIfReporterNotLastCommenter",
"_cbEnableMinCommentsFilter",
"_cbEnableMaxCommentsFilter",
"_cbHideMyFollowed",
"_cbHideMyUnfollowed",
"_cbEnableCommentAgeFilter2",
"_cbEnableCommentAgeFilter"
];
//go over the array and clear all of the uro+ check boxes
for (URCommentsIndex = 0; URCommentsIndex < URCommentUROCheckboxesArray.length ; URCommentsIndex = URCommentsIndex + 1 ) {
//document.getElementById(URCommentUROCheckboxesArray[ URCommentsIndex ]).trigger('click');
if ($(document.getElementById(URCommentUROCheckboxesArray[ URCommentsIndex ])).is(":checked")) {
//clicks the checkbox by if the checkbox is checked
$(document.getElementById(URCommentUROCheckboxesArray[ URCommentsIndex ])).trigger('click');
} else {
//click check box if checkbox in unchecked
//$(document.getElementById(URCommentUROCheckboxesArray[ URCommentsIndex ])).trigger('click');
}
}
/*
UroShowNew
UROLastCommentReporter
URO4DayFollowUp
URO7DayClose
UROclearUROFiltrs
*/
//set the different filters here
if (a == "UROclearUROFiltrs") {
//alert("URO+ UR filters hav been cleared");
} else {
if ( a == 'UroShowNew') {
console.log("ur comments - uro show new");
//alert("new");
//set URO+ max user comments to zero
///document.getElementById('_inputFilterMaxComments').value = '0';
//check the box for more than # comments
//$(document.getElementById("_cbEnableMaxCommentsFilter")).trigger('click');
//set URO+ max user comments to zero
//check the box for last user comments
$(document.getElementById("_cbHideIfReporterNotLastCommenter")).trigger('click');
}
/*
if (a == "UROLastCommentReporter") {
// _cbHideIfReporterNotLastCommenter
$(document.getElementById("_cbHideIfReporterLastCommenter")).trigger('click');
}
*/
if (a == "URO4DayFollowUp") {
console.log("ur comments - uro 4 day");
document.getElementById('_inputFilterCommentDays2').value = '1';
$(document.getElementById("_cbEnableMinCommentsFilter")).trigger('click');
document.getElementById('_inputFilterMaxComments').value = '1';
$(document.getElementById("_cbEnableMaxCommentsFilter")).trigger('click');
document.getElementById('_inputFilterCommentDays2').value = '4';
$(document.getElementById("_cbEnableCommentAgeFilter2")).trigger('click');
document.getElementById('_inputFilterCommentDays').value = '6';
$(document.getElementById("_cbEnableCommentAgeFilter")).trigger('click');
}
if (a == "URO7DayClose") {
console.log("ur comments - uro 7 day");
document.getElementById('_inputFilterCommentDays2').value = '1';
$(document.getElementById("_cbEnableMinCommentsFilter")).trigger('click');
document.getElementById('_cbEnableMaxCommentsFilter').value = '1';
$(document.getElementById("_cbEnableCommentAgeFilter")).trigger('click');
document.getElementById('_inputFilterCommentDays2').value = '7';
$(document.getElementById("_cbEnableCommentAgeFilter2")).trigger('click');
document.getElementById('_inputFilterCommentDays').value = '7';
$(document.getElementById("_cbEnableCommentAgeFilter")).trigger('click');
}
}
}
URCommentURONewClicked = function( ) {
console.log("URComment - URCommentURONewClicked");
document.getElementById("_cbFilterWazeAuto").checked = true;
}
URComments.startcode = function () {
// Check if WME is loaded, if not, waiting a moment and checks again. if yes init URComments
try {
//look for the me tab instead if the buggy chat room!
var element = document.getElementById('user-details');
console.log(document.getElementById('user-details'));
if (typeof element !== "undefined" && element.value !== '') {
//if ("undefined" != typeof unsafeWindow.W.model.chat.rooms._events.listeners.add[0].obj.userPresenters[unsafeWindow.Waze.model.loginManager.user.id] ) {
//check for the comment area
// if ($(".new-comment-text")[0]){
//console.log("URComments To Add Comment Tab");
URComments.init()
} else {
setTimeout(URComments.startcode, 500);
}
} catch(err) {
//alert(err);
console.log("UR Comments -" + err);
setTimeout(URComments.startcode, 500);
}
}
//setTimeout(URComments.startcode, 5000);
URComments.startcode();
}
setTimeout(URComments_bootstrap(), 500);
//URComments_bootstrap();