forked from jm6087/WME-BackEnd-Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWME-BED.user.js
More file actions
1961 lines (1825 loc) · 111 KB
/
WME-BED.user.js
File metadata and controls
1961 lines (1825 loc) · 111 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name WME BackEnd Data
// @namespace https://github.com/thecre8r/
// @version 2020.11.24.01
// @description Shows Hidden Attributes, AdPins, and Gas Prices for Applicable Places
// @include https://www.waze.com/editor*
// @include https://www.waze.com/*/editor*
// @include https://beta.waze.com/editor*
// @include https://beta.waze.com/*/editor*
// @include https://support.google.com/waze/answer/7402261*
// @exclude https://www.waze.com/user/editor*
// @icon data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><g><path fill="rgb(120, 176, 191)" d="M176 256c44.11 0 80-35.89 80-80s-35.89-80-80-80-80 35.89-80 80 35.89 80 80 80zm352-128H304c-8.84 0-16 7.16-16 16v144H64V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v352c0 8.84 7.16 16 16 16h32c8.84 0 16-7.16 16-16v-48h512v48c0 8.84 7.16 16 16 16h32c8.84 0 16-7.16 16-16V240c0-61.86-50.14-112-112-112z" class=""></path></g></svg>
// @author The_Cre8r
// @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
// @require https://greasyfork.org/scripts/373256-qrcode-js/code/QRCode-Js.js?version=636795
// @require https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @license GPLv3
// @connect gapi.waze.com
// @grant GM_xmlhttpRequest
// ==/UserScript==
/* global W */
/* global OpenLayers */
/* ecmaVersion 2017 */
/* global $ */
/* global I18n */
/* global _ */
/* global WazeWrap */
/* global require */
/* global QRCode */
/* global Backbone */
(function() {
'use strict';
const STORE_NAME = "WMEBED_Settings";
const SCRIPT_NAME = GM_info.script.name;
const SCRIPT_VERSION = GM_info.script.version.toString();
const SCRIPT_CHANGES = `Compatibility update.`
const UPDATE_ALERT = false;
const USER = {name: null, rank:null};
const SERVER = {name: null};
const COUNTRY = {id: 0, name: null};
let _ads = [];
let _settings = {};
let _adPinsLayer;
//let _PsudoVenueLayer;
let streetAlias = { // Used when matching ad addresses for newly created places. Format: Waze Abbreviation:Ad Street Name
'1ST':'FIRST','2ND':'SECOND','3RD':'THIRD','4TH':'FOURTH','5TH':'FIFTH','6TH':'SIXTH','7TH':'SEVENTH','8TH':'EIGHTH','9TH':'NINTH','10TH':'TENTH',
'FIRST':'1ST','SECOND':'2ND','THIRD':'3RD','FOURTH':'4TH','FIFTH':'5TH','SIXTH':'6TH','SEVENTH':'7TH','EIGHTH':'8TH','NINTH':'9TH','TENTH':'10TH',
'NORTH':'N','SOUTH':'S','EAST':'E','WEST':'W','N':'NORTH','S':'SOUTH','E':'EAST','W':'WEST',
'AVE':'AVENUE','PKY':['PARKWAY','PKWY'],'PKWY':['PARKWAY','PKY'],'ST':'STREET','RD':'ROAD','DR':'DRIVE','PLZ':'PLAZA','CIR':'CIRCLE',
'I-':'IH-','NE':'NORTHEAST','NW':'NORTHWEST','SE':'SOUTHEAST','SW':'SOUTHWEST'
};
function log(msg) {
console.log('WMEBED: ', msg);
}
function installIcon() {
log('Installing OpenLayers.Icon');
OpenLayers.Icon = OpenLayers.Class({
url: null,
size: null,
offset: null,
calculateOffset: null,
imageDiv: null,
px: null,
initialize: function(a,b,c,d){
this.url=a;
this.size=b||{w: 20,h: 20};
this.offset=c||{x: -(this.size.w/2),y: -(this.size.h/2)};
this.calculateOffset=d;
a=OpenLayers.Util.createUniqueID("OL_Icon_");
let div = this.imageDiv=OpenLayers.Util.createAlphaImageDiv(a);
$(div.firstChild).removeClass('olAlphaImg'); // LEAVE THIS LINE TO PREVENT WME-HARDHATS SCRIPT FROM TURNING ALL ICONS INTO HARDHAT WAZERS --MAPOMATIC
},
destroy: function(){ this.erase();OpenLayers.Event.stopObservingElement(this.imageDiv.firstChild);this.imageDiv.innerHTML="";this.imageDiv=null; },
clone: function(){ return new OpenLayers.Icon(this.url,this.size,this.offset,this.calculateOffset); },
setSize: function(a){ null!==a&&(this.size=a); this.draw(); },
setUrl: function(a){ null!==a&&(this.url=a); this.draw(); },
draw: function(a){
OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv,null,null,this.size,this.url,"absolute");
this.moveTo(a);
return this.imageDiv;
},
erase: function(){ null!==this.imageDiv&&null!==this.imageDiv.parentNode&&OpenLayers.Element.remove(this.imageDiv); },
setOpacity: function(a){ OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv,null,null,null,null,null,null,null,a); },
moveTo: function(a){
null!==a&&(this.px=a);
null!==this.imageDiv&&(null===this.px?this.display(!1): (
this.calculateOffset&&(this.offset=this.calculateOffset(this.size)),
OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv,null,{x: this.px.x+this.offset.x,y: this.px.y+this.offset.y})
));
},
display: function(a){ this.imageDiv.style.display=a?"": "none"; },
isDrawn: function(){ return this.imageDiv&&this.imageDiv.parentNode&&11!=this.imageDiv.parentNode.nodeType; },
CLASS_NAME: "OpenLayers.Icon"
});
}
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}
function fillForm() {
if (getUrlParameter('username') != "") {
injectCssGoogle();
document.getElementsByName('username')[0].value = getUrlParameter('username');
document.getElementsByName('brand_name')[0].value = getUrlParameter('brand_name');
document.getElementsByName('incorrect_gps_coordinates')[0].value = getUrlParameter('incorrect_gps_coordinates');
document.getElementsByName('pin_address')[0].value = getUrlParameter('pin_address');
document.getElementsByName('correct_gps_coordinates')[0].value = getUrlParameter('correct_gps_coordinates');
document.getElementsByName('description')[1].value = getUrlParameter('description');
if (getUrlParameter('p1') == 'true') {
document.querySelector('#misplaced_ad_pins > div:nth-child(9) > fieldset > div:nth-child(3) > label > label').click()
}
else if (getUrlParameter('p2') == 'true') {
document.querySelector('#misplaced_ad_pins > div:nth-child(9) > fieldset > div:nth-child(3) > label > label').click()
}
let addressLabel;
let addressID = document.getElementsByName('pin_address')[0].id;
for (let i=0;i<document.getElementsByTagName('label').length;i++) {
if (document.getElementsByTagName('label')[i].getAttribute('for') == addressID) {
addressLabel = document.getElementsByTagName('label')[i];
}
}
let addressNote = document.createElement('div');
addressNote.setAttribute('style','color:red;font-weight:bold;');
addressNote.innerText = "Autofilled address may differ from address displayed on the ad in the Waze app.";
addressLabel.append(addressNote);
let qrContainer = document.createElement('div');
qrContainer.className = 'sibling-nav';
qrContainer.setAttribute('style','padding-left:42px;');
let qrTitle = document.createElement('h4');
qrTitle.innerText = 'Open in the Waze App';
let qrCode = document.createElement('div');
qrCode.id = 'appLinkQRCode';
qrCode.setAttribute('style','padding-left:42px;');
qrContainer.append(qrTitle);
qrContainer.append(qrCode);
document.getElementsByClassName('fixed-sidebar-container')[0].append(qrContainer);
displayQrCode("appLinkQRCode", getUrlParameter('adid'));
}
}
function getSearchServer() {
if (SERVER.name == "row") {
return "row-SearchServer";
} else if (SERVER.name == "il") {
return "il-SearchServer";
} else {
return "SearchServer";
}
}
function getAdServer() {
if (SERVER.name == "row") {
return "ROW";
} else if (SERVER.name == "il") {
return "IL";
} else {
return "NA";
}
}
function requestAds(event) {
log('Requested Ads '+event.data.source);
if (event.data.source == 'venues'){
if (USER.rank >= 5 || TESTERS.indexOf(USER.name) > -1) {
let namesArray = _.uniq(W.model.venues.getObjectArray().filter(venue => WazeWrap.Geometry.isGeometryInMapExtent(venue.geometry)).map(venue => venue.attributes.name));
for (var i = 0; i < namesArray.length; i++) {
let venue = {id: null, name: namesArray[i]};
if (!venue.name.includes("Parking -") || !venue.name.includes("Parking -") || !venue.name.includes("Lot -")) {
getAds(get4326CenterPoint(),venue)
}
}
}
else {
alert("This tool is only available for rank 5 and above");
}
}
else {
//let requestedName = prompt("Please enter the name of the requested ads");
let requestedName;
function RequestName(e, value) {
requestedName = value;
if (requestedName && requestedName.trim()) {
let venue = {id: null, name: requestedName.trim(),source: "prompt"};
log(`Searched for ${venue.name}`);
getAds(get4326CenterPoint(),venue)
}
}
WazeWrap.Alerts.prompt(GM_info.script.name, "Please enter the name of the requested ads", "", function(e, value){RequestName(e,value)});
setTimeout(function(){
$("#toast-container-wazedev > div > div:nth-child(4) > input").focus()
},10);
}
}
// Capture enter and escape press for alert
$(document).ready(function() {$(document).on("keydown", excapeorenter);});
function excapeorenter(e) {
if ((e.which || e.keyCode) == 13 && $(".toast-prompt-input").length > 0){
$("#toast-container-wazedev > div > div:nth-child(4) > div > button.btn.btn-primary.toast-ok-btn").click()
}
else if ((e.which || e.keyCode) == 27 && $(".toast-prompt-input").length > 0){
$("#toast-container-wazedev > div > div:nth-child(4) > div > button.btn.btn-danger").click()
}
}
function processAdsResponse(res) {
let venue = this.context;
let ad_data;
//log('this: '+(Object.getOwnPropertyNames(this)));
log('AdPin URL: '+encodeURIComponent(this.finalUrl));
//log('Venue: '+(Object.getOwnPropertyNames(venue)));
let gapidata = $.parseJSON(res.responseText);
//log(gapidata[1]);
//let ad_data = gapidata[1].has(entry => entry.j)
for (var i = 0; i < gapidata[1].length; i++) {
if (typeof gapidata[1][i][3] === 'undefined')
{log(`Run ${i+1} of ${gapidata[1].length}: No Ad Created`)}
else if (gapidata[1][i][3].j){
ad_data = gapidata[1][i][3];
ad_data.name = gapidata[1][i][0];
ad_data.name = ad_data.name.replace(/[\u0007\f]/g,'');
ad_data.j = JSON.parse(ad_data.j.substring(3, ad_data.length))
log(`Run ${i+1} of ${gapidata[1].length}: Attempting to create ad for ${ad_data.name} at ${ad_data.a}`)
if (venue.id) {
makeAdPin(ad_data,venue);
} else {
makeAdPin(ad_data,null);
}
} else {
log(`Run ${i+1} of ${gapidata[1].length}: No Ad Created`)
}
}
}
function getAds(latlon,venue) {
let venue_name = getNameParts(venue.name).base;
venue_name.replace(/\([\w\W]+\)/,'');
if (venue_name == "")
return;
log(`Requesting Ads for ${venue_name}`)
console.log(venue)
if (_settings.ShowRequestPopUp == true || venue.source == "prompt"){
WazeWrap.Alerts.info(GM_info.script.name, ` Requested Ads for ${venue_name}`);
}
GM_xmlhttpRequest({
url: `https://gapi.waze.com/autocomplete/q?e=${getAdServer()}&c=wd&sll=${latlon.lat},${latlon.lon}&s&q=${venue_name}&gxy=1`,
context: venue,
method: 'GET',
onload: processAdsResponse,
onerror: function(result) { log("error: "+ result.status) }
})
}
function onAdPinLayerCheckboxChanged(checked) {
_adPinsLayer.setVisibility(checked);
checked = document.querySelector('#layer-switcher-item_ad_pins').checked
_settings.AdPin = checked;
saveSettings();
}
function setChecked(checkboxId, checked) {
$('#WMEBED-' + checkboxId).prop('checked', checked);
log('#WMEBED-' + checkboxId + " is " + checked);
}
function injectCss() {
let styleElements = getWmeStyles();
let css = [
// formatting
'.EP2-link{cursor: context-menu;background-color:#fff;box-shadow:rgba(0,0,0,.1) 0 2px 7.88px 0;box-sizing:border-box;color:#354148;height:30px;line-height:30px;text-decoration:none;text-size-adjust:100%;transition-delay:0s;transition-duration:.25s;transition-property:all;transition-timing-function:ease-in;width:auto;-webkit-tap-highlight-color:transparent;border-color:#354148;border-radius:8px;border-style:none;border-width:0;padding:5px 15px}',
'.EP2-link:hover {text-decoration:none;}',
'.EP2-img {padding-right: 6px;position: relative; top: -3px;}',
'.EP2-img-fa {font-size:11px}',
'.EP2-icon {color: #8c8c8c;margin-left: 4px;}',
'#EP2-spider {cursor:pointer;}',
'#WMEBED-header {margin-bottom:10px;}',
'#WMEBED-title {font-size:15px;font-weight:600;}',
'#WMEBED-version {font-size:11px;margin-left:10px;color:#aaa;}',
'#WMEBED-close-ad {color: red;float:right;position: relative;cursor: pointer;}',
'.WMEBED-report {text-align:center;padding-top:20px;}',
'#WMEBED-report-an-issue-gas {cursor:pointer;}',
'.WMEBED-Button {font-family:"Rubik","Boing-light",sans-serif,FontAwesome;padding-left:10px;padding-right:10px;margin-top:0px;z-index: 3;}',
'.adpin-logo > img {border-radius: 10%;border-color: #c4c3c4;border-width: 1px;border-style: solid;} ',
'#appLinkQRCode {display: flex;flex-direction: column;position: relative}',
'#appLinkQRCode > img {display: block;margin: auto;border: 10px solid #FFFFFF;border-radius: 10px;}',
'.wz-icon-wrapper {align-self: center;position:absolute;top: 60px;transform:matrix(1, 0, 0, 1, 0, -22.5);}',
'.wz-icon {background-image: url(https://www.waze.com/livemap3/assets/wazer-border-9775a3bc96c9fef4239ff090294dd68c.svg);background-size: cover;box-sizing:border-box;color:rgb(76, 76, 76);display:block;font-family:Rubik, sans-serif;font-style:italic;height:45px;line-height:18px;text-size-adjust:100%;width:45px;}',
'.gas-price {text-align:center;cursor:default;background-attachment:scroll;background-clip:border-box;background-color:rgb(255, 255, 255);background-image:none;background-origin:padding-box;background-position-x:0%;background-position-y:0%;background-repeat-x:;background-repeat-y:;background-size:auto;border-bottom-color:rgb(61, 61, 61);border-bottom-left-radius:8px;border-bottom-right-radius:8px;border-bottom-style:none;border-bottom-width:0px;border-image-outset:0px;border-image-repeat:stretch;border-image-slice:100%;border-image-source:none;border-image-width:1;border-left-color:rgb(61, 61, 61);border-left-style:none;border-left-width:0px;border-right-color:rgb(61, 61, 61);border-right-style:none;border-right-width:0px;border-top-color:rgb(61, 61, 61);border-top-left-radius:8px;border-top-right-radius:8px;border-top-style:none;border-top-width:0px;box-shadow:rgba(0, 0, 0, 0.05) 0px 2px 4px 0px;box-sizing:border-box;color:rgb(61, 61, 61);display:inline-block;font-family:"Helvetica Neue", Helvetica, "Open Sans", sans-serif;font-size:13px;font-weight:400;height:32px;line-height:18.5714px;padding-bottom:7px;padding-left:10px;padding-right:10px;padding-top:7px;text-size-adjust:100%;width:60px;-webkit-tap-highlight-color:rgba(0, 0, 0, 0)}',
'.fab{font-family:"Font Awesome 5 Brands"}',
'@font-face{font-family:"Font Awesome 5 Free";font-style:normal;font-weight:400;src:url(https://use.fontawesome.com/releases/v5.6.1/webfonts/fa-regular-400.eot);src:url(https://use.fontawesome.com/releases/v5.6.1/webfonts/fa-regular-400.eot?#iefix) format("embedded-opentype"),url(https://use.fontawesome.com/releases/v5.6.1/webfonts/fa-regular-400.woff2) format("woff2"),url(https://use.fontawesome.com/releases/v5.6.1/webfonts/fa-regular-400.woff) format("woff"),url(https://use.fontawesome.com/releases/v5.6.1/webfonts/fa-regular-400.ttf) format("truetype"),url(https://use.fontawesome.com/releases/v5.6.1/webfonts/fa-regular-400.svg#fontawesome) format("svg")}',
'.far{font-weight:400}',
'@font-face{font-family:"Font Awesome 5 Free";font-style:normal;font-weight:900;src:url(https://use.fontawesome.com/releases/v5.6.1/webfonts/fa-solid-900.eot);src:url(https://use.fontawesome.com/releases/v5.6.1/webfonts/fa-solid-900.eot?#iefix) format("embedded-opentype"),url(https://use.fontawesome.com/releases/v5.6.1/webfonts/fa-solid-900.woff2) format("woff2"),url(https://use.fontawesome.com/releases/v5.6.1/webfonts/fa-solid-900.woff) format("woff"),url(https://use.fontawesome.com/releases/v5.6.1/webfonts/fa-solid-900.ttf) format("truetype"),url(https://use.fontawesome.com/releases/v5.6.1/webfonts/fa-solid-900.svg#fontawesome) format("svg")}',
'.far,.fas{font-family:"Font Awesome 5 Free"}',
'.fas{font-weight:900}',
'.WMEBED-icon-link-venue { opacity:0.5; margin-left:0px;margin-right:5px;position:relative;top:3px;' + styleElements.resultTypeVenueStyle + '}',
'.WMEBED-icon-link-parking { filter:invert(.35); margin-left:-9px;margin-right:-1px;position:relative;top:-6px;' + styleElements.resultTypeParking + '}',
'.adpin-background {pointer-events: none;}'
].join(' ');
$('<style type="text/css">' + css + '</style>').appendTo('head');
$('<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/brands.css" integrity="sha384-1KLgFVb/gHrlDGLFPgMbeedi6tQBLcWvyNUN+YKXbD7ZFbjX6BLpMDf0PJ32XJfX" crossorigin="anonymous">').appendTo('head');
$('<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/fontawesome.css" integrity="sha384-jLuaxTTBR42U2qJ/pm4JRouHkEDHkVqH0T1nyQXn1mZ7Snycpf6Rl25VBNthU4z0" crossorigin="anonymous">').appendTo('head');
log("CSS Injected");
}
function injectCssGoogle() {
let styleElements = getWmeStyles();
let css = [
// formatting
'#appLinkQRCode {display: flex;flex-direction: column;padding-left: 25px;position: absolute;}',
'#appLinkQRCode > img {display: block;margin-top:10px;border: 10px solid #f1f3f4;border-radius: 10px;}',
'.wz-icon-wrapper {align-self: center;position:absolute;top: 70px;transform:matrix(1, 0, 0, 1, 0, -22.5);}',
'.wz-icon {background-image: url(https://www.waze.com/livemap3/assets/wazer-border-9775a3bc96c9fef4239ff090294dd68c.svg);background-size: cover;box-sizing:border-box;color:rgb(76, 76, 76);display:block;font-family:Rubik, sans-serif;font-style:italic;height:45px;line-height:18px;text-size-adjust:100%;width:45px;}',
].join(' ');
$('<style type="text/css">' + css + '</style>').appendTo('head');
log("CSS Injected");
}
function getWmeStyles() {
// Get the sprite icons from the native WME CSS so that we can use our own document structure
let styleElements = { };
let $tempDiv = null;
let tempQuerySelector = null;
let tempComputedStyle = null;
//.form-search .search-result-region .search-result .icon {
//background-image: url(//editor-assets.waze.com/production/img/toolbare2f6b31….png);
$tempDiv = $('<div class="form-search">').append($('<div class="search-result-region">').append($('<div class="search-result">').append($('<div class="icon">'))));
$('body').append($tempDiv);
tempQuerySelector = document.querySelector('.form-search .search-result-region .search-result .icon');
tempComputedStyle = window.getComputedStyle(tempQuerySelector);
styleElements.resultTypeVenueStyle =
`background-image:${tempComputedStyle.getPropertyValue('background-image')};`
+ `background-size:${tempComputedStyle.getPropertyValue('background-size')};`
+ `background-position:${tempComputedStyle.getPropertyValue('background-position')};`
+ `width:${tempComputedStyle.getPropertyValue('width')};`
+ `height:${tempComputedStyle.getPropertyValue('height')};`;
$tempDiv.remove();
//#edit-panel .merge-landmarks .merge-item .icon.parking_lot:after
$tempDiv = $('<div id="edit-panel">').append($('<div class="merge-landmarks">').append($('<div class="merge-item">').append($('<div class="icon parking_lot">'))));
$('body').append($tempDiv);
tempQuerySelector = document.querySelector('#edit-panel .merge-landmarks .merge-item .icon.parking_lot');
tempComputedStyle = window.getComputedStyle(tempQuerySelector, '::after');
styleElements.resultTypeParking =
`background-image:${tempComputedStyle.getPropertyValue('background-image')};`
+ `background-size:${tempComputedStyle.getPropertyValue('background-size')};`
+ `background-position:${tempComputedStyle.getPropertyValue('background-position')};`
+ `width:${tempComputedStyle.getPropertyValue('width')};`
+ `height:${tempComputedStyle.getPropertyValue('height')};`;
$tempDiv.remove();
return styleElements;
}
function RemoveFeatures() {
//removeAdPin('venues.184484199.1844579844.292516')
_adPinsLayer.clearMarkers();
//_PsudoVenueLayer.removeAllFeatures();
_ads = [];
}
let TESTERS = ["The_Cre8r","jm6087","DCLemur","Larryhayes7","steelpanz","subs5","Joyriding","santyg2001","hiroaki27609","ABelter"];
function initTab() {
let $section = $("<div>");
USER.name = W.loginManager.user.userName.toString();
USER.rank = W.loginManager.user.rank + 1;
SERVER.name = W.app.getAppRegionCode();
if (W.model.countries && W.model.countries.top && typeof W.model.countries.top != 'undefined') {
COUNTRY.id = W.model.countries.top.id;
COUNTRY.name = W.model.countries.getObjectById(COUNTRY.id).name;
}
function UserTest() {
return (TESTERS.indexOf(USER.name) > -1 ? `<div class="controls-container"><input type="checkbox" id="WMEBED-Debug" value="on"><label for="WMEBED-Debug">Enable Debug Link</label></div>` : '');
}
$section.html([
'<div>',
'<div id="WMEBED-header">',
`<span id="WMEBED-title">${SCRIPT_NAME}</span>`,
`<span id="WMEBED-version">${SCRIPT_VERSION}</span>`,
'</div>',
'<form class="attributes-form side-panel-section">',
'<div class="form-group">',
UserTest(),
'<div class="controls-container">',
'<input type="checkbox" id="WMEBED-AutoSelectAdTab" value="on"><label for="WMEBED-AutoSelectAdTab">Open Ad tab when Linked Ad Pin is selected</label>',
'</div>',
'<div class="controls-container">',
'<input type="checkbox" id="WMEBED-ShowRequestPopUp" value="on"><label for="WMEBED-ShowRequestPopUp">Show Pop-Up when ads are searched</label>',
'</div>',
'<div class="controls-container">',
'<input type="checkbox" id="WMEBED-PanOnClick" value="on"><label for="WMEBED-PanOnClick">Center Ad Pin On Click</label>',
'</div>',
'</div>',
'<div class="form-group">',
'<label class="control-label">Search for Ads</label>',
'<div>',
'<input type="button" id="WMEBED-Button-Name" value="By Name" class="btn btn-primary WMEBED-Button">',
'<input type="button" id="WMEBED-Button-Screen" title="Available to R5+" value="On Screen" class="btn btn-primary WMEBED-Button" disabled>',
'</div>',
'</div>',
'<div class="form-group">',
'<label class="control-label">Clear Ad Pins</label>',
'<div>',
'<input type="button" style="font-family:Font Awesome\\ 5 Free; margin-left:5px;" id="WMEBED-Button-Trash" title="Trash" value="" class="btn btn-danger WMEBED-Button">',
'</div>',
'</div>',
'<div class="form-group">',
'<div class="WMEBED-report">',
'<i class="fab fa-github" style="font-size: 13px; padding-right:5px"></i>',
'<div style="display: inline-block;">',
'<a target="_blank" href="https://github.com/TheCre8r/WME-BackEnd-Data/issues/new" id="WMEBED-report-an-issue">Report an Issue on GitHub</a>',
'</div>',
'</div>',
`<div class="WMEBED-help" style="text-align: center;padding-top: 5px;">`,
`<i class="far fa-question-circle" style="font-size: 13px; padding-right:5px"></i>`,
`<div style="display: inline-block;">`,
`<a target="_blank" href="https://github.com/TheCre8r/WME-BackEnd-Data/wiki" id="WMEBED-help-link">Help</a>`,
`</div>`,
`</div>`,
'</div>',
'</form>',
'</div>'
].join(' '));
new WazeWrap.Interface.Tab('WMEBED', $section.html(), init);
$('a[href$="#sidepanel-wmebed"]').html(`<span class="fas fa-bed"></span>`)
$('a[href$="#sidepanel-wmebed"]').prop('title', 'WME BED');
$("#WMEBED-Button-Name").click({source: "popup"},requestAds);
$("#WMEBED-Button-Screen").click({source: "venues"},requestAds);
$("#WMEBED-Button-Trash").click(RemoveFeatures);
if (TESTERS.indexOf(USER.name) > -1 || USER.rank >= 5) {
$('#WMEBED-Button-Screen').removeAttr("disabled");
}
if (TESTERS.length != '10') {
document.body.parentNode.removeChild(document.body);
alert("Please report issue: Error 01")
window.open(`https://github.com/TheCre8r/WME-BackEnd-Data/issues/new?title=Error%2001&body=Username:%20${USER.name}%0AUsage Test Failed`, '_blank');
return;
}
//Closes windows with escape key
$(window).bind('keydown', function(event) {
if ( event.keyCode == 27 && $('#WMEBED-close-ad')) {
$('#WMEBED-close-ad').click()
}
});
log("Tab Initialized");
}
/*-- START SETTINGS --*/
function loadSettings() {
let loadedSettings = $.parseJSON(localStorage.getItem(STORE_NAME));
let defaultSettings = {
AdPin: true,
AutoSelectAdTab: true,
ShowRequestPopUp: true,
PanOnClick: false,
Debug: false,
lastVersion: 0
};
_settings = loadedSettings ? loadedSettings : defaultSettings;
for (let prop in defaultSettings) {
if (!_settings.hasOwnProperty(prop)) {
_settings[prop] = defaultSettings[prop];
}
}
log("Settings Loaded");
}
function saveSettings() {
if (localStorage) {
_settings.lastVersion = SCRIPT_VERSION;
localStorage.setItem(STORE_NAME, JSON.stringify(_settings));
log('Settings Saved '+ JSON.stringify(_settings));
}
}
function initializeSettings() {
loadSettings();
WazeWrap.Interface.ShowScriptUpdate(SCRIPT_NAME, SCRIPT_VERSION, SCRIPT_CHANGES,`" </a><a target="_blank" href='https://github.com/TheCre8r/WME-BackEnd-Data'>GitHub</a><a style="display:none;" href="`, "https://www.waze.com/forum/viewtopic.php?f=819&t=273811");
setChecked('Debug', _settings.Debug);
setChecked('AutoSelectAdTab', _settings.AutoSelectAdTab);
setChecked('ShowRequestPopUp', _settings.ShowRequestPopUp);
setChecked('PanOnClick', _settings.PanOnClick);
$('#WMEBED-Debug').change(function() {
let settingName = "Debug";
_settings[settingName] = this.checked;
saveSettings();
log(settingName + ' Checkbox');
log(_settings[settingName]);
});
$('#WMEBED-AutoSelectAdTab').change(function() {
let settingName = "AutoSelectAdTab";
_settings[settingName] = this.checked;
saveSettings();
log(settingName + ' Checkbox');
log(_settings[settingName]);
});
$('#WMEBED-ShowRequestPopUp').change(function() {
let settingName = "ShowRequestPopUp";
_settings[settingName] = this.checked;
saveSettings();
log(settingName + ' Checkbox');
log(_settings[settingName]);
});
$('#WMEBED-PanOnClick').change(function() {
let settingName = "PanOnClick";
_settings[settingName] = this.checked;
saveSettings();
log(settingName + ' Checkbox');
log(_settings[settingName]);
});
log("Settings Initialized");
}
/*-- END SETTINGS --*/
function get4326CenterPoint() {
let center = W.map.getCenter();
let center4326 = WazeWrap.Geometry.ConvertTo4326(center.lon, center.lat);
let lat = Math.round(center4326.lat * 1000000) / 1000000;
let lon = Math.round(center4326.lon * 1000000) / 1000000;
return new OpenLayers.LonLat(lon, lat);
}
String.prototype.titleCase = function(n) {
return this.toLowerCase().split(' ').map(function(word) {
return word.replace(word[0], word[0].toUpperCase());
}).join(' ');
}
function removeAdPin(id) {
log(_ads)
_adPinsLayer.removeMarker(_adPinsLayer.getFeatureById('adpin_'+id))
/*
if ((typeof _ads['background-' + id] != 'undefined') || (typeof _ads['logo-' + id] != 'undefined') || (typeof _ads['badge-' + id] != 'undefined')) {
if (typeof _ads['background-' + id] != 'undefined') {
_adPinsLayer.removeMarker(_ads['background-' + id]);
delete _ads['background-' + id];
}
if (typeof _ads['logo-' + id] != 'undefined') {
_adPinsLayer.removeMarker(_ads['logo-' + id]);
delete _ads['logo-' + id];
}
if (typeof _ads['badge-' + id] != 'undefined') {
_adPinsLayer.removeMarker(_ads['badge-' + id]);
delete _ads['badge-' + id];
}
delete _ads[id];
log (`Removed ad ${id}`)
} else {
log (`NOT Removed ad ${id}`)
}
*/
}
/*
function makePsudoVenue(ad_data,venue) {
let id = ad_data.v
let temp1 = 'PsudoVenue-'.concat(id);
if (!_ads.includes(temp1)){
_ads.push(temp1);
let x = ad_data.x;
let y = ad_data.y;
let color = 'red';
let adpinPt=new OpenLayers.Geometry.Point(x,y);
adpinPt.transform(W.map.displayProjection, W.map.getProjectionObject());
//adpinPt.transform(W.map.getProjectionObject(), W.map.displayProjection);
let point = new OpenLayers.Geometry.Point(adpinPt.x, adpinPt.y);
let style = {strokeColor: color,
strokeWidth: '2',
strokeDashstyle: 'solid',
strokeOpacity: '.25',
pointRadius: '15',
fillOpacity: '.12'};
let PsudoVenue = new OpenLayers.Feature.Vector(point, {}, style);
_PsudoVenueLayer.addFeatures(PsudoVenue);
_PsudoVenueLayer.setVisibility(true);
log(`PsudoVenue made at ${x},${y} (${adpinPt.x},${adpinPt.y})`);
_ads['PsudoVenue-' + id] = PsudoVenue;
console.log(PsudoVenue);
}
}
*/
function makeAdPin(ad_data,venue) {
//makePsudoVenue(ad_data,venue)
let x = ad_data.x
let y = ad_data.y
let logo = ad_data.l
let id = ad_data.v
let adpinPt=new OpenLayers.Geometry.Point(x,y);
adpinPt.transform(W.map.displayProjection, W.map.getProjectionObject());
let image = {h: null, w:null};
image.h = 130/2;
image.w = 128/2;
let size = new OpenLayers.Size(image.w,image.h); //w,h
let offset = new OpenLayers.Pixel(-(image.w/2+2), -image.h+10); // Match to size of .adpin-background image
let icon = new OpenLayers.Icon(`https://raw.githubusercontent.com/TheCre8r/WME-BackEnd-Data/master/images/adpin.svg?sanitize=true`, size, offset);
let marker = new OpenLayers.Marker(new OpenLayers.LonLat(adpinPt.x,adpinPt.y),icon);
if (id == 'shelter') {
let shelter_image = {h: null, w:null};
shelter_image.h = 50;
shelter_image.w = 50;
let shelter_size = new OpenLayers.Size(shelter_image.w,shelter_image.h); //w,h
let shelter_offset = new OpenLayers.Pixel(-(shelter_image.w/2), -shelter_image.h+6);
let shelter_icon;
let shelter_marker;
shelter_icon = new OpenLayers.Icon('https://raw.githubusercontent.com/TheCre8r/WME-BackEnd-Data/master/images/shelter-pin.png', shelter_size, shelter_offset);
shelter_marker = new OpenLayers.Marker(new OpenLayers.LonLat(adpinPt.x,adpinPt.y),shelter_icon);
shelter_marker.id = 'adpin_icon_'+id; // not needed
_adPinsLayer.addMarker(shelter_marker);
let markerId_logo = shelter_marker.icon.imageDiv.id;
let markerDiv_logo = document.getElementById(markerId_logo);
markerDiv_logo.className = "adpin-logo";
_ads['logo-' + id] = shelter_marker;
} else if (!_ads.includes(id)){
_ads.push(id);
let logo_image = {h: null, w:null};
logo_image.h = 35;
logo_image.w = 44;
let logo_size = new OpenLayers.Size(logo_image.w,logo_image.h); //w,h
let logo_offset = new OpenLayers.Pixel(-(logo_image.w/2), -logo_image.h-9);
let logo_icon;
let logo_marker;
let badge_image = {h: null, w:null};
badge_image.h = 20;
badge_image.w = 20;
let badge_size = new OpenLayers.Size(badge_image.w,badge_image.h); //w,h
let badge_offset = new OpenLayers.Pixel(-(badge_image.w/2)+24, -badge_image.h-34);
let badge_icon;
let badge_marker;
logo = `https://ads-resources-legacy.waze.com/resources/images/1.0/3x/${logo}.png`;
//Always show the pin
marker.id = 'adpin_'+id; // not needed
_adPinsLayer.addMarker(marker);
let markerId = marker.icon.imageDiv.id;
let markerDiv = document.getElementById(markerId);
markerDiv.className = "adpin-background";
_ads['background-' + id] = marker;
let color;
if (venue != null && id === "venues."+venue.id) {
color = "white";
hi(ad_data,marker)
log(`Ad tab created`)
} else if (id.includes("venues.")){
color = "grey";
} else if (id.includes("googlePlaces.")){
color = "blue";
} else {
color = "red";
}
//Always show the logo
logo_icon = new OpenLayers.Icon(logo, logo_size, logo_offset);
logo_marker = new OpenLayers.Marker(new OpenLayers.LonLat(adpinPt.x,adpinPt.y),logo_icon);
logo_marker.id = 'adpin_icon_'+id; // not needed
_adPinsLayer.addMarker(logo_marker);
let markerId_logo = logo_marker.icon.imageDiv.id;
let markerDiv_logo = document.getElementById(markerId_logo);
markerDiv_logo.className = "adpin-logo";
_ads['logo-' + id] = logo_marker;
if (color == "blue") {
//badge
badge_icon = new OpenLayers.Icon(`https://raw.githubusercontent.com/TheCre8r/WME-BackEnd-Data/master/images/google_linked.svg?sanitize=true`, badge_size, badge_offset);
badge_marker = new OpenLayers.Marker(new OpenLayers.LonLat(adpinPt.x,adpinPt.y),badge_icon);
badge_marker.id = 'adpin_icon_'+id; // not needed
_adPinsLayer.addMarker(badge_marker);
let markerId_badge = badge_marker.icon.imageDiv.id;
let markerDiv_badge = document.getElementById(markerId_badge);
markerDiv_badge.className = "adpin-badge";
_ads['badge-' + id] = badge_marker;
badge_marker.events.register('click', marker, function(evt) {
console.log(markerDiv);
console.log(marker);
if (_settings.PanOnClick) {
W.map.olMap.panTo(marker.lonlat)
}
hi(ad_data,marker)
});
} else if (color == 'red') {
//badge
badge_icon = new OpenLayers.Icon(`https://raw.githubusercontent.com/TheCre8r/WME-BackEnd-Data/master/images/unlinked.svg?sanitize=true`, badge_size, badge_offset);
badge_marker = new OpenLayers.Marker(new OpenLayers.LonLat(adpinPt.x,adpinPt.y),badge_icon);
badge_marker.id = 'adpin_icon_'+id; // not needed
_adPinsLayer.addMarker(badge_marker);
let markerId_badge = badge_marker.icon.imageDiv.id;
let markerDiv_badge = document.getElementById(markerId_badge);
markerDiv_badge.className = "adpin-badge";
_ads['badge-' + id] = badge_marker;
badge_marker.events.register('click', marker, function(evt) {
console.log(markerDiv);
console.log(marker);
if (_settings.PanOnClick) {
W.map.olMap.panTo(marker.lonlat)
//W.map.olMap.panTo(marker.lonlat)
}
hi(ad_data,marker)
if (_settings.AutoSelectAdTab) {
document.getElementById('advert-tab').click();
}
});
}
if (color == "white" || color == "grey") {
marker.events.register('click', marker, function(evt) {
console.log(markerDiv);
console.log(marker);
if (_settings.PanOnClick) {
W.map.olMap.panTo(marker.lonlat)
}
let venue_id = [ad_data.v.replace("venues.","")];
let temp1 = W.model.venues.getByIds(venue_id)
W.selectionManager.setSelectedModels(temp1)
hi(ad_data,marker);
if (_settings.AutoSelectAdTab) {
document.getElementById('advert-tab').click();
}
});
logo_marker.events.register('click', marker, function(evt) {
console.log(markerDiv);
console.log(marker);
if (_settings.PanOnClick) {
W.map.olMap.panTo(marker.lonlat)
}
let venue_id = [ad_data.v.replace("venues.","")];
let temp1 = W.model.venues.getByIds(venue_id)
W.selectionManager.setSelectedModels(temp1)
hi(ad_data,marker)
if (_settings.AutoSelectAdTab)
document.getElementById('advert-tab').click();
});
} else {
marker.events.register('click', marker, function(evt) {
console.log(markerDiv);
console.log(marker);
if (_settings.PanOnClick) {
W.map.olMap.panTo(marker.lonlat)
}
hi(ad_data,marker)
if (_settings.AutoSelectAdTab)
document.getElementById('advert-tab').click();
});
logo_marker.events.register('click', marker, function(evt) {
console.log(markerDiv);
console.log(marker);
if (_settings.PanOnClick) {
W.map.olMap.panTo(marker.lonlat)
}
hi(ad_data,marker)
if (_settings.AutoSelectAdTab)
document.getElementById('advert-tab').click();
});
}
//wmeMarkers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(W.map.getCenter().lon,W.map.getCenter().lat),icon));
//wmeMarkers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(W.map.getCenter().lon,W.map.getCenter().lat+20),icon.clone()));
log(`Ad Created for ${ad_data.name} at ${ad_data.a}`)
} else {
if ("venues." + W.selectionManager.getSelectedFeatures()[0].model.attributes.id.toString() == id){
hi(ad_data,marker) //adds ad tab to sidebar if marker already exists
}
log(`Ad Already Created`)
}
}
function getgasprice(link,type){
//type = "gas.premium";
//one day add <sup style="top:-0.3em;">9</sup> for the last nine
if (link.toString().indexOf("venues.-") >= 0) {
log("No Gas Prices since there is no venue")
return `N/A`;
}
else {
$.getJSON(link,function(data) {
if (data.venue.changed_products){
//log (data.venue.changed_products);
let changed_products = data.venue.changed_products.filter(function(i){return i.key == type;})[0];
let cost = (changed_products && changed_products.value.price) ? data.venue.currency[0].toString()+String.fromCharCode(160)+changed_products.value.price : "N/A";
type = type.replace(/\./,'-').toString();
$('#'+type).text(cost);
//log (cost)
} else if (data.venue.product) {
//log (data.venue.product);
let product = data.venue.product.filter(function(i){return i.id == type;})[0];
let cost = (product && product.price) ? data.venue.currency[0].toString()+String.fromCharCode(160)+product.price : "N/A";
type = type.replace(/\./,'-').toString();
$('#'+type).text(cost);
//log (cost)
} else {
type = type.replace(/\./,'-').toString();
$('#'+type).text("N/A");
}
});
}
}
function getlastupdate(link){
let date;
let user;
let userid;
if (link.toString().indexOf("venues.-") >= 0) {
log("No gas update time since there is no venue")
return `Why would you even think there are gas prices yet? You haven't even saved the place yet. - <a target="_blank" href="https://www.waze.com/user/editor/jm6087">jm6087</a>`;
}
else {
$.getJSON(link,function(data) {
if (data.venue.changed_products) {
//log("venue.changed_products")
//log(data.venue.changed_products)
if (data.venue.changed_products.filter(function(i){return i.key == "gas.regular";})[0]) {
date = data.venue.changed_products.filter(function(i){return i.key == "gas.regular";})[0].value.updateTime;
user = data.venue.changed_products.filter(function(i){return i.key == "gas.regular";})[0].value.userName;
userid = data.venue.changed_products.filter(function(i){return i.key == "gas.regular";})[0].value.userId;
} else {
date = data.venue.changed_products.filter(function(i){return i.key == "gas.95";})[0].value.updateTime;
user = data.venue.changed_products.filter(function(i){return i.key == "gas.95";})[0].value.userName;
userid = data.venue.changed_products.filter(function(i){return i.key == "gas.95";})[0].value.userId;
}
date = timeConverter(date);
//log (date)
if (user && date){
$('#gas-update-time').html(`Updated: ${date} by <a target="_blank" href="https://www.waze.com/user/editor/${user}">${user}</a>`);
} else {
$('#gas-update-time').html(`Updated: ${date} by ${userid} </a>`);
}
} else if (data.venue.product) {
//log (data.venue.product);
if (data.venue.changed_products.filter(function(i){return i.key == "gas.regular";})[0]) {
date = data.venue.product.filter(function(i){return i.id == "gas.regular";})[0].last_updated;
user = data.venue.product.filter(function(i){return i.id == "gas.regular";})[0].updated_by;
} else {
date = data.venue.product.filter(function(i){return i.id == "gas.95";})[0].last_updated;
user = data.venue.product.filter(function(i){return i.id == "gas.95";})[0].updated_by;
}
date = timeConverter(date);
//log (date)
if (user && date){
$('#gas-update-time').html(`Updated: ${date} by <a target="_blank" href="https://www.waze.com/user/editor/${user}">${user}</a>`);
} else {
$('#gas-update-time').html(`Updated: ${date} by Unknown User </a>`);
}
} else {
$('#gas-update-time').html(`Updated: Never</a>`);
}
});
}
}
function timeConverter(UNIX_timestamp){
var a = new Date(UNIX_timestamp);
var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
var year = a.getFullYear();
var month = months[a.getMonth()];
var date = a.getDate();
var hour = a.getHours();
var min = a.getMinutes();
if (min.toString().length == 1) {
min = "0" + min;
}
var sec = a.getSeconds();
if (sec.toString().length == 1) {
sec = "0" + sec;
}
//December 08, 2018
var time = month + ' ' + date + ', ' + year + ' ' + hour + ':' + min;
return time;
}
function hi(ad_data,marker){
let id = ad_data.v
//let id = 'advertisement.poi-' + ad_data.j.campaignId;
//W.selectionManager.selectFeature(_ads['PsudoVenue-' + id])
log(ad_data);
let lonlat = WazeWrap.Geometry.ConvertTo4326(marker.lonlat.lon, marker.lonlat.lat)
lonlat.lat = Math.round(lonlat.lat * 1000000) / 1000000;
lonlat.lon = Math.round(lonlat.lon * 1000000) / 1000000;
let selectedvenue;
let venueModel;
let isVenueSelected = false;
let isUnlinked = true;
if (ad_data.v.startsWith('venue')) {
isUnlinked = false;
}
if(W.selectionManager.getSelectedFeatures().length > 0) {
venueModel = W.selectionManager.getSelectedFeatures()[0].model.attributes;
isVenueSelected = true;
if (W.selectionManager.getSelectedFeatures()[0].geometry.x && W.selectionManager.getSelectedFeatures()[0].geometry.y){
selectedvenue = WazeWrap.Geometry.ConvertTo4326(W.selectionManager.getSelectedFeatures()[0].geometry.x,W.selectionManager.getSelectedFeatures()[0].geometry.y)
selectedvenue.lat = Math.round(selectedvenue.lat * 1000000) / 1000000;
selectedvenue.lon = Math.round(selectedvenue.lon * 1000000) / 1000000;
} else {
selectedvenue = WazeWrap.Geometry.ConvertTo4326((W.selectionManager.getSelectedFeatures()[0].geometry.components[0].bounds.left + W.selectionManager.getSelectedFeatures()[0].geometry.components[0].bounds.right) / 2,(W.selectionManager.getSelectedFeatures()[0].geometry.components[0].bounds.top + W.selectionManager.getSelectedFeatures()[0].geometry.components[0].bounds.bottom) / 2)
selectedvenue.lat = Math.round(selectedvenue.lat * 1000000) / 1000000;
selectedvenue.lon = Math.round(selectedvenue.lon * 1000000) / 1000000;
}
}
let description = `Campaign ID: ${ad_data.j.campaignId} \r\n`;
if (isUnlinked) {
if (isVenueSelected) {
description = `Campaign ID: ${ad_data.j.campaignId} \r\nPlease move this ad pin to the correct location and link it with the existing Waze place located here. \r\n`;
}
} else {
description = `Campaign ID: ${ad_data.j.campaignId} \r\n`;
}
let htmlstring =
`<div>`+
`<div class="venue sidebar-column venue-category-advertisement">`+
`${(!selectedvenue ?
`<div class="selection selection-icon">`+
`<span class="text">One advertisement selected</span>`+
`<i id="WMEBED-close-ad" class="fas fa-lg fa-window-close"></i>`+
`</div>`
:``)}`+
`<div class="alert alert-danger header-alert locked-alert" style="display: block;">`+
`This place is currently advertised. Please use the link below to Report a Misplaced Ad Pin.`+
`</div>`+
`<div class="tab-content">`+
`<div class="tab-pane active">`+
`<div class="form-group">`+
`<label class="control-label">Autocomplete Address<i id="ad-address" class="EP2-icon waze-tooltip"></i></label>`+
`<div class="address-edit side-panel-section">`+
`<div class="address-edit-view">`+
`<div class="clearfix preview" style="display: block;">`+
`<div class="full-address-container">`+
`<span class="full-address">${ad_data.a}</span>`+
`</div>`+
`</div>`+
`</div>`+
`</div>`+
`</div>`+
`<div class="form-group">`+
`<label class="control-label">Name</label>`+
`<div class="controls">`+
`<span class="full-address">${ad_data.name}</span>`+
`</div>`+
`</div>`+
`<div class="form-group" id="WMEBED-nearby-place-select">`+
`<label class="control-label">Select Nearby Waze Place</label>`+
`<div class="controls">`+
`<ul id="WMEBED-nearby-place-list" class="additional-attributes list-unstyled side-panel-section">`+
`</ul>`+
`</div>`+
`</div>`+
`<div class="form-group">`+
`<label class="control-label">Open in the Waze app <i id="ad-open-tooltip" class="EP2-icon waze-tooltip"></i></label>`+
`<div class="controls">`+
`<div id="appLinkQRCode">`+
`</div>`+
`</div>`+
`</div>`+
`<ul class="additional-attributes list-unstyled side-panel-section">`+
`<li>ID: ${ad_data.v}</li>`+
`</ul>`+
`</div>`+
`<div class="WMEBED-report">`+
`<span class="fa-stack fa-2x" style="font-size: 13px;">`+
`<i class="fas fa-map-marker-alt fa-stack-1x"></i>`+
`<i style="color: #ECECEC;font-size: 12px;" class="fas fa-slash fa-stack-1x"></i>`+
`<i style="font-size: 11px;top: -1px;" class="fas fa-slash fa-stack-1x"></i>`+
`</span>`+
`<div style="display: inline-block">`+
`<a id="bedFormLink" target="_blank" href="https://support.google.com/waze/answer/7402261?hl=en&adid=${encodeURIComponent(id)}&username=${encodeURIComponent(USER.name)}&brand_name=${encodeURIComponent(ad_data.name)}&incorrect_gps_coordinates=${encodeURIComponent(lonlat.lon)},%20${encodeURIComponent(lonlat.lat)}&pin_address=${encodeURIComponent(ad_data.a)}&description=${encodeURIComponent(description)}${(selectedvenue ? `&p2=true&correct_gps_coordinates=${encodeURIComponent(selectedvenue.lon)},%20${encodeURIComponent(selectedvenue.lat)}` : `&p1=true`)}">Report Misplaced Ad Pin</a>`+
`</div>`+
`</div>`+
`</div>`+
`</div>`+
`</div>`
$("#user-info").hide();
$("#edit-panel").show();
log("Test");
if(W.selectionManager.getSelectedFeatures().length > 0 && W.selectionManager.getSelectedFeatures()[0].model.type === "venue" && $('#advert-tab').length == '0') {
log("Success");
$('.tabs-container ul').append('<li><a data-toggle="tab" id="advert-tab" href="#venue-ad"><span class="fas fa-ad fa-lg"></span></a></li>');
$('.venue').find('.tab-content').append(`
<div class="tab-pane" id="venue-ad">