-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
831 lines (733 loc) · 38.2 KB
/
app.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
/// <reference path="intellisense.js" />
var UPDATE_STEP = 1300;
var ESTIMATION = 'estimation';
var SPENT = 'spent';
var REMAINING = 'remaining';
var g_bheader = {
//review: move g_spentTotal etc here
comboSEView: null,
hide: function () {
if (this.comboSEView)
this.comboSEView.hide();
}
};
var g_spentTotal = null;
var g_estimationTotal = null;
var g_remainingTotal = null;
var g_boardName = null;
var g_bUpdatingGlobalSums = null; //null means uninitialized. tracks if we are waiting for all trello cards to load
var g_manifestVersion = "";
var g_rgExcludedUsers = []; //users exluded from the S/E bar
var g_bDontShowSpentPopups = false;
var g_serViews = { board: { s: true, e: true, r: true }, list: { s: true, e: true, r: false }, card: { s: true, e: true, r: false } };
var g_verStore = ""; //only set when chrome calls us with an available update. might be outdated after update
function isTabVisible() {
return !(document.hidden || document.webkitHidden || document.msHidden || document.mozHidden);
}
document.addEventListener('visibilitychange', function () {
if (!isTabVisible())
return;
testExtension(function () {
if (g_bDidInitialIntervalsSetup && document.body) //once we got here without a body, so do some sanity checks for that timing issue
doAllUpdates(true);
});
});
function showModlessDialog(elem) {
if (!elem.show) {
dialogPolyfill.registerDialog(elem);
}
elem.show();
}
function showModalDialog(elem) {
if (!elem.show) {
dialogPolyfill.registerDialog(elem);
}
elem.showModal();
}
//insertCardTimer
//
function insertCardTimer(containerBar) {
tryInsert();
function tryInsert() {
if (!inserted())
setTimeout(tryInsert, 200);
}
function inserted() {
if (!g_bReadGlobalConfig)
return false;
var url = document.URL;
var idCardCur = getIdCardFromUrl(url);
if (!idCardCur)
return true;
var sidebars = $('[data-testid="card-back-name"]');
if (sidebars.length == 0)
return false;
var actions = sidebars.find($('[data-testid="card-back-copy-card-button"]')).first().parent();
if (actions.length == 0)
return false;
var divInsert = actions.parent();
if (divInsert.find($("#agile_timer")).size() != 0)
return true;
divInsert.prepend(loadCardTimer(idCardCur, containerBar));
return true;
}
}
var g_bErrorExtension = false;
function showExtensionUpgradedError(e, bNeedsBackgroundUpgrade) {
if (g_bErrorExtension)
return;
g_bErrorExtension = true;
var message = "";
//note: newer chrome no longer detects the "connecting to extension" error and instead throws a general "Cannot read property 'name' from Undefined" error.
if (e && e.message && !bIgnoreError(e.message))
message = e.message;
var divDialog = $("#agile_dialog_ExtensionUpgraded");
if (divDialog.length == 0) {
//focus on h2 so it doesnt go to the first link
divDialog = $('\
<dialog id="agile_dialog_ExtensionUpgraded" class="agile_dialog_DefaultStyle agile_dialog_Postit agile_dialog_Postit_Anim">\
<h3 tabindex="1" style="outline: none;">Chrome updated Plus for Trello</h3><br> \
<p>Reload to continue. <A href="http://www.plusfortrello.com/p/change-log.html" target="_blank">Whats new?</A></p> \
<p id="agile_dialog_ExtensionUpgraded_message"></p> \
<a href="" class="button-link agile_dialog_Postit_button" id="agile_dialog_ExtensionUpgraded_Refresh">Reload</a> \
<a title="Ignore to keep working on this page.\nSome Plus features may not work until you Reload." href="" class="button-link agile_dialog_Postit_button" id="agile_dialog_ExtensionUpgraded_Ignore">Ignore</a> \
</dialog>');
getDialogParent().append(divDialog);
divDialog = $("#agile_dialog_ExtensionUpgraded");
var imgReload = $("<img>").attr("src", chrome.extension.getURL("images/reloadchrome.png")).addClass('agile_reload_ext_button_img');
var reload = divDialog.find("#agile_dialog_ExtensionUpgraded_Refresh");
reload.append($("<span>").append(imgReload));
var bOnReload = false;
reload.off("click.plusForTrello").on("click.plusForTrello", function (e) {
e.preventDefault();
if (bOnReload)
return; //extra reentry safety
bOnReload = true;
setTimeout(function () { //timeout so the button reacts to the click uxwise
if (bNeedsBackgroundUpgrade) {
reload.text("Installing...");
reload.prop('disabled', true);
sendExtensionMessage({ method: "reloadExtension" }, function (response) {
//do nothing. we catch EXTENSION_RESTARTING and reload all trello windows
});
} else {
location.reload(); //note not passing false per http://stackoverflow.com/questions/16873263/load-from-cache-with-window-location-reload-and-hash-fragment-in-chrome-doesnt
}
}, 10);
});
divDialog.find("#agile_dialog_ExtensionUpgraded_Ignore").off("click.plusForTrello").on("click.plusForTrello", function (e) {
if (bNeedsBackgroundUpgrade)
localStorage.setItem(PROP_LS_MSLAST_IGNORE_EXTUPGRADE, Date.now());
e.preventDefault(); //link click would navigate otherwise
divDialog.removeClass("agile_dialog_Postit_Anim_ShiftToShow");
setTimeout(function () { divDialog[0].close(); }, 300+10); //wait for animation to complete
});
}
$("#agile_dialog_ExtensionUpgraded_message").text(message);
showModlessDialog(divDialog[0]);
setTimeout(function () { divDialog.addClass("agile_dialog_Postit_Anim_ShiftToShow"); }, 200); //some dialog conflict prevents animation from working without timeout
}
function showFirstLicDialog(bExpanded, bShowWSOption, callback) {
var divDialog = $("#agile_dialog_FirstLic");
if (divDialog.length == 0) {
//focus on h2 so it doesnt go to the first link
divDialog = $('\
<dialog id="agile_dialog_FirstLic" style="cursor:pointer;text-align: center;width:33em;padding-top:0.5em;" class="agile_dialog_DefaultStyle agile_dialog_Postit agile_dialog_Postit_Anim_Lic">\
<div id="agile_FirstLic_title" tabindex="1" style="outline: none; text-align: center;cursor:pointer;">Click here to activate your "Plus for Trello Pro" yearly license.</div> \
<div id="agile_FirstLic_content" style="display:none;"><br><b>"Plus for Trello Pro" yearly license</b><br>\
<br>\
<p >License activation is disabled until further notice.</p>\
<p style="display:none;">You will then have 7 days to try "Pro" without charges.</p>\
<p style="display:none;">Click "Activate" to enter payment details.</p><br>\
<a style="display:none;" href="" class="button-link agile_dialog_Postit_button" style="" id="agile_dialog_FirstLic_Cancel">Cancel</a><br>\
<br>\
<br>\
<div style="text-align: left;">\
<p style="display:none;"><a href="" id="agile_stripe_tellmore">Click here</a> to use Google Payments instead.</p>\
<div style="display:none;" id="agile_stripe_tellmore_content">\
<hr>\
<p>Or purchase a single license (your own) using Google Payments.</p>\
<p>Requires you use <A href="https://support.google.com/chrome/answer/185277" target="_blank">Chrome sign-in</A>.<\p>\
<p>This method is for a single license. To purchase a group license use the other method above (Stripe).</p>\
<a href="" class="button-link agile_dialog_Postit_button" id="agile_dialog_FirstLic_OKWebstore">Activate with the Google \"Chrome Web Store\"</a>\
</div>\
</div>\
<br>\
<span style="font-size:80%;color:#909090;float:left;">Note: <A href="http://www.plusfortrello.com" target="_blank" style="color:#909090;">Plus for Trello</A> is not associated with Trello or Atlassian.\
</span>\
<span style="float:right;">\<A href="\
https://translate.google.com.pe/?hl=en&sl=en&tl=es&text=License%20activation%20is%20disabled%20until%20further%20notice%0A%0ANote%3A%20%22Plus%20for%20Trello%22%20is%20not%20associated%20with%20%22Trello%22%20or%20%22Atlassian%22.%5C&op=translate" target="_blank">Translate</A></span>\
<span style="float:right;margin-right:1em;">\<A href="http://www.plusfortrello.com/p/plus-for-trello-pro-version.html" target="_blank">Help</A></span>\
<\div>\
</dialog>');
getDialogParent().append(divDialog);
divDialog = $("#agile_dialog_FirstLic");
}
function initDialog() {
divDialog.off("click.plusForTrello").on("click.plusForTrello", function (e) {
var content = divDialog.find("#agile_FirstLic_content");
if (content.is(":visible"))
return;
divDialog.find("#agile_FirstLic_title").hide();
divDialog.removeClass("agile_box_input_hilite");
content.slideDown(200);
});
function doCloseDialog(callbackBefore, callbackAfter) {
if (callbackBefore)
callbackBefore();
divDialog.removeClass("agile_dialog_Postit_Anim_ShiftToShow");
setTimeout(function () {
divDialog[0].close();
if (callbackAfter)
callbackAfter();
}, 300); //wait for animation to complete
}
var elemTellMore = divDialog.find("#agile_stripe_tellmore");
if (bShowWSOption) {
elemTellMore.off("click.plusForTrello").on("click.plusForTrello", function (e) {
e.preventDefault();
elemTellMore.parent().hide();
divDialog.find("#agile_stripe_tellmore_content").show();
});
} else {
elemTellMore.parent().hide();
divDialog.find("#agile_stripe_tellmore_content").hide();
}
divDialog.find("#agile_dialog_FirstLic_OKWebstore").off("click.plusForTrello").on("click.plusForTrello", function (e) {
e.preventDefault();
doCloseDialog(function () {
callback(STATUS_OK, false);
});
});
divDialog.find("#agile_dialog_FirstLic_OK").off("click.plusForTrello").on("click.plusForTrello", function (e) {
e.preventDefault();
doCloseDialog(function () {
callback(STATUS_OK, true);
});
});
var bOvertime = false;
if (g_msStartPro && (Date.now() - g_msStartPro > 1000 * 60 * 60 * 24 * 3)) {
bOvertime = true;
}
divDialog.find("#agile_dialog_FirstLic_Cancel").off("click.plusForTrello").on("click.plusForTrello", function (e) {
e.preventDefault(); //link click would navigate otherwise
doCloseDialog(function () {
if (bOvertime)
setTimeout(function () {
sendDesktopNotification("If you do not wish to activate please turn off 'Pro' from the Plus Help pane.",10000);
}, 1000);
callback("cancel");
});
});
if (bOvertime || bExpanded) {
divDialog.find("#agile_FirstLic_title").hide();
divDialog.find("#agile_FirstLic_content").show();
} else {
divDialog.find("#agile_FirstLic_title").show();
divDialog.find("#agile_FirstLic_content").hide();
hiliteOnce(divDialog, 3000);
}
}
initDialog();
showModlessDialog(divDialog[0]);
//divDialog.find("#agile_dialog_FirstLic_OK").focus();
setTimeout(function () { divDialog.addClass("agile_dialog_Postit_Anim_ShiftToShow"); }, 200); //some dialog conflict prevents animation from working without timeout
}
function showTryProDialog(bHilite, callback) {
var divDialog = $("#agile_dialog_TryPro");
function doCloseDialog(callbackAfter) {
divDialog.removeClass("agile_dialog_Postit_Anim_ShiftToShow");
setTimeout(function () {
divDialog[0].close();
if (callbackAfter)
callbackAfter();
}, 300); //wait for animation to complete
}
if (divDialog.length == 0) {
//focus on h2 so it doesnt go to the first link
divDialog = $('\
<dialog id="agile_dialog_TryPro" style="cursor:pointer;padding-bottom:6px;padding-top:6px;text-align: center;width:21em;" class="agile_dialog_DefaultStyle agile_dialog_Postit agile_dialog_Postit_Anim_TryPro">\
<div tabindex="1" style="outline: none;cursor:pointer;margin-top:0em;"><span>Try Plus for Trello "Pro" for free</span> \
<button style="display:inline-block;padding:0;margin-left:1em;margin-top:0;margin-bottom:0;width:3em;min-height:0.5em;">OK</button> \
<img style="padding:3px;margin-left:0.5em;margin-bottom:-7px;" src="' + chrome.extension.getURL("images/close.png") + '"></img></div> \
</dialog>');
getDialogParent().append(divDialog);
divDialog = $("#agile_dialog_TryPro");
if (bHilite) {
setTimeout(function () {
hiliteOnce(divDialog, 2000);
}, 1000);
}
divDialog.find("img").click(function (e) {
e.stopPropagation();
e.preventDefault();
doCloseDialog(function () {
callback(false);
});
return false;
});
divDialog.click(function (e) {
doCloseDialog(function () {
callback(true);
});
});
}
showModlessDialog(divDialog[0]);
setTimeout(function () { divDialog.addClass("agile_dialog_Postit_Anim_ShiftToShow"); }, 200); //some dialog conflict prevents animation from working without timeout
if (!g_bForceShowTry) {
setTimeout(function () {
if (divDialog.hasClass("agile_dialog_Postit_Anim_ShiftToShow")) { //class indicates we havent started anim&close process
g_bShowedTryPro = false; //pretend not showed so we try later
doCloseDialog();
}
}, 15000);
}
}
function showTryNoSEDialog(callback) {
if (!callback)
callback = function () { };
var divDialog = $("#agile_dialog_tryNoSE");
function doCloseDialog(callbackAfter) {
divDialog.removeClass("agile_dialog_Postit_Anim_ShiftToShow");
setTimeout(function () {
divDialog[0].close();
if (callbackAfter)
callbackAfter();
}, 300); //wait for animation to complete
}
if (divDialog.length == 0) {
divDialog = $('\
<dialog id="agile_dialog_tryNoSE" style="cursor:pointer;padding-bottom:6px;padding-top:6px;text-align: center;width:37em;" class="agile_dialog_DefaultStyle agile_dialog_Postit agile_dialog_Postit_Anim_TryPro">\
<div tabindex="1" style="outline: none;cursor:pointer;margin-top:0em;"><span>Hi! Seems you are not using Plus for Trello Spent or Estimates. <A href="http://www.plusfortrello.com/p/new-features-for-those-not-using-time.html" target="_blank"> Learn more</A></span> \
<img style="padding:3px;margin-left:0.5em;margin-bottom:-7px;" src="' + chrome.extension.getURL("images/close.png") + '"></img></div> \
</dialog>');
getDialogParent().append(divDialog);
divDialog = $("#agile_dialog_tryNoSE");
divDialog.find("img").click(function (e) {
e.stopPropagation();
e.preventDefault();
doCloseDialog(function () {
callback(false);
});
return false;
});
}
showModlessDialog(divDialog[0]);
setTimeout(function () { divDialog.addClass("agile_dialog_Postit_Anim_ShiftToShow"); }, 200); //some dialog conflict prevents animation from working without timeout
}
function showFatalError(message) {
if (g_bErrorExtension)
return;
g_bErrorExtension = true;
var divDialog = $("#agile_dialog_FatalError");
if (divDialog.length == 0) {
divDialog = $('\
<dialog id="agile_dialog_FatalError" class="agile_dialog_DefaultStyle agile_dialog_Postit"> \
<h3>Plus for Trello error</h3>\
<p id="agile_dialog_FatalError_message"></p> \
<A id="agile_dialog_FatalError_ViewLog" href="" target="_blank">View error log</A> \
<a style="float:right;" href="" class="button-link agile_dialog_Postit_button" id="agile_dialog_FatalError_Ignore">Ignore</a> \
</dialog>');
getDialogParent().append(divDialog);
divDialog = $("#agile_dialog_FatalError");
divDialog.find("#agile_dialog_FatalError_ViewLog").prop("href", chrome.extension.getURL("plusmessages.html"));
divDialog.find("#agile_dialog_FatalError_Ignore").off("click.plusForTrello").on("click.plusForTrello", function (e) {
e.preventDefault(); //link click would navigate otherwise
divDialog[0].close();
});
}
$("#agile_dialog_FatalError_message").text(message);
showModlessDialog(divDialog[0]);
}
function testExtension(callback) {
if (g_bErrorExtension)
return;
try {
var rgLog = g_plusLogMessages;
sendExtensionMessage({ method: "testBackgroundPage", logMessages: rgLog },
function (response) {
if (response.status == STATUS_OK) { //status of log write
g_plusLogMessages = [];
}
if (callback)
callback();
}, true); //true to rethrow exceptions
} catch (e) {
showExtensionUpgradedError(e);
}
}
function loadExtensionVersion(callback) {
if (g_manifestVersion != "")
return;
g_manifestVersion = "unknown"; //prevent loading again and handle error case
sendExtensionMessage({ method: "getManifestVersion"}, function (response) {
if (response.status!= STATUS_OK)
return;
g_manifestVersion = response.version;
callback();
});
}
function newerStoreVersion(bUrgentOnly) {
var bNeedUpgrade = false;
if (g_verStore && g_verStore != g_manifestVersion) {
var partsCurrent = g_manifestVersion.split(".");
var partsStore = g_verStore.split(".");
var vCur;
var vStore;
if (partsStore.length != partsCurrent.length) {
//this shouldnt happent, but protect anyway
bNeedUpgrade = false; //to prevent possible endless loop
}
else {
for (var iPartsVersion = 0; iPartsVersion < partsStore.length; iPartsVersion++) {
vCur = parseInt(partsCurrent[iPartsVersion], 10);
vStore = parseInt(partsStore[iPartsVersion], 10);
if (vCur > vStore)
break;
if (vStore > vCur)
bNeedUpgrade = true;
if (bNeedUpgrade && bUrgentOnly && iPartsVersion == partsStore.length-1) {
bNeedUpgrade = (vStore > 90); //overwrite previous. 90+ is a special emergency value to force update
}
}
}
}
return bNeedUpgrade;
}
function handleIframeLoad() {
var url = document.URL.toLowerCase();
if (url.indexOf("https://trello.com/embed/card?") == 0) {
checkTitle();
function checkTitle() {
//send the title to the iframe parent
var title = document.title;
if (!title)
setInterval(checkTitle, 200);
else {
window.parent.postMessage({
type: 'trello_card_title',
title: title
},
'*' /* targetOrigin: any */);
}
}
}
}
$(function () {
loadExtensionVersion(function () {
setTimeout(function () { //in timeout so we can safely reference globals and give a little time for trello load itself since we "run_at": "document_start"
var bInIFrame = (window != window.top);
setTrelloAuth(null, bInIFrame); //do this earliest
if (bInIFrame) {
//Note: sometimes background loads trello in an iframe (when trello authentication fails, dsc token is expired)
handleIframeLoad();
return;
}
setInterval(setTrelloAuth, 10000); //review: why again? retry?
//$(document).tooltip(); //review this breaks when closing a window with ESC, tooltip stays up and its hard to clean up
//http://tablesorter.com/docs/example-parsers.html
//http://stackoverflow.com/a/2129479/2213940
addTableSorterParsers();
loadOptions(function () {
entryPoint();
});
}, 600); //"run_at": "document_start" is before trello does ajax so breathe and dont compete with trello load
});
});
var g_dscTrello = null;
function setTrelloAuth(callback, bInFrame) {
var dscNew = $.cookie("dsc");
if (dscNew && dscNew != g_dscTrello) {
g_dscTrello = dscNew;
sendExtensionMessage({ method: "setTrelloAuthData", dsc: dscNew, bInFrame: bInFrame }, function () {
if (callback)
setTimeout(callback,1); //prevent recursing from message callback
});
} else if (callback) {
callback();
}
}
function entryPoint() {
g_waiterLi.SetWaiting(true);
//note: this also does setInterval on the callback which we use to do sanity checks and housekeeping
setCallbackPostLogMessage(testExtensionAndcommitPendingPlusMessages); //this allows all logs (logPlusError, logException) to be written to the database
HelpButton.display(); //inside is where the fun begins
checkEnableMoses();
}
//review zig: merge with loadSharedOptions / loadStorageGlobals
function loadOptions(callback) {
var keyDisplayPointUnits = "bDisplayPointUnits";
var keyAllowNegativeRemaining = "bIgnoreZeroECards";
var keyPreventIncreasedE = "bPreventEstMod";
var keyDontWarnParallelTimers = "bDontWarnParallelTimers";
var keyAcceptSFT = "bAcceptSFT";
var keyAcceptPFTLegacy = "bAcceptPFTLegacy";
var keyAlreadyDonated = "bUserSaysDonated";
var keyHidePendingCards = "bHidePendingCards";
var keyAlwaysShowSEBar = "bAlwaysShowSEBar";
var keyUseLastSEBarUser = "bUseLastSEBarUser";
var keyHideLessMore = "bHideLessMore";
var keyDowStart = "dowStart";
var keyDowDelta = "dowDelta";
var keySyncOutsideTrello = "bSyncOutsideTrello";
var keybChangeCardColor = "bChangeCardColor";
var keybHideTour = "bHideTour";
var keyPropbSumFilteredCardsOnly = "bSumFilteredCardsOnly";
var keybEnableTrelloSync = "bEnableTrelloSync";
var keybEnterSEByCardComments = "bEnterSEByCardComments";
var keyrgKeywordsforSECardComment = "rgKWFCC";
var keyrgExcludedUsers = "rgExcludedUsers";
var keyUnits = "units";
var keyCheckedTrelloSyncEnable = "bCheckedTrelloSyncEnable";
var keybDisabledSync = "bDisabledSync"; //note this takes precedence over bEnableTrelloSync or g_strServiceUrl 'serviceUrl'
var keyClosePlusHomeSection = "bClosePlusHomeSection";
var keybDontShowTimerPopups = "bDontShowTimerPopups";
var keybDontShowSpentPopups = "bDontShowSpentPopups";
var keyServiceUrl = 'serviceUrl'; //note we only get but not set. Code later will set it
function BLastErrorDetected() {
if (chrome.runtime.lastError) {
sendDesktopNotification("Plus for Trello cannot load\n" + chrome.runtime.lastError.message, 20000);
return true;
}
return false;
}
//get options from sync
chrome.storage.sync.get([SYNCPROP_NO_EST, SYNCPROP_NO_SE, SYNCPROP_SERVIEWS, SYNCPROP_KEYWORDS_HOME, keyDisplayPointUnits, SYNCPROP_GLOBALUSER, SYNCPROP_BOARD_DIMENSION, SYNCPROP_bStealthSEMode, SYNCPROP_language, keyServiceUrl, keybDontShowTimerPopups, keybDontShowSpentPopups, keyClosePlusHomeSection, keyDontWarnParallelTimers, keyUnits,
keyrgExcludedUsers, keyrgKeywordsforSECardComment, keyAcceptSFT, keyHideLessMore,
keyAcceptPFTLegacy, keybEnterSEByCardComments, SYNCPROP_optAlwaysShowSpentChromeIcon, keyAllowNegativeRemaining,keyPreventIncreasedE, keyAlreadyDonated, keybEnableTrelloSync,
keyCheckedTrelloSyncEnable, keyHidePendingCards, keyAlwaysShowSEBar, keyUseLastSEBarUser, keyDowStart, keyDowDelta, SYNCPROP_MSSTARTPLUSUSAGE, keySyncOutsideTrello, keybHideTour,
keybChangeCardColor, keyPropbSumFilteredCardsOnly, keybDisabledSync],
function (objSync) {
if (BLastErrorDetected())
return;
try {
g_rgKeywordsHome = JSON.parse(objSync[SYNCPROP_KEYWORDS_HOME] || "[]");
} catch (e) {
logException(e);
}
g_bNoSE = objSync[SYNCPROP_NO_SE] || false;
g_bNoEst = objSync[SYNCPROP_NO_EST] || false;
g_serViews = (objSync[SYNCPROP_SERVIEWS] || g_serViews);
g_globalUser = objSync[SYNCPROP_GLOBALUSER] || DEFAULTGLOBAL_USER;
g_dimension = objSync[SYNCPROP_BOARD_DIMENSION] || VAL_COMBOVIEWKW_ALL;
g_language = objSync[SYNCPROP_language] || "en";
g_bDontShowTimerPopups = objSync[keybDontShowTimerPopups] || false;
g_bDontShowSpentPopups = objSync[keybDontShowSpentPopups] || false;
g_bShowHomePlusSections = !(objSync[keyClosePlusHomeSection] || false) && !g_bNoSE;
UNITS.current = objSync[keyUnits] || UNITS.current;
g_bDontWarnParallelTimers = objSync[keyDontWarnParallelTimers] || false;
g_bEnableTrelloSync = objSync[keybEnableTrelloSync] || false;
g_bCheckedTrelloSyncEnable = objSync[keyCheckedTrelloSyncEnable] || false;
g_optEnterSEByComment.loadFromStrings(objSync[keybEnterSEByCardComments], objSync[keyrgKeywordsforSECardComment]);
g_rgExcludedUsers = JSON.parse(objSync[keyrgExcludedUsers] || "[]");
g_bDisableSync = objSync[keybDisabledSync] || false;
g_bUserDonated = objSync[keyAlreadyDonated] || false;
g_msStartPlusUsage = objSync[SYNCPROP_MSSTARTPLUSUSAGE] || null; //later we will try to initialize it when null, but may remain null
g_bHidePendingCards = objSync[keyHidePendingCards] || false;
g_bAlwaysShowSEBar = objSync[keyAlwaysShowSEBar] || false;
g_bUseLastSEBarUser = objSync[keyUseLastSEBarUser] || false;
g_bHideLessMore = objSync[keyHideLessMore] || false;
setOptAlwaysShowSpentChromeIcon(objSync[SYNCPROP_optAlwaysShowSpentChromeIcon]);
DowMapper.setDowStart(objSync[keyDowStart] || DowMapper.DOWSTART_DEFAULT, objSync[keyDowDelta] || 0);
g_bAcceptSFT = objSync[keyAcceptSFT];
if (g_bAcceptSFT === undefined)
g_bAcceptSFT = true;
g_bAcceptPFTLegacy = objSync[keyAcceptPFTLegacy];
if (g_bAcceptPFTLegacy === undefined)
g_bAcceptPFTLegacy = true; //defaults to true to not break legacy users
g_bDisplayPointUnits = objSync[keyDisplayPointUnits] || false;
g_bAllowNegativeRemaining = objSync[keyAllowNegativeRemaining] || false;
g_bPreventIncreasedE = objSync[keyPreventIncreasedE] || false;
g_bStealthSEMode = (objSync[SYNCPROP_bStealthSEMode] && objSync[keyServiceUrl] && !g_bDisableSync) ? true : false;
g_bSyncOutsideTrello = objSync[keySyncOutsideTrello] || false;
g_bChangeCardColor = objSync[keybChangeCardColor] || false;
g_bHideTour = objSync[keybHideTour] || false;
g_bCheckedbSumFiltered = objSync[keyPropbSumFilteredCardsOnly] || false;
//alert("g_bEnableTrelloSync : " + g_bEnableTrelloSync + "\ncomments sync : " + g_optEnterSEByComment.bEnabled + "\ndisabled sync : " + g_bDisableSync);
chrome.storage.local.get([LOCALPROP_PRO_VERSION, LOCALPROP_PRO_MSDATEENABLED, LOCALPROP_EXTENSION_VERSIONSTORE], function (obj) {
if (BLastErrorDetected())
return;
g_verStore = obj[LOCALPROP_EXTENSION_VERSIONSTORE] || "";
g_bProVersion = obj[LOCALPROP_PRO_VERSION] || false;
g_msStartPro = obj[LOCALPROP_PRO_MSDATEENABLED] || 0;
if (!g_bProVersion || g_msStartPro > 0)
callback();
else {
//fix g_msStartPro
setProVersionOption(g_bProVersion, function () {
callback();
});
}
});
});
}
var g_msLastAllUpdatesInterval = 0;
function doAllUpdates(bFromInterval) {
if (bFromInterval) {
var msNow = Date.now();
if (msNow - g_msLastAllUpdatesInterval < UPDATE_STEP * 0.8)
return; //prevent frequent calls (we pretend bFromInterval in some situations)
g_msLastAllUpdatesInterval = msNow;
}
//note: this mostly helps for testing during development, so the setting can be changed from
//one chrome tab as you watch another chrome tab with plus help and validate test scenarios
chrome.storage.sync.get([SYNCPROP_NO_SE, SYNCPROP_NO_EST], function (obj) {
var bNoSE = obj[SYNCPROP_NO_SE];
var bNoEst = obj[SYNCPROP_NO_EST];
if ((!bNoSE != !g_bNoSE) || (!bNoEst != !g_bNoEst)) {
g_bNoSE = bNoSE;
g_bNoEst = bNoEst;
showHideSEFeatures();
}
});
var url = document.URL;
var urlLower = url.toLowerCase();
var idCard = getIdCardFromUrl(url);
if (idCard)
sendExtensionMessage({ method: "notifyCardTab", idCard: idCard }, function (response) { });
else {
var idBoard = getIdBoardFromUrl(url);
if (idBoard) {
sendExtensionMessage({ method: "notifyBoardTab", idBoard: idBoard }, function (response) { });
var pftSettings = $(".agile-pft-boardsettings");
if (pftSettings.length == 0) {
var boardmenu = $(".board-menu");
if (boardmenu.length > 0) {
var settingsIcon = $(".board-menu-navigation-item .icon-share");
if (settingsIcon.length > 0 && settingsIcon.is(":visible")) {
var boardmenumav = $(".board-menu-navigation");
if (boardmenumav.length > 0) {
boardmenumav = boardmenumav.eq(boardmenumav.length>1?1:0);
pftSettings = $("<A class='agile-pft-boardsettings board-menu-navigation-item-link' href=''>'Plus' Help & Settings</A>");
var pftIcon = $("<A class='agile-pft-boardsettings-icon board-menu-navigation-item-link-icon'>");
pftSettings.append(pftIcon);
pftSettings.insertAfter(boardmenumav);
pftSettings.click(function () {
Help.display();
});
}
}
}
}
}
}
if (bFromInterval && !isTabVisible())
return;
markForUpdate();
if (isPlusDisplayDisabled())
return;
if (g_delayedActions.bPendingWeeklyReport)
doWeeklyReport(g_configData, getCurrentTrelloUser(), false, true);
addCardCommentHelp();
var strDetectLicense = "https://trello.com/"+URLPART_PLUSLICENSE+"/";
if (url.indexOf(strDetectLicense) == 0) {
var liData = (url.slice(strDetectLicense.length) || "").split("/");
if (liData.length == 2) {
var userOwner = liData[0];
var idSub = liData[1];
handlePlusLicenseUrl(userOwner, idSub);
}
}
else if (urlLower.indexOf("https://trello.com/plus-emergency-settings")==0) {
var linkReset = $("#plusEmergencyReset");
var elemDetect = $(".big-message h1");
if (linkReset.length == 0 && elemDetect.length > 0) {
elemDetect.text("");
$(".big-message p").text("");
linkReset = $("<button id='plusEmergencyReset'>Plus emergency 'Reset Sync'</button>");
$("#content").append(linkReset);
linkReset = $("#plusEmergencyReset");
linkReset.click(function (e) {
e.preventDefault();
ResetPlus();
});
var linkPlusHelpPane = $("<br><button >Show the Plus help pane</button>");
$("#content").append(linkPlusHelpPane);
linkPlusHelpPane.click(function (e) {
e.preventDefault();
Help.display();
return false;
});
}
}
}
var g_globalTotalSpent = null; //used to detect changes on global spent
var g_globalTotalEstimation = null; //used to detect changes on global est
var g_strPageHtmlLast = "";
var g_bNeedsUpdate = false;
/* markForUpdate
*
* Waits until changes stabilize to make an update
**/
function markForUpdate() {
var strPageHtml = document.body.innerHTML;
if (!g_bForceUpdate && strPageHtml != g_strPageHtmlLast) {
g_bNeedsUpdate = true;
g_strPageHtmlLast = strPageHtml;
} else if (g_bNeedsUpdate || g_bForceUpdate) {
g_strPageHtmlLast = strPageHtml;
update(true);
}
}
var g_bForceUpdate = false;
function update(bShowBoardTotals) {
updateWorker(bShowBoardTotals);
}
function updateSsLinksDetector(globalTotalSpent, globalTotalEstimation) {
var user = getCurrentTrelloUser();
if (user != null && globalTotalSpent == g_globalTotalSpent && globalTotalEstimation == g_globalTotalEstimation)
updateSsLinks();
else {
var gTSLocal = g_globalTotalSpent;
var gTELocal = g_globalTotalEstimation;
setTimeout(function () { updateSsLinksDetector(gTSLocal, gTELocal); }, 500); //try later until it stabilizes
}
}
function ResetPlus() {
findAllActiveTimers(function (rgTimers) {
var strConfirm = 'Are you sure you want to Reset?';
if (rgTimers.length>1)
strConfirm = strConfirm + ' Multiple active timers (except the active timer) will be lost.';
if (!confirm(strConfirm))
return;
sendExtensionMessage({ method: "detectLegacyHistoryRows" },
function (response) {
if (response.hasLegacyRows) {
if (g_optEnterSEByComment.IsEnabled() && !g_optEnterSEByComment.hasLegacyKeyword()) {
if (!confirm("The legacy keyword 'Plus S/E' is missing from your keywords, thus Plus will not be able to read your legacy rows.\nAre you sure you want to Reset?"))
return;
}
}
sendExtensionMessage({ method: "isSyncing" },
function (response) {
if (response.status != STATUS_OK) {
alert(response.status);
return;
}
if (response.bSyncing) {
//note: this isnt perfect but will cover many concurrency cases
if (!confirm("Plus is currently syncing.\nYou should press Cancel unless Plus is stuck in this state.\nAre you sure you want to reset?"))
return;
}
sendExtensionMessage({ method: "getTotalDBRowsNotSync" },
function (response) {
if (response.status != STATUS_OK) {
alert(response.status);
return;
}
if (response.cRowsTotal > 0 && (g_bDisableSync || !g_optEnterSEByComment.IsEnabled())) { //review newsync
if (!g_optEnterSEByComment.IsEnabled() && g_strServiceUrl && g_strServiceUrl.length > 0) {
if (!confirm("You have pending S/E rows that havent synced yet to the spreadsheet. Are you sure you want to lose those rows?"))
return;
}
else if (!confirm("Sync is not enabled. S/E rows wont come back until you do so.'\nAre you sure you want to reset now?"))
return;
}
clearAllStorage(function () {
restartPlus("All local data cleared. Refreshing to start sync...");
});
});
});
});
});
}