This repository has been archived by the owner on Feb 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathopr_tools_cn.user.js
2662 lines (2422 loc) · 141 KB
/
opr_tools_cn.user.js
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 OPR tools CN
// @version 2.0.0
// @description Add links to maps, rate on common objects, and other small improvements
// @author CubicPill
// @match https://opr.ingress.com/*
// @grant unsafeWindow
// @grant GM_notification
// @grant GM_addStyle
// @homepageURL https://github.com/CubicPill/OPR-tools-CN
// @downloadURL https://raw.githubusercontent.com/CubicPill/OPR-tools-CN/master/opr_tools_cn.user.js
// @updateURL https://raw.githubusercontent.com/CubicPill/OPR-tools-CN/master/opr_tools_cn.user.js
// @require https://raw.githubusercontent.com/wandergis/coordtransform/master/index.js
// @require https://cdn.rawgit.com/alertifyjs/alertify.js/v1.0.10/dist/js/alertify.js
// @require https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.4.4/proj4.js
// ==/UserScript==
// original author 1110101, https://gitlab.com/1110101/opr-tools/graphs/master
// original source https://gitlab.com/1110101/opr-tools
// merge-requests welcome
/*
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
const STRINGS_EN = {
baidu: "Baidu",
tencent: "Tencent",
amap: "Amap",
bdstreetview: "Baidu StreetView",
photo: "Bad Photo",
private: "Private Area",
school: "School",
face: "Face",
temporary: "Temporary",
location: "Location",
agent: "Name In Title",
apartment: "Apartment Sign",
cemetery: "Cemetery",
street_sign: "City/Street Sign",
fire_dept: "Fire Department",
hospital: "Hospital",
hotel: "Hotel/Inn",
exercise: "Exercise Equipment",
post: "Post Office",
survey_marker: "Survey Marker",
water_tower: "Water Tower",
fountain: "Fountain",
gazebo: "Gazebo",
mt_marker: "Mountain Top Marker",
playground: "Playground",
ruin: "Ruins",
trail_mk: "Trail Marker",
percent_processed: "Percent Processed",
next_badge_tier: "Next badge tier",
new_preset_name: "New preset name:",
preset: "Preset",
created_preset: "✔ Created preset",
delete_preset: "Deleted preset",
applied_preset: "✔ Applied",
preset_tooltip: "(OPR-Tools) Create your own presets for stuff like churches, playgrounds or crosses'.\nHowto: Answer every question you want included and click on the +Button.\n\nTo delete a preset shift-click it.",
expired: "EXPIRED",
};
const STRINGS_CN = {
baidu: "百度地图",
tencent: "腾讯地图",
amap: "高德地图",
bdstreetview: "百度街景",
photo: "低质量图片",
private: "封闭区域",
school: "中小学",
face: "人脸",
temporary: "临时景观",
location: "位置不准确",
agent: "标题包含 Codename",
apartment: "小区招牌",
cemetery: "墓园",
street_sign: "路牌",
fire_dept: "消防局",
hospital: "医院",
hotel: "酒店",
exercise: "健身器材",
post: "邮局",
survey_marker: "测量地标",
water_tower: "水塔",
fountain: "喷泉",
gazebo: "亭子",
mt_marker: "山顶标记",
playground: "运动场",
ruin: "遗址",
trail_mk: "步道路标",
percent_processed: "已处理的百分比",
next_badge_tier: "下一等级牌子",
preset: "预设评分",
new_preset_name: "新预设评分名称:",
created_preset: "✔ 创建预设",
delete_preset: "删除预设",
applied_preset: "✔ 使用预设",
preset_tooltip: "(OPR-Tools) 为长椅、操场等物品建立自己的预设评分.\n使用方法: 对所有希望包括的评分项评分,然后点击 + 按钮.\n\n删除预设请按住 Shift 键然后点击。",
expired: "已过期",
};
let STRINGS = STRINGS_CN;
if (navigator.language.search('en'))
STRINGS = STRINGS_EN;
STRINGS = STRINGS_CN;
const OPRT = {
SCANNER_OFFSET: "oprt_scanner_offset",
REFRESH: "oprt_refresh",
FROM_REFRESH: "oprt_from_refresh",
REFRESH_NOTI_SOUND: "oprt_refresh_noti_sound",
REFRESH_NOTI_DESKTOP: "oprt_refresh_noti_desktop",
MAP_TYPE: "oprt_map_type",
};
// polyfill for ViolentMonkey
if (typeof exportFunction !== "function") {
exportFunction = (func, scope, options) => {
if (options && options.defineAs) {
scope[options.defineAs] = func;
}
return func;
};
}
if (typeof cloneInto !== "function") {
cloneInto = obj => obj;
}
function addGlobalStyle(css) {
GM_addStyle(css);
addGlobalStyle = () => {
}; // noop after first run
}
function init() {
const w = typeof unsafeWindow == "undefined" ? window : unsafeWindow;
let tryNumber = 15;
let oprt_customPresets;
let browserLocale = window.navigator.languages[0] || window.navigator.language || "en";
const initWatcher = setInterval(() => {
if (tryNumber === 0) {
clearInterval(initWatcher);
w.document.getElementById("NewSubmissionController")
.insertAdjacentHTML("afterBegin", `
<div class='alert alert-danger'><strong><span class='glyphicon glyphicon-remove'></span> OPR-Tools initialization failed, refresh page</strong></div>
`);
addRefreshContainer();
return;
}
if (w.angular) {
let err = false;
try {
initAngular();
}
catch (error) {
err = error;
// console.log(error);
}
if (!err) {
try {
initScript();
clearInterval(initWatcher);
} catch (error) {
console.log(error);
if (error === 41) {
addRefreshContainer();
}
if (error !== 42) {
clearInterval(initWatcher);
}
}
}
}
tryNumber--;
}, 1000);
function initAngular() {
const el = w.document.querySelector("[ng-app='portalApp']");
w.$app = w.angular.element(el);
w.$injector = w.$app.injector();
w.inject = w.$injector.invoke;
w.$rootScope = w.$app.scope();
w.getService = function getService(serviceName) {
w.inject([serviceName, function (s) {
w[serviceName] = s;
}]);
};
w.$scope = element => w.angular.element(element).scope();
}
function initScript() {
const subMissionDiv = w.document.getElementById("NewSubmissionController");
const subController = w.$scope(subMissionDiv).subCtrl;
const newPortalData = subController.pageData;
const whatController = w.$scope(w.document.getElementById("WhatIsItController")).whatCtrl;
const answerDiv = w.document.getElementById("AnswersController");
const ansController = w.$scope(answerDiv).answerCtrl;
// adding CSS
addGlobalStyle(GLOBAL_CSS);
modifyHeader();
if (subController.errorMessage !== "") {
// no portal analysis data available
throw 41; // @todo better error code
}
if (typeof newPortalData === "undefined") {
// no submission data present
throw 42; // @todo better error code
}
// detect portal edit
if (subController.reviewType === "NEW") {
modifyNewPage(ansController, subController, whatController, newPortalData);
} else if (subController.reviewType === "EDIT") {
modifyEditPage(ansController, subController, newPortalData);
}
checkIfAutorefresh();
startExpirationTimer(subController);
}
function modifyNewPage(ansController, subController, whatController, newPortalData) {
mapButtons(newPortalData, w.document.getElementById("descriptionDiv"), "beforeEnd");
let newSubmitDiv = moveSubmitButton();
let {submitButton, submitAndNext} = quickSubmitButton(newSubmitDiv, ansController);
textButtons();
const customPresetUI = `
<div class="row" id="presets"><div class="col-xs-12">
<div>` + STRINGS.preset + ` <button class="button btn btn-default btn-xs" id="addPreset">+</button></div>
<div class='btn-group' id="customPresets"></div>
</div></div>`;
w.document.querySelector("form[name='answers'] div.row").insertAdjacentHTML("afterend", customPresetUI);
addCustomPresetButtons();
// we have to inject the tooltip to angular
w.$injector.invoke(cloneInto(["$compile", ($compile) => {
let compiledSubmit = $compile(`<span class="glyphicon glyphicon-info-sign darkgray" uib-tooltip-trigger="outsideclick" uib-tooltip-placement="left" tooltip-class="goldBorder" uib-tooltip="` + STRINGS.preset_tooltip + `"></span> `)(w.$scope(document.getElementById("descriptionDiv")));
w.document.getElementById("addPreset").insertAdjacentElement("beforebegin", compiledSubmit[0]);
}], w, {cloneFunctions: true}));
// click listener for +preset button
w.document.getElementById("addPreset").addEventListener("click", exportFunction(event => {
alertify.okBtn("Save").prompt(STRINGS.new_preset_name,
(value, event) => {
event.preventDefault();
if (value == "undefined" || value == "") {
return;
}
saveCustomPreset(value, ansController, whatController);
alertify.success(STRINGS.created_preset + ` <i>${value}</i>`);
addCustomPresetButtons();
}, event => {
event.preventDefault();
}
);
}), w, false);
let clickListener = exportFunction(event => {
const source = event.target || event.srcElement;
let value = source.id;
if (value === "" || event.target.nodeName !== "BUTTON") {
return;
}
let preset = oprt_customPresets.find(item => item.uid === value);
if (event.shiftKey) {
alertify.log(STRINGS.delete_preset + ` <i>${preset.label}</i>`);
w.document.getElementById(preset.uid).remove();
deleteCustomPreset(preset);
return;
}
ansController.formData.quality = preset.quality;
ansController.formData.description = preset.description;
ansController.formData.cultural = preset.cultural;
ansController.formData.uniqueness = preset.uniqueness;
ansController.formData.location = preset.location;
ansController.formData.safety = preset.safety;
// the controller's set by ID function doesn't work
// and autocomplete breaks if there are any spaces
// so set the field to the first word from name and match autocomplete by ID
// at the very least, I know this will set it and leave the UI looking like it was manually set.
whatController.whatInput = preset.nodeName.split(" ")[0];
let nodes = whatController.getWhatAutocomplete();
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].id == preset.nodeId) {
whatController.whatNode = nodes[i];
break;
}
}
whatController.whatInput = "";
// update ui
event.target.blur();
w.$rootScope.$apply();
alertify.success(STRINGS.applied_preset + ` <i>${preset.label}</i>`);
}, w);
w.document.getElementById("customPresets").addEventListener("click", clickListener, false);
// make photo filmstrip scrollable
const filmstrip = w.document.getElementById("map-filmstrip");
let lastScrollLeft = filmstrip.scrollLeft;
function scrollHorizontally(e) {
e = window.event || e;
if (("deltaY" in e && e.deltaY !== 0 || "wheelDeltaY" in e && e.wheelDeltaY !== 0) && lastScrollLeft === filmstrip.scrollLeft) {
e.preventDefault();
const delta = (e.wheelDeltaY || -e.deltaY * 25 || -e.detail);
filmstrip.scrollLeft -= (delta);
lastScrollLeft = filmstrip.scrollLeft;
}
}
filmstrip.addEventListener("wheel", exportFunction(scrollHorizontally, w), false);
filmstrip.addEventListener("DOMMouseScroll", exportFunction(scrollHorizontally, w), false);
// hotfix for #27 not sure if it works
let _initMap = subController.initMap;
subController.initMap = exportFunction(() => {
_initMap();
mapMarker(subController.markers);
});
mapOriginCircle(subController.map2);
mapMarker(subController.markers);
mapTypes(subController.map, false);
mapTypes(subController.map2, true);
// hook resetStreetView() and re-apply map types and options to first map. not needed for duplicates because resetMap() just resets the position
let _resetStreetView = subController.resetStreetView;
subController.resetStreetView = exportFunction(() => {
_resetStreetView();
mapOriginCircle(subController.map2)
mapTypes(subController.map2, true);
}, w);
// adding a green 40m circle around the new location marker that updates on dragEnd
let draggableMarkerCircle;
let _showDraggableMarker = subController.showDraggableMarker;
subController.showDraggableMarker = exportFunction(() => {
_showDraggableMarker();
w.getService("NewSubmissionDataService");
let newLocMarker = w.NewSubmissionDataService.getNewLocationMarker();
google.maps.event.addListener(newLocMarker, "dragend", function () {
if (draggableMarkerCircle == null)
draggableMarkerCircle = new google.maps.Circle({
map: subController.map2,
center: newLocMarker.position,
radius: 40,
strokeColor: "#4CAF50", // material green 500
strokeOpacity: 1,
strokeWeight: 2,
fillOpacity: 0,
});
else draggableMarkerCircle.setCenter(newLocMarker.position);
});
});
document.querySelector("#street-view + small").insertAdjacentHTML("beforeBegin", "<small class='pull-left'><span style='color:#ebbc4a'>Circle:</span> 40m</small>");
// move portal rating to the right side. don't move on mobile devices / small width
if (screen.availWidth > 768) {
const scorePanel = w.document.querySelector("div[class~='pull-right']");
let nodeToMove = w.document.querySelector("div[class='btn-group']").parentElement;
scorePanel.insertBefore(nodeToMove, scorePanel.firstChild);
}
// bind click-event to Dup-Images-Filmstrip. result: a click to the detail-image the large version is loaded in another tab
const imgDups = w.document.querySelectorAll("#map-filmstrip > ul > li > img");
const openFullImage = function () {
w.open(`${this.src}=s0`, "fulldupimage");
};
for (let imgSep in imgDups) {
if (imgDups.hasOwnProperty(imgSep)) {
imgDups[imgSep].addEventListener("click", () => {
const imgDup = w.document.querySelector("#content > img");
if (imgDup !== null) {
imgDup.removeEventListener("click", openFullImage);
imgDup.addEventListener("click", openFullImage);
imgDup.setAttribute("style", "cursor: pointer;");
}
});
}
}
// add translate buttons to title and description (if existing)
let lang = "en";
try {
lang = browserLocale.split("-")[0];
} catch (e) {
}
const link = w.document.querySelector("#descriptionDiv a");
const content = link.innerText.trim();
let a = w.document.createElement("a");
let span = w.document.createElement("span");
span.className = "glyphicon glyphicon-book";
span.innerHTML = " ";
a.appendChild(span);
a.className = "translate-title button btn btn-default pull-right";
a.target = "translate";
a.style.padding = "0px 4px";
a.href = `https://translate.google.com/#auto/${lang}/${encodeURIComponent(content)}`;
link.insertAdjacentElement("afterend", a);
const description = w.document.querySelector("#descriptionDiv").innerHTML.split("<br>")[3].trim();
if (description !== "<No description>" && description !== "") {
a = w.document.createElement("a");
span = w.document.createElement("span");
span.className = "glyphicon glyphicon-book";
span.innerHTML = " ";
a.appendChild(span);
a.className = "translate-description button btn btn-default pull-right";
a.target = "translate";
a.style.padding = "0px 4px";
a.href = `https://translate.google.com/#auto/${lang}/${encodeURIComponent(description)}`;
const br = w.document.querySelectorAll("#descriptionDiv br")[2];
br.insertAdjacentElement("afterend", a);
}
// automatically open the first listed possible duplicate
try {
const e = w.document.querySelector("#map-filmstrip > ul > li:nth-child(1) > img");
if (e !== null) {
setTimeout(() => {
e.click();
}, 500);
}
} catch (err) {
}
expandWhatIsItBox();
// keyboard navigation
// keys 1-5 to vote
// space/enter to confirm dialogs
// esc or numpad "/" to reset selector
// Numpad + - to navigate
let currentSelectable = 0;
let maxItems = 7;
// a list of all 6 star button rows, and the two submit buttons
let starsAndSubmitButtons = w.document.querySelectorAll(".col-sm-6 .btn-group, .col-sm-4.hidden-xs .btn-group, .big-submit-button");
function highlight() {
starsAndSubmitButtons.forEach(exportFunction((element) => {
element.style.border = "none";
}, w));
if (currentSelectable <= maxItems - 2) {
starsAndSubmitButtons[currentSelectable].style.border = cloneInto("1px dashed #ebbc4a", w);
submitAndNext.blur();
submitButton.blur();
} else if (currentSelectable == 6) {
submitAndNext.focus();
}
else if (currentSelectable == 7) {
submitButton.focus();
}
}
addEventListener("keydown", (event) => {
/*
keycodes:
8: Backspace
9: TAB
13: Enter
16: Shift
27: Escape
32: Space
68: D
107: NUMPAD +
109: NUMPAD -
111: NUMPAD /
49 - 53: Keys 1-5
97 - 101: NUMPAD 1-5
*/
if (event.keyCode >= 49 && event.keyCode <= 53)
numkey = event.keyCode - 48;
else if (event.keyCode >= 97 && event.keyCode <= 101)
numkey = event.keyCode - 96;
else
numkey = null;
// do not do anything if a text area or a input with type text has focus
if (w.document.querySelector("input[type=text]:focus") || w.document.querySelector("textarea:focus")) {
return;
}
// "analyze next" button
else if ((event.keyCode === 13 || event.keyCode === 32) && w.document.querySelector("a.button[href=\"/recon\"]")) {
w.document.location.href = "/recon";
event.preventDefault();
} // submit low quality rating
else if ((event.keyCode === 13 || event.keyCode === 32) && w.document.querySelector("[ng-click=\"answerCtrl2.confirmLowQuality()\"]")) {
w.document.querySelector("[ng-click=\"answerCtrl2.confirmLowQuality()\"]").click();
currentSelectable = 0;
event.preventDefault();
} // submit low quality rating alternate
else if ((event.keyCode === 13 || event.keyCode === 32) && w.document.querySelector("[ng-click=\"answerCtrl2.confirmLowQualityOld()\"]")) {
w.document.querySelector("[ng-click=\"answerCtrl2.confirmLowQualityOld()\"]").click();
currentSelectable = 0;
event.preventDefault();
} // click first/selected duplicate (key D)
else if ((event.keyCode === 68) && w.document.querySelector("#content > button")) {
w.document.querySelector("#content > button").click();
currentSelectable = 0;
event.preventDefault();
} // click on translate title link (key T)
else if (event.keyCode === 84) {
const link = w.document.querySelector("#descriptionDiv > .translate-title");
if (link) {
link.click();
event.preventDefault();
}
} // click on translate description link (key Y)
else if (event.keyCode === 89) {
const link = w.document.querySelector("#descriptionDiv > .translate-description");
if (link) {
link.click();
event.preventDefault();
}
} // submit duplicate
else if ((event.keyCode === 13 || event.keyCode === 32) && w.document.querySelector("[ng-click=\"answerCtrl2.confirmDuplicate()\"]")) {
w.document.querySelector("[ng-click=\"answerCtrl2.confirmDuplicate()\"]").click();
currentSelectable = 0;
event.preventDefault();
} // submit normal rating
else if ((event.keyCode === 13 || event.keyCode === 32) && currentSelectable === maxItems) {
w.document.querySelector("[ng-click=\"answerCtrl.submitForm()\"]").click();
event.preventDefault();
} // close duplicate dialog
else if ((event.keyCode === 27 || event.keyCode === 111) && w.document.querySelector("[ng-click=\"answerCtrl2.resetDuplicate()\"]")) {
w.document.querySelector("[ng-click=\"answerCtrl2.resetDuplicate()\"]").click();
currentSelectable = 0;
event.preventDefault();
} // close low quality ration dialog
else if ((event.keyCode === 27 || event.keyCode === 111) && w.document.querySelector("[ng-click=\"answerCtrl2.resetLowQuality()\"]")) {
w.document.querySelector("[ng-click=\"answerCtrl2.resetLowQuality()\"]").click();
currentSelectable = 0;
event.preventDefault();
}
// return to first selection (should this be a portal)
else if (event.keyCode === 27 || event.keyCode === 111) {
currentSelectable = 0;
}
// skip portal if possible
else if (event.keyCode === 106 || event.keyCode === 220) {
if (newPortalData.canSkip)
ansController.skipToNext();
}
else if (event.keyCode === 72) {
showHelp(); // @todo
}
// select next rating
else if ((event.keyCode === 107 || event.keyCode === 9) && currentSelectable < maxItems) {
currentSelectable++;
event.preventDefault();
}
// select previous rating
else if ((event.keyCode === 109 || event.keyCode === 16 || event.keyCode === 8) && currentSelectable > 0) {
currentSelectable--;
event.preventDefault();
}
else if (numkey === null || currentSelectable > maxItems - 2) {
return;
}
else if (numkey !== null && event.shiftKey) {
try {
w.document.getElementsByClassName("customPresetButton")[numkey - 1].click();
} catch (e) {
// ignore
}
}
// rating 1-5
else {
starsAndSubmitButtons[currentSelectable].querySelectorAll("button.button-star")[numkey - 1].click();
currentSelectable++;
}
highlight();
});
highlight();
modifyNewPage = () => {
}; // just run once
}
function modifyEditPage(ansController, subController, newPortalData) {
let editDiv = w.document.querySelector("div[ng-show=\"subCtrl.reviewType==='EDIT'\"]");
mapButtons(newPortalData, editDiv, "afterEnd");
let newSubmitDiv = moveSubmitButton();
let {submitButton, submitAndNext} = quickSubmitButton(newSubmitDiv, ansController);
textButtons();
mapTypes(subController.locationEditsMap, true);
// add translation links to title and description edits
if (newPortalData.titleEdits.length > 1 || newPortalData.descriptionEdits.length > 1) {
for (const titleEditBox of editDiv.querySelectorAll(".titleEditBox")) {
const content = titleEditBox.innerText.trim();
let a = w.document.createElement("a");
let span = w.document.createElement("span");
span.className = "glyphicon glyphicon-book";
span.innerHTML = " ";
a.appendChild(span);
a.className = "translate-title button btn btn-default pull-right";
a.target = "translate";
a.style.padding = "0px 4px";
a.href = `https://translate.google.com/#auto/${browserLocale.split("-")[0]}/${encodeURIComponent(content)}`;
titleEditBox.querySelector("p").style.display = "inline-block";
titleEditBox.insertAdjacentElement("beforeEnd", a);
}
}
if (newPortalData.titleEdits.length <= 1) {
let titleDiv = editDiv.querySelector("div[ng-show=\"subCtrl.pageData.titleEdits.length <= 1\"] h3");
const content = titleDiv.innerText.trim();
let a = w.document.createElement("a");
let span = w.document.createElement("span");
span.className = "glyphicon glyphicon-book";
span.innerHTML = " ";
a.appendChild(span);
a.className = "translate-title button btn btn-default";
a.target = "translate";
a.style.padding = "0px 4px";
a.style.marginLeft = "14px";
a.href = `https://translate.google.com/#auto/${browserLocale.split("-")[0]}/${encodeURIComponent(content)}`;
titleDiv.insertAdjacentElement("beforeend", a);
}
if (newPortalData.descriptionEdits.length <= 1) {
let titleDiv = editDiv.querySelector("div[ng-show=\"subCtrl.pageData.descriptionEdits.length <= 1\"] p");
const content = titleDiv.innerText.trim() || "";
if (content !== "<No description>" && content !== "") {
let a = w.document.createElement("a");
let span = w.document.createElement("span");
span.className = "glyphicon glyphicon-book";
span.innerHTML = " ";
a.appendChild(span);
a.className = "translate-title button btn btn-default";
a.target = "translate";
a.style.padding = "0px 4px";
a.style.marginLeft = "14px";
a.href = `https://translate.google.com/#auto/${browserLocale.split("-")[0]}/${encodeURIComponent(content)}`;
titleDiv.insertAdjacentElement("beforeEnd", a);
}
}
expandWhatIsItBox();
// fix locationEditsMap if only one location edit exists
if (newPortalData.locationEdits.length <= 1)
subController.locationEditsMap.setZoom(19);
/* EDIT PORTAL */
// keyboard navigation
let currentSelectable = 0;
let hasLocationEdit = (newPortalData.locationEdits.length > 1);
// counting *true*, please don't shoot me
let maxItems = (newPortalData.descriptionEdits.length > 1) + (newPortalData.titleEdits.length > 1) + (hasLocationEdit) + 2;
let mapMarkers;
if (hasLocationEdit) mapMarkers = subController.allLocationMarkers;
else mapMarkers = [];
// a list of all 6 star button rows, and the two submit buttons
let starsAndSubmitButtons = w.document.querySelectorAll(
"div[ng-show=\"subCtrl.reviewType==='EDIT'\"] > div[ng-show=\"subCtrl.pageData.titleEdits.length > 1\"]:not(.ng-hide)," +
"div[ng-show=\"subCtrl.reviewType==='EDIT'\"] > div[ng-show=\"subCtrl.pageData.descriptionEdits.length > 1\"]:not(.ng-hide)," +
"div[ng-show=\"subCtrl.reviewType==='EDIT'\"] > div[ng-show=\"subCtrl.pageData.locationEdits.length > 1\"]:not(.ng-hide)," +
".big-submit-button");
/* EDIT PORTAL */
function highlight() {
let el = editDiv.querySelector("h3[ng-show=\"subCtrl.pageData.locationEdits.length > 1\"]");
el.style.border = "none";
starsAndSubmitButtons.forEach(exportFunction((element) => {
element.style.border = "none";
}, w));
if (hasLocationEdit && currentSelectable === maxItems - 3) {
el.style.borderLeft = cloneInto("4px dashed #ebbc4a", w);
el.style.borderTop = cloneInto("4px dashed #ebbc4a", w);
el.style.borderRight = cloneInto("4px dashed #ebbc4a", w);
el.style.padding = cloneInto("16px", w);
el.style.marginBottom = cloneInto("0", w);
submitAndNext.blur();
submitButton.blur();
}
else if (currentSelectable < maxItems - 2) {
starsAndSubmitButtons[currentSelectable].style.borderLeft = cloneInto("4px dashed #ebbc4a", w);
starsAndSubmitButtons[currentSelectable].style.paddingLeft = cloneInto("16px", w);
submitAndNext.blur();
submitButton.blur();
} else if (currentSelectable === maxItems - 2) {
submitAndNext.focus();
}
else if (currentSelectable === maxItems) {
submitButton.focus();
}
}
/* EDIT PORTAL */
addEventListener("keydown", (event) => {
/*
Keycodes:
8: Backspace
9: TAB
13: Enter
16: Shift
27: Escape
32: Space
68: D
107: NUMPAD +
109: NUMPAD -
111: NUMPAD /
49 - 53: Keys 1-5
97 - 101: NUMPAD 1-5
*/
if (event.keyCode >= 49 && event.keyCode <= 53)
numkey = event.keyCode - 48;
else if (event.keyCode >= 97 && event.keyCode <= 101)
numkey = event.keyCode - 96;
else
numkey = null;
// do not do anything if a text area or a input with type text has focus
if (w.document.querySelector("input[type=text]:focus") || w.document.querySelector("textarea:focus")) {
return;
}
// "analyze next" button
else if ((event.keyCode === 13 || event.keyCode === 32) && w.document.querySelector("a.button[href=\"/recon\"]")) {
w.document.location.href = "/recon";
event.preventDefault();
} // submit normal rating
else if ((event.keyCode === 13 || event.keyCode === 32) && currentSelectable === maxItems) {
w.document.querySelector("[ng-click=\"answerCtrl.submitForm()\"]").click();
event.preventDefault();
} // return to first selection (should this be a portal)
else if (event.keyCode === 27 || event.keyCode === 111) {
currentSelectable = 0;
}
// select next rating
else if ((event.keyCode === 107 || event.keyCode === 9) && currentSelectable < maxItems) {
currentSelectable++;
event.preventDefault();
}
// select previous rating
else if ((event.keyCode === 109 || event.keyCode === 16 || event.keyCode === 8) && currentSelectable > 0) {
currentSelectable--;
event.preventDefault();
}
else if (numkey === null || currentSelectable > maxItems - 2) {
return;
}
// rating 1-5
else {
if (hasLocationEdit && currentSelectable === maxItems - 3 && numkey <= mapMarkers.length) {
google.maps.event.trigger(angular.element(document.getElementById("NewSubmissionController")).scope().getAllLocationMarkers()[numkey - 1], "click");
}
else {
if (hasLocationEdit) numkey = 1;
starsAndSubmitButtons[currentSelectable].querySelectorAll(".titleEditBox, input[type='checkbox']")[numkey - 1].click();
currentSelectable++;
}
}
highlight();
});
highlight();
}
// add map buttons
function mapButtons(newPortalData, targetElement, where) {
// coordinate format conversion
const coordUtm33 = proj4("+proj=longlat", "+proj=utm +zone=33", [newPortalData.lng, newPortalData.lat]);
const coordUtm35 = proj4("+proj=longlat", "+proj=utm +zone=35", [newPortalData.lng, newPortalData.lat]);
const coordPuwg92 = proj4("+proj=longlat", "+proj=tmerc +lat_0=0 +lon_0=19 +k=0.9993 +x_0=500000 +y_0=-5300000 +ellps=GRS80 +units=m +no_defs", [newPortalData.lng, newPortalData.lat]);
const wgs_lat = newPortalData.lat;
const wgs_lng = newPortalData.lng;
const name = newPortalData.title;
const _gcj = coordtransform.wgs84togcj02(wgs_lng, wgs_lat);
const gcj_lat = _gcj[1];
const gcj_lng = _gcj[0];
const _bd = coordtransform.gcj02tobd09(gcj_lng, gcj_lat);
const bd_lat = _bd[1];
const bd_lng = _bd[0];
const mapButtons = [
"<a class='button btn btn-default' target='intel' href='https://www.ingress.com/intel?ll=" + wgs_lat + "," + wgs_lng + "&z=17'>Intel</a>",
"<a class='button btn btn-default' target='osm' href='https://www.openstreetmap.org/?mlat=" + wgs_lat + "&mlon=" + wgs_lng + "&zoom=16'>OSM</a>",
"<a class='button btn btn-default' target='baidu' href='http://api.map.baidu.com/marker?location=" + wgs_lat + "," + wgs_lng + "&title=" + name + "&content=OPR_Candidate&output=html&coord_type=wgs84&src=OPR'>" + STRINGS.baidu + "</a>",
"<a class='button btn btn-default' target='tencent' href='http://apis.map.qq.com/uri/v1/marker?&marker=coord:" + gcj_lat + "," + gcj_lng + ";title:" + name + ";addr:&referer=OPR'>" + STRINGS.tencent + "</a>",
"<a class='button btn btn-default' target='amap' href='http://uri.amap.com/marker?position=" + wgs_lng + "," + wgs_lat + "&name=" + name + "&src=opr&coordinate=wgs84&callnative=0\n'>" + STRINGS.amap + "</a>",
"<a class='button btn btn-default' target='baidu-streetview' href='http://api.map.baidu.com/pano/?x=" + bd_lng + "&y=" + bd_lat + "&lc=0&ak=ngDX6G7TgWSmjMstxolm7g642F7eUbkS'>" + STRINGS.bdstreetview + "</a>"
];
targetElement.insertAdjacentHTML(where, `<div><div class='btn-group'>${mapButtons.join("")}`);
}
// add new button "Submit and reload", skipping "Your analysis has been recorded." dialog
function quickSubmitButton(submitDiv, ansController) {
let submitButton = submitDiv.querySelector("button");
submitButton.classList.add("btn", "btn-warning");
let submitAndNext = submitButton.cloneNode(false);
submitAndNext.innerHTML = `<span class="glyphicon glyphicon-floppy-disk"></span> <span class="glyphicon glyphicon-forward"></span>`;
submitAndNext.title = "Submit and go to next review";
submitAndNext.addEventListener("click", exportFunction(() => {
exportFunction(() => {
window.location.assign("/recon");
}, ansController, {defineAs: "openSubmissionCompleteModal"});
}, w));
w.$injector.invoke(cloneInto(["$compile", ($compile) => {
let compiledSubmit = $compile(submitAndNext)(w.$scope(submitDiv));
submitDiv.querySelector("button").insertAdjacentElement("beforeBegin", compiledSubmit[0]);
}], w, {cloneFunctions: true}));
return {submitButton, submitAndNext};
}
function textButtons() {
let emergencyWay = "";
if (browserLocale.includes("de")) {
emergencyWay = "RETTUNGSWEG!1";
} else {
emergencyWay = "Emergency Way";
}
// add text buttons
const textButtons = `
<button id='photo' class='button btn btn-default textButton' data-tooltip='Indicates a low quality photo'>Photo</button>
<button id='private' class='button btn btn-default textButton' data-tooltip='Located on private residential property'>Private</button>`;
const textDropdown = `
<li><a class='textButton' id='school' data-tooltip='Located on school property'>School</a></li>
<li><a class='textButton' id='person' data-tooltip='Photo contains 1 or more people'>Person</a></li>
<li><a class='textButton' id='perm' data-tooltip='Seasonal or temporary display or item'>Temporary</a></li>
<li><a class='textButton' id='location' data-tooltip='Location wrong'>Location</a></li>
<li><a class='textButton' id='natural' data-tooltip='Candidate is a natural feature'>Natural</a></li>
<li><a class='textButton' id='emergencyway' data-tooltip='Obstructing emergency way'>${emergencyWay}</a></li>
`;
const textBox = w.document.querySelector("#submitDiv + .text-center > textarea");
w.document.querySelector("#submitDiv + .text-center").insertAdjacentHTML("beforeend", `
<div class='btn-group dropup'>${textButtons}
<div class='button btn btn-default dropdown'><span class='caret'></span><ul class='dropdown-content dropdown-menu'>${textDropdown}</ul>
</div></div><div class="hidden-xs"><button id='clear' class='button btn btn-default textButton' data-tooltip='clears the comment box'>Clear</button></div>
`);
const buttons = w.document.getElementsByClassName("textButton");
for (let b in buttons) {
if (buttons.hasOwnProperty(b)) {
buttons[b].addEventListener("click", exportFunction(event => {
const source = event.target || event.srcElement;
let text = textBox.value;
if (text.length > 0) {
text += ",\n";
}
switch (source.id) {
case "photo":
text += "Low quality photo";
break;
case "private":
text += "Private residential property";
break;
case "duplicate":
text += "Duplicate of previously reviewed portal candidate";
break;
case "school":
text += "Located on primary or secondary school grounds";
break;
case "person":
text += "Picture contains one or more people";
break;
case "perm":
text += "Portal candidate is seasonal or temporary";
break;
case "location":
text += "Portal candidate's location is not on object";
break;
case "emergencyway":
text += "Portal candidate is obstructing the path of emergency vehicles";
break;
case "natural":
text += "Portal candidate is a natural feature";
break;
case "clear":
text = "";
break;
}
textBox.value = text;
textBox.dispatchEvent(new Event("change"));
event.target.blur();
}, w), false);
}
}
}
// adding a 40m circle around the portal (capture range)
function mapOriginCircle(map) {
// noinspection JSUnusedLocalSymbols
const circle = new google.maps.Circle({
map: map,
center: map.center,
radius: 40,
strokeColor: "#ebbc4a",
strokeOpacity: 0.8,
strokeWeight: 1.5,
fillOpacity: 0,
});
}
// replace map markers with a nice circle
function mapMarker(markers) {
for (let i = 0; i < markers.length; ++i) {