// ==UserScript==
// @name WME reviewEdits
// @namespace https://greasyfork.org/en/scripts/382070-wme-reviewedits
// @version 2019.04.20
// @description copies information from WME and adds to google sheet for record of reviewed edits.
// @author ramblinwreck_81
// @include https://www.waze.com/en-US/editor*
// @exclude https://www.waze.com/user/editor*
// @grant none
// @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js?version=229392
// ==/UserScript==
(function() {
'use strict';
var settings = {};
console.log('reviewEdits: initiating anonymous function');
function bootstrap(tries) {
console.log('reviewEdits: initiating bootstrap');
tries = tries || 1;
if (W && W.map &&
W.model && W.loginManager.user &&
$ ) {
console.log('reviewEdits: initializing WMEGL');
WMEGLinit();
} else if (tries < 1000) {
setTimeout(function () {bootstrap(tries++);}, 200);
}
}
function RE_init() {
// setTimeout(init,8000);
init();
}
function init()
{
var $section = $("<div>");
$section.html([
'<div>',
'<h2>RE_Tab</h2>',
'<input type="checkbox" id="RE_Enabled" class="RE_SettingsCheckbox"><label for="RE_Enabled">Enable This Script</label>',
'<hr>',
'<hr>',
'<div>',
'</div>',
'</div>'
].join(' '));
new WazeWrap.Interface.Tab('Review Edits', $section.html(), initializeSettings);
addLocateButton();
function addLocateButton () {
var RE_y = document.createElement('div');
RE_y.setAttribute('id', 'review-edits');
RE_y.setAttribute('style', 'display:inline;');
document.getElementById('sidepanel-RE').appendChild(RE_y);
var RE_bb = document.createElement('button');
RE_bb.setAttribute('type', 'button');
RE_bb.setAttribute('value', 'Submit');
RE_bb.setAttribute('id', 'RE_locator');
RE_bb.setAttribute('title', 'open review edit form');
RE_bb.innerHTML = 'Open Form';
document.getElementById('review-edits').appendChild(RE_bb);
document.getElementById("RE_locator").style.height="20px";
document.getElementById("RE_locator").style.width="50px";
document.getElementById('RE_locator').style.padding='1px';
document.getElementById("RE_locator").addEventListener("click",localize, false);
if(settings.Enabled) {
document.getElementById('RE_locator').disabled = false;
} else {
document.getElementById('RE_locator').disabled = true;
}
}// end of addLocateButton function
function localize()
{
// if(document.getElementById('gisStatus').style.color === 'red')
// {
// var gisButtonsButton = document.getElementById('gisStatus');
// gisButtonsButton.click();
// // alert("Please enable WME GIS Buttons.");
// // return;
// }
var RE_latTimer;
var RE_getLat = false;
document.getElementById('RE_locator').disabled = true;
function get4326CenterPoint()
{
let projI = new OL.Projection("EPSG:900913");
let projE = new OL.Projection("EPSG:4326");
let center_lonlat = (new OL.LonLat(W.map.center.lon, W.map.center.lat)).transform(projI,projE);
let lat = Math.round(center_lonlat.lat * 1000000) / 1000000;
let lon = Math.round(center_lonlat.lon * 1000000) / 1000000;
// document.getElementById('WMEGLlatitude').innerHTML = lat;
// document.getElementById('WMEGLlongitude').innerHTML = lon;
return new OL.LonLat(lon, lat);
}
debugger;
let latlon = get4326CenterPoint();
createURL();
//document.getElementById('gisCounty').click();
// checkForGreen();
// function checkForGreen()
// {
// if(document.getElementById('gisStatus').style.color === 'green')
// {
// clearTimeout(delay);
// console.log('gone green');
// finishIt();
// } else {
// console.log('waiting for green...');
// var delay = setTimeout(checkForGreen,250);
// }
// } https://www.waze.com/en-US/editor?env=usa&lon=-84.40354&lat=33.75070&zoom=5&segments=11969512 https://www.waze.com/en-US/editor?env=usa&lon=-84.43797&lat=33.74890&zoom=3&venues=180617554.1806044463.618869
// https://www.waze.com/en-US/editor?env=usa&lon=-84.40354&lat=33.75070&zoom=5
function createURL()
{
var strStartURL = 'https://www.waze.com/en-US/editor?env=usa&lon=';
var correctURL;
var newURL;
var placeName='';
var latOffset = parseInt(latlon.lat,10) + 0.003;
var lonOffset = parseInt(latlon.lon,10) - 0.003;
var zoomOffset = parseInt(W.map.zoom, 10) + 2;
var editorURL = strStartURL + lonOffset + '&lat=' + latOffset + '&zoom=' + zoomOffset;
if(W.selectionManager.getSelectedFeatures()[0].model.attributes.primaryStreetID === undefined) {
correctURL = strStartURL + latlon.lon + '&lat=' + latlon.lat + '&zoom=' + W.map.zoom + '&venues=' + W.selectionManager.getSelectedFeatures()[0].model.attributes.id;
placeName = W.selectionManager.getSelectedFeatures()[0].model.attributes.name;
} else {
correctURL = strStartURL + latlon.lon + '&lat=' + latlon.lat + '&zoom=' + W.map.zoom + '&segments=' + W.selectionManager.getSelectedFeatures()[0].model.attributes.id;
}
// if (WMEGLstr.indexOf('qpublic') > -1) {
// // matched on qpublic
// // string = 'http://qpublic9.qpublic.net/qpmap4/map.php?county=ga_fulton&layers=parcels+roads+lakes&mapmode';
// var equal = WMEGLstr.indexOf('=');
// var ampersand = WMEGLstr.indexOf('&');
// console.log(ampersand);
// var oldCounty = WMEGLstr.substr(equal, ampersand - equal);
// var underSc = oldCounty.indexOf('_');
// var newCounty = oldCounty.substr(underSc + 1);
// var firstLtr = newCounty.substr(0,1);
// firstLtr = firstLtr.toUpperCase();
// newCounty = firstLtr + newCounty.substr(1) + 'CountyGA';
// newURL = 'https://qpublic.schneidercorp.com/Application.aspx?App=' + newCounty + '&Layer=Parcels&PageType=Map';
// console.log('WMEGL new URL is ' + newURL);
// } else {
// // no match on qpublic
// newURL = WMEGLstr;
// console.log('WMEGL new URL is ' + newURL);
// }
// window.open(newURL,'gisPage');
// end of new code
// if(settings.open2ndWMEWindow) {
// var WMEGLurl = 'https://www.waze.com/en-US/editor/?env=usa&lon=' + latlon.lon + '&lat=' + latlon.lat + '&zoom=4';
// window.open(WMEGLurl,'wmeDup');
// }
// WMEGLcreateElements();
// function WMEGLthisTimeLat() {
// clearInterval(WMEGLlatTimer);
// erase();
// } // end of WMEGLthisTimeLat function
// function WMEGLcreateElements()
// {
// var WMEGLz=document.createElement("button");
// WMEGLz.setAttribute("type", "button");
// WMEGLz.setAttribute("value", "Submit");
// WMEGLz.setAttribute("id","grab-long-lat");
// WMEGLz.setAttribute("title","Get Long");
// WMEGLz.innerHTML = "Get Longitude";
// var WMEGLaa=document.createElement('textArea');
// WMEGLaa.setAttribute("id", "long-and-lat-txt");
// WMEGLaa.textContent = "";
// document.getElementById("lat-long-info").appendChild(WMEGLaa);
// document.getElementById("lat-long-info").appendChild(WMEGLz);
// document.getElementById("grab-long-lat").style.height="20px";
// document.getElementById("grab-long-lat").style.width="100px";
// var cancelIt = document.createElement('button');
// cancelIt.setAttribute('type', 'button');
// cancelIt.setAttribute('value', 'Cancel');
// cancelIt.setAttribute('id', 'stop-lat-long');
// cancelIt.setAttribute('title', 'Cancel Lat/Long');
// document.getElementById('lat-long-info').appendChild(cancelIt);
// document.getElementById('stop-lat-long').style.height = '20px';
// document.getElementById('stop-lat-long').style.width = '100px';
// cancelIt.innerHTML = "Cancel";
// document.getElementById('stop-lat-long').addEventListener('click', erase,false);
// } // end of WMGGLcreateElements function
function erase()
{
document.getElementById('WME-GIS-locator').disabled = false;
document.getElementById("grab-long-lat").removeEventListener('click',coordinates, false);
var removeElement = document.getElementById("grab-long-lat");
removeElement.parentNode.removeChild(removeElement);
removeElement = document.getElementById('long-and-lat-txt');
removeElement.parentNode.removeChild(removeElement);
removeElement = document.getElementById('stop-lat-long');
removeElement.parentNode.removeChild(removeElement);
}
function coordinates()
{
if(WMEGLgetLat !==true) {
document.getElementById("long-and-lat-txt").textContent = latlon.lon;
document.getElementById("long-and-lat-txt").select();
document.execCommand("copy");
var WMEGLa = document.getElementById("grab-long-lat");
WMEGLa.innerHTML = "Get Latitude";
WMEGLgetLat = true;
} else {
document.getElementById("long-and-lat-txt").textContent = latlon.lat;
document.getElementById("long-and-lat-txt").select();
document.execCommand("copy");
WMEGLlatTimer = setInterval(function(){WMEGLthisTimeLat();},4000);
}
}//end of coordinates function
document.getElementById("grab-long-lat").addEventListener("click",coordinates, false);
} // end of createURL function
}// end of localize function
} // end of init function
function initializeSettings()
{
loadSettings();
setChecked('WMEGLEnabled', settings.Enabled);
setChecked('WMEGLopen2ndWMEWindow', settings.open2ndWMEWindow);
$('#WMEGLlatitude').text('');
$('#WMEGLlongitude').text('');
$('.WMEGLSettingsCheckbox').change(function() {
var settingName = $(this)[0].id.substr(5);
settings[settingName] = this.checked;
saveSettings();
if(settings.Enabled) {
document.getElementById('WME-GIS-locator').disabled = false;
} else {
document.getElementById('WME-GIS-locator').disabled = true;
}
console.log(settingName + ' checkbox change saved');
});
$('#WMEGLopen2ndWMEWindow').change(function() {
settings.open2ndWMEWindow = this.checked;
saveSettings();
});
}
function setChecked(checkboxId, checked)
{
$('#' + checkboxId).prop('checked', checked);
}
function saveSettings()
{
if (localStorage) {
var localsettings = {
Enabled: settings.Enabled,
open2ndWMEWindow: settings.open2ndWMEWindow,
};
localStorage.setItem("WMEGL_Settings", JSON.stringify(localsettings));
}
if(settings.Enabled) {
document.getElementById('WME-GIS-locator').disabled = false;
} else {
document.getElementById('WME-GIS-locator').disabled = true;
}
}
function loadSettings()
{
var loadedSettings = $.parseJSON(localStorage.getItem("WMEGL_Settings"));
var defaultSettings = {
Enabled: false,
open2ndWMEWindow: false,
};
settings = loadedSettings ? loadedSettings : defaultSettings;
for (var prop in defaultSettings) {
if (!settings.hasOwnProperty(prop)) {
settings[prop] = defaultSettings[prop];
}
}
}
bootstrap();
})();