-
Notifications
You must be signed in to change notification settings - Fork 0
/
easyptre.js
2351 lines (2161 loc) · 115 KB
/
easyptre.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 EasyPTRE
// @namespace https://openuserjs.org/users/GeGe_GM
// @version 0.11.2
// @description Plugin to use PTRE's features with AGR / OGL / OGI. Check https://ptre.chez.gg/
// @author GeGe_GM
// @license MIT
// @copyright 2022, GeGe_GM
// @match https://*.ogame.gameforge.com/game/*
// @match https://ptre.chez.gg/*
// @updateURL https://openuserjs.org/meta/GeGe_GM/EasyPTRE.meta.js
// @downloadURL https://openuserjs.org/install/GeGe_GM/EasyPTRE.user.js
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_addStyle
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_xmlhttpRequest
// ==/UserScript==
// Check current website
var modeEasyPTRE = "ingame";
if (/ptre.chez.gg/.test(location.href)) {
modeEasyPTRE = "ptre";
console.log("[PTRE] EasyPTRE: Mode PTRE");
}
// Settings
const ptreMessageDisplayTime = 5*1000;
const menuImageDisplayTime = 3*1000;
const ptrePushDelayMicroSec = 500;
const versionCheckTimeout = 6*60*60;
const technosCheckTimeout = 15*60;
const dataSharingDelay = 200;
const improvePageDelay = 200;
const ptreTargetListMaxSize = 300;
const deepSpacePlayerId = 99999;
// TODO: Set ptreAGRTargetListMaxSize
// Variables
var toolName = 'EasyPTRE';
var server = -1;
var country = "";
var universe = -1;
var currentPlayerID = -1;
var ptreID = "ptre-id";
var lastActivitiesGalaSent = 0;
var lastActivitiesSysSent = 0;
var lastPTREActivityPushMicroTS = 0;
var ptreGalaxyActivityCount = 0;
var ptreGalaxyEventCount = 0;
if (modeEasyPTRE == "ingame") {
server = document.getElementsByName('ogame-universe')[0].content;
var splitted = server.split('-');
universe = splitted[0].slice(1);
var splitted2 = splitted[1].split('.');
country = splitted2[0];
currentPlayerID = document.getElementsByName('ogame-player-id')[0].content;
} else {
country = document.getElementsByName('ptre-country')[0].content;
universe = document.getElementsByName('ptre-universe')[0].content;
GM_setValue(ptreID, document.getElementsByName('ptre-id')[0].content);
}
// GM keys
var ptreTeamKey = "ptre-" + country + "-" + universe + "-TK";
var ptreImproveAGRSpyTable = "ptre-" + country + "-" + universe + "-ImproveAGRSpyTable";
var ptrePTREPlayerListJSON = "ptre-" + country + "-" + universe + "-PTREPlayerListJSON";
var ptreAGRPlayerListJSON = "ptre-" + country + "-" + universe + "-AGRPlayerListJSON";
var ptreAGRPrivatePlayerListJSON = "ptre-" + country + "-" + universe + "-AGRPrivatePlayerListJSON";
var ptreEnableConsoleDebug = "ptre-" + country + "-" + universe + "-EnableConsoleDebug";
var ptreAddBuddiesToFriendsAndPhalanx = "ptre-" + country + "-" + universe + "-AddBuddiesToFriendsAndPhalanx";
var ptreLastAvailableVersion = "ptre-" + country + "-" + universe + "-LastAvailableVersion";
var ptreLastAvailableVersionRefresh = "ptre-" + country + "-" + universe + "-LastAvailableVersionRefresh";
var ptreMaxCounterSpyTsSeen = "ptre-" + country + "-" + universe + "-MaxCounterSpyTsSeen";
var ptreTechnosJSON = "ptre-" + country + "-" + universe + "-Technos";
var ptreLastTechnosRefresh = "ptre-" + country + "-" + universe + "-LastTechnosRefresh";
var ptrePlayerID = "ptre-" + country + "-" + universe + "-PlayerID";
var ptreDataToSync = "ptre-" + country + "-" + universe + "-DataToSync";
var ptreGalaxyData = "ptre-" + country + "-" + universe + "-GalaxyDataG";
var ptreBuddiesList = "ptre-" + country + "-" + universe + "-BuddiesList";
var ptreBuddiesListLastRefresh = "ptre-" + country + "-" + universe + "-BuddiesListLastRefresh";
// Images
var imgPTRE = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAMAAACelLz8AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAB1FBMVEUAAEAAAEE1IjwvHTsEA0GBTCquYhxbNjINCUAFBEEqGjwyIDsAAUAYED+k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Xa1drY06ejNNTSMjq36uy2N8+M6pEAAAABYktHRDJA0kzIAAAACXBIWXMAAAsSAAALEgHS3X78AAAAB3RJTUUH5gwDDgk1VmNCsAAAAJNJREFUGNN1ztcOgkAURdFjA3sF7KKoMA6CIE1s//9ZtoTMOLAfV3JzD1CtSXI9S5YazRJabdPiMjtd9CyhPgYiDjESUSlEcmAiP6T2kcmmHySOe2JyHaJA9fwzl+9pUIOQxzDQ3udRnFyykjgi30fplSmlxZNyxo/zcCLiFLPbv93nWCwfvD1XOsrrjbFlMnb7ygvg8zvdxWLNowAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0xMi0wM1QxNDowOTo0OCswMDowMAzRxoAAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMTItMDNUMTQ6MDk6NDgrMDA6MDB9jH48AAAAAElFTkSuQmCC';
// PTRE URLs
var galaxyContentLinkTest = "https:\/\/"+server+"\/game\/index.php?page=ingame&component=galaxy&action=fetchGalaxyContent&ajax=1&asJson=1";
var urlPTREImportSR = 'https://ptre.chez.gg/scripts/oglight_import.php?tool=' + toolName;
var urlPTREPushActivity = 'https://ptre.chez.gg/scripts/oglight_import_player_activity.php?tool=' + toolName + '&country=' + country + '&univers=' + universe;
var urlPTRESyncTargets = 'https://ptre.chez.gg/scripts/api_sync_target_list.php?tool=' + toolName + '&country=' + country + '&univers=' + universe;
var urlPTREGetPlayerInfos = 'https://ptre.chez.gg/scripts/oglight_get_player_infos.php?tool=' + toolName + '&country=' + country + '&univers=' + universe;
var urlPTRESyncSharableData = 'https://ptre.chez.gg/scripts/api_sync_data.php?tool=' + toolName + '&country=' + country + '&univers=' + universe;
var urlPTREGetPhalanxInfosFromGala = 'https://ptre.chez.gg/scripts/api_get_phalanx_infos.php?tool=' + toolName + '&country=' + country + '&univers=' + universe;
var urlPTREGetGEEInfosFromGala = 'https://ptre.chez.gg/scripts/api_get_gee_infos.php?tool=' + toolName + '&country=' + country + '&univers=' + universe;
var urlPTREPushGalaUpdate = 'https://ptre.chez.gg/scripts/api_galaxy_import_infos.php?tool=' + toolName + '&country=' + country + '&univers=' + universe;
var urlToScriptMetaInfos = 'https://openuserjs.org/meta/GeGe_GM/EasyPTRE.meta.js';
// ****************************************
// MAIN EXEC
// OGame pages
// ****************************************
if (modeEasyPTRE == "ingame") {
// Add EasyPTRE menu
if (!/page=standalone&component=empire/.test(location.href)) {
// Setup Mneu Button
var ptreMenuName = toolName;
var lastAvailableVersion = GM_getValue(ptreLastAvailableVersion, -1);
if (lastAvailableVersion != -1 && lastAvailableVersion !== GM_info.script.version) {
ptreMenuName = "CLICK ME";
}
var aff_option = '<span class="menu_icon"><a id="iconeUpdate" href="https://ptre.chez.gg" target="blank_" ><img id="imgPTREmenu" class="mouseSwitch" src="' + imgPTRE + '" height="26" width="26"></a></span>';
aff_option += '<a id="affOptionsPTRE" class="menubutton " href="#" accesskey="" target="_self"><span class="textlabel" id="ptreMenuName">' + ptreMenuName + '</span></a>';
var tab = document.createElement("li");
tab.innerHTML = aff_option;
tab.id = 'optionPTRE';
document.getElementById('menuTableTools').appendChild(tab);
document.getElementById('affOptionsPTRE').addEventListener("click", function (event) {
displayPTREMenu();
}, true);
}
// Run on all pages
if (!/page=standalone&component=empire/.test(location.href)) {
consoleDebug("Any page detected");
setTimeout(improvePageAny, improvePageDelay);
}
// Galaxy page: Set routines
if (/component=galaxy/.test(location.href)) {
consoleDebug("Galaxy page detected");
setTimeout(improvePageGalaxy, improvePageDelay);
}
// Message page: Add PTRE send SR button
if (/component=messages/.test(location.href)) {
consoleDebug("Message page detected");
setTimeout(improvePageMessages, improvePageDelay);
}
// Save fleeters techs in order to send it to simulator from PTRE pages
// Huge QOL to not add them manually
if (/page=ingame&component=fleetdispatch/.test(location.href)) {
consoleDebug("Fleet page detected");
setTimeout(improvePageFleet, improvePageDelay);
}
// Capture Phalanx level
if (/page=ingame&component=facilities/.test(location.href)) {
consoleDebug("Facilities page detected");
setTimeout(improvePageFacilities, improvePageDelay);
}
// Buddies Page
if (/page=ingame&component=buddies/.test(location.href)) {
consoleDebug("Buddies page detected");
setTimeout(improvePageBuddies, improvePageDelay);
}
// Check for new version only if we already did the check once
// In order to not display the Tampermoney autorisation window during an inappropriate moment
// It will be enabled when user opens the PTRE menu
if (GM_getValue(ptreLastAvailableVersionRefresh, 0) != 0) {
updateLastAvailableVersion(false);
} else {
consoleDebug("Version Check not initialized: open settings to initialize it");
}
}
// ****************************************
// MAIN EXEC
// PTRE pages only
// ****************************************
if (modeEasyPTRE == "ptre") {
// Remove EasyPTRE notification from PTRE website
if (document.getElementById("easyptre_install_notification")) {
document.getElementById("easyptre_install_notification").remove();
}
// Display Lifeforms research on PTRE Lifeforms page
if (/ptre.chez.gg\/\?page=lifeforms_researchs/.test(location.href)){
if (universe != 0) {
console.log("[PTRE] PTRE Lifeforms page detected: "+country+"-"+universe);
const json = GM_getValue(ptreTechnosJSON, '');
if (json != '') {
tab = parsePlayerResearchs(json, "tab");
document.getElementById("tech_from_easyptre").innerHTML = tab;
console.log("[PTRE] Updating lifeforms page");
} else {
console.log("[PTRE] No lifeforms data saved");
}
}
}
// Update PTRE Spy Report Pages
if (/ptre.chez.gg\/\?iid/.test(location.href)){
console.log("[PTRE] PTRE Spy Report page detected: "+country+"-"+universe);
const json = GM_getValue(ptreTechnosJSON, '');
if (json != '') {
const linkElement = document.getElementById("simulate_link");
let hrefValue = linkElement.getAttribute("href");
var prefill = parsePlayerResearchs(json, "prefill");
hrefValue = hrefValue.replace("replaceme", prefill);
linkElement.setAttribute("href", hrefValue);
document.getElementById("simulator_comment").innerHTML = "This link contains your LF techs";
console.log("[PTRE] Updating simulator link");
} else {
console.log("[PTRE] No lifeforms data saved");
}
}
}
// ****************************************
// Add PTRE styles
// Ugly style... yes!
// ****************************************
GM_addStyle(`
.success_status {
color:#99CC00;
}
.error_status {
color: #D43635;
}
.warning_status {
color:#D29D00;
}
.ptre_maintitle {
color: #6f9fc8;
font-weight:bold;
text-decoration: underline;
}
.ptre_title {
color: #6f9fc8;
font-weight:bold;
}
.ptre_tab_title {
color: #6f9fc8;
}
.ptre_bold {
font-weight:bold;
}
.td_cell {
padding: 3px;
}
.tr_cell_radius {
background-color: transparent;
}
.td_cell_radius_0 {
background-color: #12171C;
padding: 3px;
border-radius: 6px;
border: 1px solid black;
}
.td_cell_radius_1 {
background-color: #0d1014;
padding: 3px;
border-radius: 6px;
border: 1px solid black;
}
.td_cell_radius_2 {
background-color: #1031a0;
padding: 3px;
border-radius: 6px;
border: 1px solid black;
}
.ptre_ship {
background-image: url('https://gf3.geo.gfsrv.net/cdn84/3b19b4263662f5a383524052047f4f.png');
background-repeat: no-repeat;
height: 28px;
width: 28px;
display: block;
}
.ptre_ship_202 {
background-position: 0 0;
}
.ptre_ship_203 {
background-position: -28px 0;
}
.ptre_ship_204 {
background-position: -56px 0;
}
.ptre_ship_205 {
background-position: -84px 0;
}
.ptre_ship_206 {
background-position: -112px 0;
}
.ptre_ship_207 {
background-position: -140px 0;
}
.ptre_ship_208 {
background-position: -168px 0;
}
.ptre_ship_209 {
background-position: -196px 0;
}
.ptre_ship_210 {
background-position: -224px 0;
}
.ptre_ship_211 {
background-position: -252px 0;
}
.ptre_ship_212 {
background-position: -280px 0;
}
.ptre_ship_213 {
background-position: -308px 0;
}
.ptre_ship_214 {
background-position: -336px 0;
}
.ptre_ship_215 {
background-position: -364px 0;
}
.ptre_ship_217 {
background-position: -448px 0;
}
.ptre_ship_218 {
background-position: -392px 0;
}
.ptre_ship_219 {
background-position: -420px 0;
}
.td_ship {
padding: 3px;
}
.button {
padding: 0px;
}
#divPTRESettings {
position: fixed;
bottom: 30px;
right: 10px;
z-index: 1000;
font-size: 10pt;
}
#boxPTRESettings {
width: 500px;
padding:10px;
border: solid black 2px;
background-color: #171d22;
}
#boxPTREMessage {
position: fixed;
bottom: 30px;
right: 10px;
z-index: 1001;
padding:10px;
border: solid black 2px;
background-color: #171d22;
}
#boxPTREInfos {
position: fixed;
bottom: 30px;
right: 540px;
z-index: 1000;
font-size: 10pt;
min-width: 300px;
padding:10px;
border: solid black 2px;
background-color: #171d22;
}
#btnSaveOptPTRE {
cursor:pointer;
}
#ptreGalaxyMiniMessage {
color:green;
font-weight:bold;
}
#targetDivSettings {
height: 350px;
overflow-y: scroll;
}
#ptreGalaxyBox {
background-color: #171d22;
font-weight: revert;
padding-top: 10px;
}
#ptreGalaxyMessageBoxContent {
padding-left: 10px;
padding-top: 3px;
text-align: left;
display: block;
line-height: 1.3em;
}
`);
// ****************************************
// IMPROVE VIEWS
// ****************************************
// To run on all pages
function improvePageAny() {
console.log("[PTRE] Improving Any Page");
if (isAGREnabled() && !isOGLorOGIEnabled()) {
if (document.getElementById('ago_panel_Player')) {
let observer2 = new MutationObserver(updateLocalAGRList);
var node2 = document.getElementById('ago_panel_Player');
observer2.observe(node2, {
attributes: true,
childList: true, // observer les enfants directs
subtree: true, // et les descendants aussi
characterDataOldValue: true // transmettre les anciennes données au callback
});
}
if (document.getElementById('ago_box_title')) {
// Add PTRE link to AGR pinned player
addPTRELinkToAGRPinnedTarget();
// Check if pinned player is updated
let observer = new MutationObserver(addPTRELinkToAGRPinnedTarget);
var node = document.getElementById('ago_box_title');
observer.observe(node, {
attributes: true,
childList: true, // observer les enfants directs
subtree: true, // et les descendants aussi
characterDataOldValue: true // transmettre les anciennes données au callback
});
}
}
}
// Add PTRE buttons to messages page
function improvePageMessages() {
console.log("[PTRE] Improving Messages Page");
if (!isOGLorOGIEnabled() && !isOGLorOGIEnabled()) {
if (GM_getValue(ptreTeamKey) != '') {
// Update Message Page (spy report part)
setTimeout(addPTREStuffsToMessagesPage, 1000);
// Update AGR Spy Table
if (isAGREnabled() && (GM_getValue(ptreImproveAGRSpyTable, 'true') == 'true')) {
let spyTableObserver = new MutationObserver(improveAGRSpyTable);
var nodeSpyTable = document.getElementById('messagecontainercomponent');
spyTableObserver.observe(nodeSpyTable, {
attributes: true,
childList: true, // observer les enfants directs
subtree: true, // et les descendants aussi
});
}
}
}
}
// Add buttons to galaxy
function improvePageGalaxy() {
console.log("[PTRE] Improving Galaxy Page");
var tempContent = '<table width="100%"><tr>';
tempContent+= '<td valign="top"><span class="ptre_maintitle">PTRE TOOLBAR</span></td><td valign="top"><div id="ptreGalaxyPhalanxButton" type="button" class="button btn_blue">FRIENDS & PHALANX</div> <div id="ptreGalaxyGEEButton" type="button" class="button btn_blue">GALAXY EVENT EXPLORER</div></td>';
tempContent+= '<td valign="top">';
if (!isOGLorOGIEnabled()) {
tempContent+= '<span id="ptreGalaxyActivityCount" class="success_status"></span> Activities | <span id="ptreGalaxyEventCount" class="success_status"></span> Galaxy Events';
} else {
tempContent+= '---';
}
tempContent+= '</td></tr><td valign="top" colspan="3"><hr></td></tr>';
tempContent+= '<td valign="top" colspan="3"><div id="ptreGalaxyMessageBoxContent"></div></td></tr></table>';
var tempDiv = document.createElement("div");
tempDiv.innerHTML = tempContent;
tempDiv.id = 'ptreGalaxyBox';
document.getElementsByClassName("galaxyTable")[0].appendChild(tempDiv);
document.getElementById('ptreGalaxyPhalanxButton').addEventListener("click", function (event) {
getPhalanxInfosFromGala();
});
document.getElementById('ptreGalaxyGEEButton').addEventListener("click", function (event) {
getGEEInfosFromGala();
});
// Add PTRE debug message Div
if (!document.getElementById("ptreGalaxyMessageD")) {
tempDiv = document.createElement("div");
tempDiv.innerHTML = '<span id="ptreGalaxyMiniMessage"></span>';
tempDiv.id = 'ptreGalaxyMessageD';
document.getElementsByClassName('galaxyRow ctGalaxyFleetInfo')[0].appendChild(tempDiv);
}
if (isAGREnabled() && !isOGLorOGIEnabled()) {
// Run it once (As AGR does not modifiy Galaxy)
checkForNewSystem();
// Then add Trigger
if (document.getElementById('galaxyHeader')) {
console.log("[PTRE] Add trigger on galaxyHeader");
let spyTableObserver = new MutationObserver(checkForNewSystem);
var nodeSpyTable = document.getElementById('galaxyRow8');
spyTableObserver.observe(nodeSpyTable, {
attributes: true/*,
childList: true, // observer les enfants directs
subtree: true, // et les descendants aussi
characterDataOldValue: true*/ // transmettre les anciennes données au callback
});
}
}
// If no AGR/OGL/OGI: add PTRE stuffs to Galaxy tab
// This only add buttons to add target to native EasyPTRE
if (!isAGREnabled() && !isOGLorOGIEnabled()) {
consoleDebug("Improving Galaxy Page for AGR");
var galaxy = document.getElementsByClassName('galaxyRow ctContentRow ');
var nbBtnPTRE = 0;
if (!document.getElementById('spanAddPlayer0') && !document.getElementById('spanSuppPlayer0')) {
$.each(galaxy, function(nb, lignePosition) {
if (lignePosition.children[7] != '') {
var actionPos = lignePosition.children[7];
if (actionPos.innerHTML != '') {
if (actionPos.children[1] && actionPos.children[1].getAttributeNode('data-playerid')) {
var playerId = actionPos.children[1].getAttributeNode('data-playerid').value;
var playerInfo = lignePosition.children[5];
if (playerInfo.children[0]) {
var playerPseudo = playerInfo.children[0].innerText;
var notIna = true;
var inaPlayer = playerInfo.children[1].innerText;
if (playerPseudo == '') {
playerPseudo = playerInfo.children[1].innerText;
inaPlayer = playerInfo.children[2].innerText;
}
if (isAGREnabled()) {
inaPlayer = playerInfo.children[0].innerText;
inaPlayer = inaPlayer.substr(-4, 4);
var indexPseudo = playerPseudo.search(/\n/);
playerPseudo = playerPseudo.substr(0, indexPseudo);
}
if (inaPlayer == ' (i)' || inaPlayer == ' (I)') {
notIna = false;
}
//consoleDebug('id : '+playerId+' pseudo :'+playerPseudo+' ina :'+inaPlayer);
var isInList = isPlayerInTheList(playerId, 'PTRE');
if (!isInList && notIna) {
var AddPlayerCheck = '<a class="tooltip" id="addcheckptr_'+nbBtnPTRE+'" title="Ajouter ce joueur a la liste PTRE" style="cursor:pointer;"><img class="mouseSwitch" src="' + imgAddPlayer + '" height="20" width="20"></a>';
var btnAddPlayer = document.createElement("span");
btnAddPlayer.innerHTML = AddPlayerCheck;
btnAddPlayer.id = 'spanAddPlayer'+nbBtnPTRE;
lignePosition.children[7].appendChild(btnAddPlayer);//
document.getElementById('addcheckptr_'+nbBtnPTRE).addEventListener("click", function (event)
{
//alert('J ajoute le joueur '+playerPseudo+' '+playerId);
var retAdd = addPlayerToList(playerId, playerPseudo, 'PTRE');
displayPTREPopUpMessage(retAdd[1]);
}, true);
nbBtnPTRE++;
} else if (isInList) {
var SupPlayerCheck = '<a class="tooltip" id="suppcheckptr_'+nbBtnPTRE+'" title="Retirer ce joueur de la liste PTRE" style="cursor:pointer;"><img class="mouseSwitch" src="' + imgSupPlayer + '" height="20" width="20"></a>';
var btnSupPlayer = document.createElement("span");
btnSupPlayer.innerHTML = SupPlayerCheck;
btnSupPlayer.id = 'spanSuppPlayer'+nbBtnPTRE;
lignePosition.children[7].appendChild(btnSupPlayer);//
document.getElementById('suppcheckptr_'+nbBtnPTRE).addEventListener("click", function (event)
{
var retSupp = deletePlayerFromList(playerId, 'PTRE');
displayPTREPopUpMessage(retSupp);
}, true);
nbBtnPTRE++;
}
}
}
}
}
});
}
}
}
// Save lifeforms researchs
// Save JSON "API 2" from fleet page
function improvePageFleet() {
console.log("[PTRE] Improving Fleet Page");
var currentTime = serverTime.getTime() / 1000;
if (currentTime > GM_getValue(ptreLastTechnosRefresh, 0) + technosCheckTimeout) {
GM_setValue(ptrePlayerID, currentPlayerID);
var spanElement = document.querySelector('.show_fleet_apikey');
var tooltipContent = spanElement.getAttribute('data-tooltip-title');
var tempDiv = document.createElement('div');
tempDiv.innerHTML = tooltipContent;
var inputElements = tempDiv.querySelectorAll('input');
var secondInputElement = inputElements[1];
var techJSON = secondInputElement ? secondInputElement.value : null;
if (techJSON != null) {
//techList = JSON.parse(techJSON);
GM_setValue(ptreTechnosJSON, techJSON);
var tempMessage = 'Saving Lifeforms researches: <a href="https://ptre.chez.gg/?page=lifeforms_researchs" target="_blank">Display on PTRE</a>';
displayPTREPopUpMessage(tempMessage);
// Update last check TS
GM_setValue(ptreLastTechnosRefresh, currentTime);
} else {
console.log("[PTRE] Cant find Techs!");
}
}
}
// Update Phalanx data
function improvePageFacilities() {
console.log("[PTRE] Improving Facilities Page");
if (document.getElementById('technologies')) {
const technologiesDiv = document.getElementById('technologies');
if (technologiesDiv.querySelector('li.sensorPhalanx')) {
const sensorPhalanxLi = technologiesDiv.querySelector('li.sensorPhalanx');
const levelSpan = sensorPhalanxLi.querySelector('span.level');
var phalanx_level = levelSpan.getAttribute('data-value');
var coords = document.getElementsByName('ogame-planet-coordinates')[0].content;
var moonID = document.getElementsByName('ogame-planet-id')[0].content;
//console.log('[PTRE] ' + coords + ' Found Phalanx level '+phalanx_level);
//var moon = {type: "moon", id: coords, val: {pha_lvl: phalanx_level, toto: "titi", tata: "tutu"}};
var phalanx = {type: "phalanx", id: moonID, coords: coords, val: phalanx_level};
addDataToPTREData(phalanx);
}
}
}
// Parse Buddies page
function improvePageBuddies() {
const currentTime = serverTime.getTime() / 1000;
const playerLinks = document.querySelectorAll('a[data-playerid]');
const playerIds = Array.from(playerLinks).map(link => link.getAttribute('data-playerid'));
consoleDebug(playerIds);
dataJSON = JSON.stringify(playerIds);
GM_setValue(ptreBuddiesList, dataJSON);
GM_setValue(ptreBuddiesListLastRefresh, currentTime);
displayPTREPopUpMessage('Saving buddies list (for Friends & Phalanx)');
}
// ****************************************
// NOTIFICATIONS FUNCTIONS
// ****************************************
// Displays PTRE responses messages
// Responses from server
// Displayed on the rigth-bottom corner
function displayPTREPopUpMessage(message) {
var previousContent = '';
if (document.getElementById('boxPTREMessage') && document.getElementById("ptreMessage")) {
// Get previous content and remove box
previousContent = document.getElementById("ptreMessage").innerHTML;
document.getElementById('boxPTREMessage').remove();
}
// Recreate box
var divPTREMessage = '<div id="boxPTREMessage">PTRE:<span id="ptreMessage">' + previousContent + '<span id="fisrtPtreMessage"><br>' + message + '</span></span></div>';
var boxPTREMessage = document.createElement("div");
boxPTREMessage.innerHTML = divPTREMessage;
boxPTREMessage.id = 'boxPTREMessage';
if (document.getElementById('bottom')) {
document.getElementById('bottom').appendChild(boxPTREMessage);
setTimeout(function() {cleanFirstPTREPopUpMessage();}, ptreMessageDisplayTime);
}
}
// Remove first message in list and remove entire message box if empty
function cleanFirstPTREPopUpMessage() {
if (document.getElementById('fisrtPtreMessage')) {
document.getElementById('fisrtPtreMessage').remove();
if (document.getElementById("ptreMessage").innerHTML == '') {
document.getElementById('boxPTREMessage').remove();
}
}
}
// Display message under galaxy view
function displayGalaxyMiniMessage(message) {
if (document.getElementById("ptreGalaxyMiniMessage")) {
document.getElementById("ptreGalaxyMiniMessage").innerHTML = "PTRE: " + message;
} else {
console.log("[PTRE] Error. Cant display: " + message);
}
}
// Display message content on galaxy page
function displayGalaxyMessageContent(message) {
if (document.getElementById("ptreGalaxyMessageBoxContent")) {
document.getElementById("ptreGalaxyMessageBoxContent").innerHTML = message;
} else {
console.log("[PTRE] Error. Cant display: " + message);
}
}
// ****************************************
// MINI FUNCTIONS
// ****************************************
// Detects if AGR is enabled
function isAGREnabled() {
if (document.getElementById('ago_panel_Player')) {
return true;
}
return false;
}
// Detects if OGL is enabled
function isOGLorOGIEnabled() {
if (document.querySelector('body.oglight') || document.getElementsByClassName('ogl-harvestOptions').length != 0) {
return true;
}
return false;
}
// Convert planets activities to OGL - PTRE format
function convertActivityToOGLFormat(showActivity, idleTime) {
if (showActivity == '15') {
return '*';
} else if (showActivity == '60') {
return idleTime;
} else if (!showActivity) {
return '60';
}
return '60';
}
function buildPTRELinkToPlayer(playerID) {
return 'https://ptre.chez.gg/?country=' + country + '&univers=' + universe + '&player_id=' + playerID;
}
function consoleDebug(message) {
if (GM_getValue(ptreEnableConsoleDebug, 'false') == 'true') {
console.log('[PTRE] ' + message);
}
}
function round(x, y) {
return Number.parseFloat(x).toFixed(y);
}
function displayMessageInSettings(message) {
if (document.getElementById('messageDivInSettings')) {
document.getElementById('messageDivInSettings').innerHTML = message;
}
}
function setNumber(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
}
// ****************************************
// PTRE/AGR LIST RELATED
// ****************************************
// Remove player from PTRE/AGR list
function deletePlayerFromList(playerId, type) {
// Check if player is part of the list
if (isPlayerInTheList(playerId, type)) {
// Get list content depending on if its PTRE or AGR list
var targetJSON = '';
var pseudo = '';
if (type == 'PTRE') {
targetJSON = GM_getValue(ptrePTREPlayerListJSON, '');
} else if (type == 'AGR') {
targetJSON = GM_getValue(ptreAGRPlayerListJSON, '');
}
var targetList = [];
var idASup = '_';
if (targetJSON != '') {
targetList = JSON.parse(targetJSON);
}
$.each(targetList, function(i, PlayerCheck) {
if (PlayerCheck.id == playerId) {
idASup = i;
pseudo = PlayerCheck.pseudo;
}
});
if (idASup != '_') {
targetList.splice(idASup, 1);
}
// Save list
targetJSON = JSON.stringify(targetList);
if (type == 'PTRE') {
GM_setValue(ptrePTREPlayerListJSON, targetJSON);
} else if (type == 'AGR') {
GM_setValue(ptreAGRPlayerListJSON, targetJSON);
}
return 'Player ' + pseudo + ' was removed from ' + type + ' list';
} else {
return 'Player is not part of ' + type + ' list';
}
}
// Add player to PTRE/AGR list
function addPlayerToList(playerId, playerPseudo, type) {
// Check if player is part of the list
if (!isPlayerInTheList(playerId, type)) {
// Get list content depending on if its PTRE or AGR list
var targetJSON = '';
if (type == 'PTRE') {
targetJSON = GM_getValue(ptrePTREPlayerListJSON, '');
} else if (type == 'AGR') {
targetJSON = GM_getValue(ptreAGRPlayerListJSON, '');
}
var targetList = [];
if (targetJSON != '') {
targetList = JSON.parse(targetJSON);
}
if (type == 'PTRE' && targetList.length >= ptreTargetListMaxSize) {
return [0, type + ' targets list is full, please remove a target'];
} else {
// Add player to list
var player = {id: playerId, pseudo: playerPseudo};
targetList.push(player);
// Save list
targetJSON = JSON.stringify(targetList);
var ret_code = 0;
if (type == 'PTRE') {
GM_setValue(ptrePTREPlayerListJSON, targetJSON);
} else if (type == 'AGR') {
GM_setValue(ptreAGRPlayerListJSON, targetJSON);
// We want to detect and notify when an AGR target is added
ret_code = 1;
}
consoleDebug('Player ' + playerPseudo + ' has been added to ' + type + ' list');
return [ret_code, 'Player has been added to ' + type + ' list'];
}
} else {
return [0, 'Player is already in ' + type + ' list'];
}
}
// This list contains targets that should not be shared to PTRE Team
function tooglePrivatePlayer(playerId) {
var targetJSON = '';
var targetList = [];
var status = '';
targetJSON = GM_getValue(ptreAGRPrivatePlayerListJSON , '');
var idASup = -1;
if (targetJSON != '') {
targetList = JSON.parse(targetJSON);
$.each(targetList, function(i, PlayerCheck) {
if (PlayerCheck.id == playerId) {
// Present => Delete
idASup = i;
}
});
if (idASup != -1) {
targetList.splice(idASup, 1);
status = 'shareable (sync to share)';
consoleDebug("Deleting private player (" + idASup + "): " + playerId);
}
}
if (idASup == -1) {
var player = {id: playerId};
targetList.push(player);
status = 'private';
consoleDebug("Adding private player " + playerId);
}
// Save new list
targetJSON = JSON.stringify(targetList);
GM_setValue(ptreAGRPrivatePlayerListJSON, targetJSON);
return status;
}
function isTargetPrivate(playerId) {
var targetJSON = '';
var targetList = [];
targetJSON = GM_getValue(ptreAGRPrivatePlayerListJSON , '');
var found = 0;
if (targetJSON != '') {
targetList = JSON.parse(targetJSON);
$.each(targetList, function(i, PlayerCheck) {
if (PlayerCheck.id == playerId) {
found = 1;
}
});
if (found == 1) {
return true;
}
}
return false;
}
function debugListContent() {
var targetJSON = '';
targetJSON = GM_getValue(ptreAGRPlayerListJSON, '');
var targetList = JSON.parse(targetJSON);
console.log("[PTRE] AGR list: ");
console.log(targetList);
targetJSON = GM_getValue(ptrePTREPlayerListJSON, '');
targetList = JSON.parse(targetJSON);
console.log("[PTRE] PTRE list: ");
console.log(targetList);
}
// Check is player is in list
function isPlayerInLists(playerId) {
if (isPlayerInTheList(playerId, 'AGR') || isPlayerInTheList(playerId, 'PTRE')) {
return true;
}
return false;
}
function isPlayerInTheList(playerId, type = 'PTRE') {
var targetJSON = '';
if (type == 'PTRE') {
targetJSON = GM_getValue(ptrePTREPlayerListJSON, '');
} else if (type == 'AGR') {
targetJSON = GM_getValue(ptreAGRPlayerListJSON, '');
}
var ret = false;
if (targetJSON != '') {
var targetList = JSON.parse(targetJSON);
$.each(targetList, function(i, PlayerCheck) {
if (PlayerCheck.id == playerId) {
ret = true;
}
});
}
return ret;
}
function getAGRPlayerIDFromPseudo(playerPseudo) {
var ret = 0;
var targetJSON = GM_getValue(ptreAGRPlayerListJSON, '');
if (targetJSON != '') {
var targetList = JSON.parse(targetJSON);
$.each(targetList, function(i, PlayerCheck) {
if (PlayerCheck.pseudo == playerPseudo) {
ret = PlayerCheck.id;
}
});
}
return ret;
}
// Copy AGR internal players list to local AGR list
// AGR list IDs
// Friend: 52 => NO
// Trader: 55 => NO
// Watch: 62 => YES
// Miner: 64 => YES
// Target: 66 => YES
// To attack: 67 => YES
function updateLocalAGRList() {
var tabAgo = document.getElementsByClassName('ago_panel_overview');
var count = 0;
if (tabAgo && tabAgo[1] && tabAgo[1].children) {
$.each(tabAgo[1].children, function(i, ligneJoueurAGR) {
if (ligneJoueurAGR.getAttributeNode('ago-data')) {
var txtjsonDataAgo = ligneJoueurAGR.getAttributeNode('ago-data').value;
var jsonDataAgo = JSON.parse(txtjsonDataAgo);
var token = jsonDataAgo.action.token;
// Do not add Friends and Traders to target list
// This will add user custom list too
if (token != 52 && token != 55) {
var IdPlayer = jsonDataAgo.action.id;
var PseudoPlayer = ligneJoueurAGR.children[1].innerText;
//consoleDebug('AGR native list member: ' + PseudoPlayer + ' (' + IdPlayer + ') | token:' + token + ')');
var ret = addPlayerToList(IdPlayer, PseudoPlayer, 'AGR');
count+= ret[0];
}
}
});
}
if (count > 0) {
displayPTREPopUpMessage(count + ' targets added to AGR list');
}
}
// ****************************************
// IMPROVE MAIN VIEWS
// ****************************************
// This function adds PTRE link to AGR pinned target
function addPTRELinkToAGRPinnedTarget() {
if (document.getElementById('ago_box_title')) {
var pseudoAGR = document.getElementById('ago_box_title').innerHTML;
updateLocalAGRList();
var playerID = getAGRPlayerIDFromPseudo(pseudoAGR);
if (playerID != 0) {
document.getElementById('ago_box_title').innerHTML = pseudoAGR + ' [<a href="' + buildPTRELinkToPlayer(playerID) + '" target="_blank">PTRE</a>]';
}
}