WME UR Comments

This script is for replying to UR comments with a single click. Based off Chat Jumper and URO+

ของเมื่อวันที่ 24-10-2014 ดู เวอร์ชันล่าสุด

// ==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		RickZabel@gmail.com
// @grant			none
// @grant			GM_info
// @version			0.1.13
// @match			https://editor-beta.waze.com/*editor/*
// @match			https://www.waze.com/*editor/*
// @author			Rick Zabel '2014
// @license			MIT/BSD/X11
// ==/UserScript==

var URCommentVersion = "0.1.13";
var URCommentVersionUpdateNotes = "UR Comments has been updated to " + URCommentVersion + ", Added a setting to add reply Instructions to the end of the 4 day follow up! Also moved settings to the bottom of the list since they dont need to be seen as often.";

/* Changelog
 * 0.1.13 - Added a user setting for adding reply Instructions to the 4 day follow up
 * 0.1.11 - Added  version number to notifactions
 * 0.1.1 - Added new version notifactions
 * 0.1.0 - Close and Reloads the map if the following events happen, request has to be open, cicked any ur comment on the UrCommnet tab, then clicked send. this will force uro+ to reapply it's filter
 * 0.0.92 - added comment for clearing TTS Cache
 * 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
 */


/* Wishlist 
 * 
 * /my own
 * split the close / reload to two different option when reload turns Auto close back on (reloading with an UR open makes the UR not able to be controller with URO)
 * add a check to see if URo is installed
 * (this is turning out to be harder then i thought) find a way to auto close fixed and 7 day closed UR,and then deal with the message, then click save 
 * if possible have an option to zoom back out all the way after clicking send / close on a UR
 * set up the code with a dropdown box for multi Languages or others boilerplate lists (dwarf's, vector, hawkey,...) would have to rewrite the way reply Instructions are handled 
 * perhaps after each array set var ReplyInstructions = "dwarf's, vector, hawkey,..."
 * 
 * /users
 * hakweygoal would like a way to edit the comments (not sure how to do this as of right now a new version would over write what ever changes i let users make)
*/


//alert the user in  URComment version updates
if (localStorage.getItem('URCommentVersion') == URCommentVersion) {
    //alert("UR Comments current version");
} else {
    alert(URCommentVersionUpdateNotes)
    localStorage.setItem('URCommentVersion', URCommentVersion);
}


window.BoilerPlateCreatorsArray = [ "rickzabel",
                                   "dwarflord",
                                   "hawkeygoal",
                                   "vectorspace"
                                  ];


//set global comment var and array
//this is the array used to store the ur comments the format is name, comment, name, comment...


//rickzabel's list
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. ",
                  "<br>",
                  "",
                  "Missing Exit",
                  "Would you please let us know what exit you believe is missing? Thanks!",
                  "Turn Not Allowed",
                  "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",
                  "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.",
                  "Clear TTS Cache",
                  "If you continue to have this problem you will need to clear your Text to Speech cache. Go to navigation screen and type cc@tts in search field and hit search. You should get a pop up message that the TTS file has been cleared. It will take a few days for the file to build back up with all the spoken street names.",
                  "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!"
                 ];

ReplyInstructions = "(Respond directly to these messages in the Waze app inbox, by clicking on “Map issue – new Comment”, scroll all the way down to the reply box, enter your reply and click send!)";
//end rickzabel's list


console.log("ur comments - generate var list");




/////////////////////////////////////

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('close-button').addEventListener("click", getsendcommentbutton( ), false);
            
            // btn btn-default
            
            //inc the CurrentIndex
            CurrentIndex++;
        }
        
        /*
        //go over  BoilerPlateCreatorsArray and generate the select   
        var d = '<br><br><select id="BoilerPlateCreators">';
        for ( var i = 0; i < BoilerPlateCreatorsArray.length  ; i = i + 1 ) {
            console.log("ur comments - make div for - " + BoilerPlateCreatorsArray[ i ]);
            //var d = $('<div style="margin:1px;"><a id="URComments-comment' + i + '" class="URComments" style="float:none;color:#000000" title="123">' + BoilerPlateCreatorsArray[ i ] + '</a></div>');  
            d = d + '<option value="' + BoilerPlateCreatorsArray[ i ] + '">' +  BoilerPlateCreatorsArray[ i ] + '</option>';
            console.log("ur comments - BoilerPlateCreatorsArray " + BoilerPlateCreatorsArray[ i ]);
        }
        d = d + "</select><br><br>";
        $("#sidepanel-Comments").append(d);
        //create call back for the select
        //document.getElementById('URComments-comment' + CurrentIndex).addEventListener("click", getClickFunction( BoilerPlateCreatorsArray[ i ] ,BoilerPlateCreatorsArray[ i + 1 ]), false);
        document.getElementById("BoilerPlateCreators").addEventListener("change", BoilerPlateCreatorsFunction, false);
        
		//set the users BoilerPlateCreators choice in the select   
        var storedlist = localStorage.getItem('BoilerPlateCreators');
        alert(storedlist);
        if (storedlist != "") {
            //this is how you set the select after it is filled
            $("#BoilerPlateCreators").val(localStorage.getItem('BoilerPlateCreators'));
        } else {
            alert("null");
             $("#BoilerPlateCreators").val("rickzabel");
        }
        */
        
        //auto reload map after sending comment replies
        var d = $('<br><input type="checkbox" id="UrCommentAutoReloadAfterComment" title="This option will close the user request and reload the map after you click send.This forces URO+ to re-apply the chosen URO filters. Currently this does not apply to the Fixed and 7th day With No Response messages since each you have to choose Closed or Not identified, then click save, and then click ok on the message about open dialog. ">Auto Close / Reload After Comment<br>');
        $("#sidepanel-Comments").append(d);
        //create the callback function
        document.getElementById("UrCommentAutoReloadAfterComment").addEventListener("change", AutoReloadAfterComment, false);       
        
        //add reply Instructions to the 4 day Follow-Up
        var d = $('<input type="checkbox" id="UrCommentAddReplyInstructions" title="Add Reply Instructions to each UR-Comment">Add Instructions to the 4 day Follow Up<br><br>');
        $("#sidepanel-Comments").append(d);
        //create the callback function
        document.getElementById("UrCommentAddReplyInstructions").addEventListener("change", AddReplyInstructions, false);       
        
        console.log("URComments Tab Added");  
        
        // UR-COmments load and set settings and checkboxes  
        if (localStorage.getItem('AutoReloadAfterComment') == "yes") {
            //alert("YES");
            $(document.getElementById("UrCommentAutoReloadAfterComment")).trigger('click');
        }  
        
        //post reply Instructions to comments
        if (localStorage.getItem('AddReplyInstructions') == "yes") {
            //alert("YES");
            $(document.getElementById("UrCommentAddReplyInstructions")).trigger('click');
        }      
        
    }                    
    
    
    //use this to save what choice is made in the list and then reload the page to change lists
    BoilerPlateCreatorsFunction = function () {
        //alert(BoilerPlateCreatorsFunction);
        alert("you have selected " + BoilerPlateCreators.value);
        
        //this is how you set the select after it is filled
        // $("#BoilerPlateCreators").val("vectorspace");
        
        localStorage.setItem('BoilerPlateCreators', BoilerPlateCreators.value);
        //this will reload the page
        location.reload();   
    }
    
    
    getsendcommentbutton = function () {
        console.log("trash");
        //console.log("ur comments - click function");
        return function () {
            // PostURComment(a, b);   
        }
    }
    
    
    // UrCommentAutoReloadAfterComment
    AutoReloadAfterComment = function() {
        //alert("check Box clicked");
        
        //try to save the state of the check box
        if (UrCommentAutoReloadAfterComment.checked) {
            localStorage.setItem('AutoReloadAfterComment','yes');
            //alert("yes");
        } else {
            localStorage.setItem('AutoReloadAfterComment','no');
            //alert("no");
        }
        //alert ( localStorage.getItem('AutoReloadAfterComment') ); 
        
    }
    
    
    //UrCommentAddReplyInstructions
    //add reply inscrutions to replies
    AddReplyInstructions = function() {
        //alert("UrCommentAddReplyInstructions check Box clicked");
        
        //try to save the state of the check box
        if (UrCommentAddReplyInstructions.checked) {
            localStorage.setItem('AddReplyInstructions','yes');
            //alert(" AddReplyInstructions yes");
        } else {
            localStorage.setItem('AddReplyInstructions','no');
            //alert("AddReplyInstructions no");
        }
        //alert ( localStorage.getItem('AutoReloadAfterComment') ); 
        
    }
    
    //on click pass text to the PostURComment function
    getClickFunction = function(a, b) {
        console.log("ur comments - click function");
        return function () {
            PostURComment(a, b);   
        }
    }
    
    
    function URCommentSendBtnClicked () {
        //look for close btn
        var x = document.getElementsByClassName("close-button");
        //alert( x.length );
        //go trough all of the eletemnts that match the requested class
        for(var i = 0, j=x.length; i<j; i++){
            // alert(i + " - " + x[i].innerHTML);
            var btnHtml = (i + " - " + x[i].innerHTML);
            //alert (btnHtml);
            if(btnHtml.indexOf("<span>Close</span>") > -1) {
                
                setTimeout(timehack, 500);
                
            }
        }
    }   
    
    
    function timehack () {
        var x = document.getElementsByClassName("close-button");
        //alert( x.length );
        //go trough all of the eletemnts that match the requested class
        for(var i = 0, j=x.length; i<j; i++){
            // alert(i + " - " + x[i].innerHTML);
            var btnHtml = (i + " - " + x[i].innerHTML);
            //alert (btnHtml);
            if(btnHtml.indexOf("<span>Close</span>") > -1) {
                //alert("clse btn found");
                
                x[i].click();
                
                setTimeout(URCommentAutoReloadMapOnComment, 500); 
                
                console.log(i + " - " + x[i].innerHTML);
                //close btn
                // x[i].addEventListener("click", URCommentCloseBtnClicked, true);
            }
        }
    }
    
    
    
    function URCommentCloseBtnClicked () {
        //alert("closed clicked");
        setTimeout(URCommentAutoReloadMapOnComment, 500);
    }
    
    
    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("URCommentAutoReloadMapOnComment");
        
        //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) {
        
        //if the user option is set to reload map after posting comment reply
        if (UrCommentAutoReloadAfterComment.checked & title != "Fixed" & title != "7th day With No Response") {
            //here we are getting ready to reload the maps after clicking a urcomment reply then send then close.
            //it does not work if i reload after clicking send (the ur gets stuck untill a page reload), or clicking send then close (wont reload), 
            
            //look for the sent button
            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++){
                var btnHtml = (i + " - " + x[i].innerHTML);
                //alert (btnHtml);
                if(btnHtml.indexOf("Send") > -1) {
                    //alert("send button found");
                    console.log(i + " - " + x[i].innerHTML);
                    //send btn
                    x[i].addEventListener("click", URCommentSendBtnClicked, true);
                }
                
            }
        }
        
        console.log('PostURComment set comment box to "' + title + ' - "' + comment + '"' );
        
        if ($(".new-comment-text")[0]){ 
            //alert(UrCommentAddReplyInstructions.checked);
            //alert(ReplyInstructions);
            if (UrCommentAddReplyInstructions.checked == true & title == "4 day Follow-Up") {
                //reply instructions
                $(".new-comment-text").val(comment + "\r\n\r\n" + ReplyInstructions);   
            } else {
                //comment only
                $(".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, 2000);
            }
        } catch(err) {
            //alert(err);
            console.log("UR Comments -" + err);
            setTimeout(URComments.startcode, 2000);
        }
        
    }
    
    //setTimeout(URComments.startcode, 5000);
    URComments.startcode();
}
setTimeout(URComments_bootstrap, 2000);


//URComments_bootstrap();