11
11
// @include /^https?://www\.geocaching\.com/my/recentlyviewedcaches\./
12
12
// @include /^https?://www\.geocaching\.com/(map/|geocache/)/
13
13
// @include /^https?://www\.geocaching\.com/plan/lists/
14
- // @include /^https?://www\.opencaching\.de/viewcache.php/
14
+ // @include /^https?://www\.geocaching\.com/account/dashboard/
15
+ // @include /^https?://www\.opencaching\.de/(viewcache|myhome).php/
15
16
// @icon https://send2.cgeo.org/send2cgeo.png
16
17
// @downloadURL https://github.com/cgeo/send2cgeo/raw/release/send2cgeo.user.js
17
18
// @updateURL https://github.com/cgeo/send2cgeo/raw/release/send2cgeo.user.js
18
19
// @supportURL https://github.com/cgeo/send2cgeo/issues
19
20
// @version 0.51
21
+ // @grant GM_setValue
22
+ // @grant GM_getValue
20
23
// ==/UserScript==
21
24
22
25
// Function that handles the actual sending
@@ -25,20 +28,29 @@ var s2cgScript = document.createElement('script');
25
28
s2cgScript . type = 'text/javascript' ;
26
29
s2cgScript . innerHTML = 'window.s2geo = function(GCCode) {'
27
30
// show the box and the "please wait" text
28
- + '$("#send2cgeo, #send2cgeo div").fadeIn();'
29
- // hide iframe for now and wait for page to be loaded
30
- + '$("#send2cgeo iframe")'
31
- + ' .hide()'
32
- + ' .off("load")'
33
- + ' .attr("src", "https://send2.cgeo.org/add.html?cache=" + GCCode)'
34
- + ' .on("load",'
35
- + ' function() {'
36
- // hide "please wait text" and show iframe
37
- + ' $("#send2cgeo div").hide();'
38
- // hide box after 3 seconds
39
- + ' $(this).css("display", "block").parent().delay(3000).fadeOut();'
40
- + ' }'
41
- + ' );'
31
+ + ( isUsePopUpWindow ( )
32
+ ? " var sendCache = window.open('https://send2.cgeo.org/add.html?cache=' + GCCode, 'send' + GCCode, 'width=200,height=100,top=10,left=10,menubar=no,status=no');"
33
+ + ' window.setTimeout('
34
+ + ' function() {'
35
+ + ' sendCache.close();'
36
+ + ' },'
37
+ + ' 3000'
38
+ + ' )'
39
+ : '$("#send2cgeo, #send2cgeo div").fadeIn();'
40
+ // hide iframe for now and wait for page to be loaded
41
+ + '$("#send2cgeo iframe")'
42
+ + ' .hide()'
43
+ + ' .off("load")'
44
+ + ' .attr("src", "https://send2.cgeo.org/add.html?cache=" + GCCode)'
45
+ + ' .on("load",'
46
+ + ' function() {'
47
+ // hide "please wait text" and show iframe
48
+ + ' $("#send2cgeo div").hide();'
49
+ // hide box after 3 seconds
50
+ + ' $(this).css("display", "block").parent().delay(3000).fadeOut();'
51
+ + ' }'
52
+ + ' );'
53
+ )
42
54
+ '};' ;
43
55
44
56
document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( s2cgScript ) ;
@@ -147,6 +159,10 @@ var start = function(c) {
147
159
} ) ;
148
160
} ;
149
161
162
+ function isUsePopUpWindow ( ) {
163
+ return GM_getValue ( 'usePopUpWindow' , false ) ;
164
+ }
165
+
150
166
function s2cgGCMain ( ) {
151
167
// check for premium membership (parts of the page content are different)
152
168
function premiumCheck ( ) {
@@ -307,21 +323,50 @@ function s2cgGCMain() {
307
323
$ ( anchorElement ) . append ( html ) ;
308
324
309
325
$ ( '#s2cg-' + GCCode ) . on ( 'click' , function ( ) {
310
- // show the box and the "please wait" text
311
- $ ( "#send2cgeo, #send2cgeo div" ) . fadeIn ( ) ;
312
- // hide iframe for now and wait for page to be loaded
313
- $ ( "#send2cgeo iframe" )
314
- . hide ( )
315
- . off ( "load" )
316
- . attr ( "src" , "https://send2.cgeo.org/add.html?cache=" + GCCode )
317
- . on ( "load" ,
326
+ if ( isUsePopUpWindow ( ) ) {
327
+ var sendCache = window . open ( 'https://send2.cgeo.org/add.html?cache=' + GCCode , 'send' + GCCode , 'width=200,height=100,top=10,left=10,menubar=no,status=no' ) ;
328
+ window . setTimeout (
318
329
function ( ) {
319
- // hide "please wait text" and show iframe
320
- $ ( "#send2cgeo div" ) . hide ( ) ;
321
- // hide box after 3 seconds
322
- $ ( this ) . css ( "display" , "block" ) . parent ( ) . delay ( 3000 ) . fadeOut ( ) ;
323
- }
330
+ sendCache . close ( ) ;
331
+ } ,
332
+ 3000
324
333
) ;
334
+ /* $(sendCache.document).ready(function () {
335
+ function checkForContent(waitCount) {
336
+ if ($(sendCache.document).contents().find('body').html() != '') {
337
+ var body = $(sendCache.document).contents().find('body').html();
338
+ console.log(body);
339
+ } else {
340
+ waitCount++;
341
+ if (waitCount <= 200) {
342
+ setTimeout(
343
+ function() {
344
+ checkForContent(waitCount);
345
+ },
346
+ 50
347
+ );
348
+ }
349
+ }
350
+ }
351
+ checkForContent(0);
352
+ });*/
353
+ } else {
354
+ // show the box and the "please wait" text
355
+ $ ( "#send2cgeo, #send2cgeo div" ) . fadeIn ( ) ;
356
+ // hide iframe for now and wait for page to be loaded
357
+ $ ( "#send2cgeo iframe" )
358
+ . hide ( )
359
+ . off ( "load" )
360
+ . attr ( "src" , "https://send2.cgeo.org/add.html?cache=" + GCCode )
361
+ . on ( "load" ,
362
+ function ( ) {
363
+ // hide "please wait text" and show iframe
364
+ $ ( "#send2cgeo div" ) . hide ( ) ;
365
+ // hide box after 3 seconds
366
+ $ ( this ) . css ( "display" , "block" ) . parent ( ) . delay ( 3000 ) . fadeOut ( ) ;
367
+ }
368
+ ) ;
369
+ }
325
370
} ) ;
326
371
}
327
372
@@ -342,6 +387,7 @@ function s2cgGCMain() {
342
387
+ '<iframe style="' + iframeStyle + '"></iframe>'
343
388
+ '</div>' ) ;
344
389
390
+ // This function add the send2cgeo buttons on geocaching.com
345
391
// Send to c:geo on browsemap (old map)
346
392
if ( document . location . href . match ( / \. c o m \/ m a p / ) ) {
347
393
var template = $ ( "#cacheDetailsTemplate" ) . html ( ) ;
@@ -583,6 +629,138 @@ function s2cgGCMain() {
583
629
584
630
oc . innerHTML = oc . innerHTML . replace ( '</p>' , html ) ;
585
631
}
632
+
633
+ // This will add settings
634
+ function save_settings ( ) {
635
+ GM_setValue ( 'usePopUpWindow' , $ ( '#usePopUpWindow' ) . is ( ':checked' ) ) ;
636
+ }
637
+
638
+ var settingsHTML = '<div id="send2cgeo_settings" style="display:none;">'
639
+ + ' <div id="s2cg_settings_content">'
640
+ + ' <p>If third party cookies are not allowed, the script will not work. This can be avoided by displaying send2cgeo in a popup window.</p>'
641
+ + ' <div class="toggle">'
642
+ + ' <label>Use send2cgeo with a popup window'
643
+ + ' <input type="checkbox" id="usePopUpWindow"' + ( isUsePopUpWindow ( ) ? ' checked' : '' ) + '><span class="slider"></span>'
644
+ + ' </label>'
645
+ + ' </div>'
646
+ + ' <input type="button" id="send2cgeo_settings_submit" value="Save">'
647
+ + ' </div>'
648
+ + '</div>' ;
649
+
650
+ var settingsCSS = '#send2cgeo_settings {'
651
+ + ' position: fixed;'
652
+ + ' background: rgba(31, 31, 31, .7);'
653
+ + ' top: 0;'
654
+ + ' left: 0;'
655
+ + ' width: 100%;'
656
+ + ' height: 100%;'
657
+ + ' z-index: 1111;'
658
+ + ' color: #fff;'
659
+ + '}'
660
+
661
+ + '#s2cg_settings_content {'
662
+ + ' position: absolute;'
663
+ + ' top: 50%;'
664
+ + ' left: 50%;'
665
+ + ' -webkit-transform: translate(-50%, -50%);'
666
+ + ' -ms-transform: translate(-50%, -50%);'
667
+ + ' transform: translate(-50%, -50%);'
668
+ + ' background: rgba(31, 31, 31, 1);'
669
+ + ' padding: 1em;'
670
+ + ' border-radius: 1em;'
671
+ + '}'
672
+
673
+ + '#s2cg_settings_content p, .toggle label, #send2cgeo_settings_submit {'
674
+ + ' font-size: ' + ( document . location . href . match ( / \. d e \/ m y h o m e \. p h p / ) ? '1.5' : '1' ) + 'em !important;'
675
+ + '}'
676
+
677
+ + '#send2cgeo_settings_submit {'
678
+ + ' margin-top: 1em;'
679
+ + ' color: rgba(31, 31, 31, 1);'
680
+ + ' border-radius: 5px;'
681
+ + ' cursor: pointer;'
682
+ + ' padding: 0 8px;'
683
+ + '}'
684
+
685
+ + '.toggle {'
686
+ + ' padding-left: 1em;'
687
+ + '}'
688
+
689
+ + '.toggle label {'
690
+ + ' position: relative;'
691
+ + ' display: inline-block;'
692
+ + ' text-transform: none;'
693
+ + '}'
694
+
695
+ + '.toggle input {'
696
+ + ' display: none;'
697
+ + '}'
698
+
699
+ + '.toggle .slider {'
700
+ + ' position: absolute;'
701
+ + ' cursor: pointer;'
702
+ + ' margin-left: .5em;'
703
+ + ' width: 2em;'
704
+ + ' height: 1em;'
705
+ + ' background: #c32e04; /* red */'
706
+ + ' transition: all .3s ease-in-out;'
707
+ + ' border-radius: 1em;'
708
+ + '}'
709
+
710
+ + '.toggle .slider:before {'
711
+ + ' position: absolute;'
712
+ + ' content: "";'
713
+ + ' height: .6em;'
714
+ + ' width: .6em;'
715
+ + ' left: .2em;'
716
+ + ' bottom: .2em;'
717
+ + ' background: white;'
718
+ + ' border-radius: 50%;'
719
+ + ' transition: all .3s ease-in-out;'
720
+ + '}'
721
+
722
+ + '.toggle input:checked + .slider {'
723
+ + ' background: #5a9900; /* green */'
724
+ + '}'
725
+
726
+ + '.toggle input:checked + .slider:before {'
727
+ + ' -webkit-transform: translateX(1em);'
728
+ + ' -ms-transform: translateX(1em);'
729
+ + ' transform: translateX(1em);'
730
+ + '}' ;
731
+
732
+ // geocaching.com
733
+ if ( document . location . href . match ( / \. c o m \/ a c c o u n t \/ d a s h b o a r d / ) ) {
734
+ $ ( 'head' ) . append ( '<style>' + settingsCSS + '</style>' ) ;
735
+ $ ( 'body' ) . append ( settingsHTML ) ;
736
+ $ ( '.bio-meta' ) . append ( '<a id="s2cg_openSettings" href="javascript:void(0)" style="display:block;">Send2cgeo Settings</a>' ) ;
737
+ $ ( '#send2cgeo_settings_submit' ) . on ( 'click' , function ( ) {
738
+ save_settings ( ) ;
739
+ $ ( '#send2cgeo_settings' ) . css ( 'display' , 'none' ) ;
740
+ } ) ;
741
+ $ ( '#s2cg_openSettings' ) . on ( 'click' , function ( ) {
742
+ $ ( '#send2cgeo_settings' ) . css ( 'display' , 'unset' ) ;
743
+ } ) ;
744
+ }
745
+
746
+ // opencaching.de
747
+ if ( document . location . href . match ( / \. d e \/ m y h o m e \. p h p / ) ) {
748
+ $ ( 'head' ) . append ( '<style>' + settingsCSS + '</style>' ) ;
749
+ $ ( 'body' ) . append ( settingsHTML ) ;
750
+ $ ( '.content2-pagetitle' ) . after ( '<div class="content2-container bg-blue02" style="margin-top:20px;">'
751
+ + ' <p class="content-title-noshade-size3">'
752
+ + ' <img src="https://send2.cgeo.org/send2cgeo.png" style="margin-right:10px;" height="22px" />'
753
+ + ' Send2cgeo <span class="content-title-link"><a id="s2cg_openSettings" href="javascript:void(0)">Settings</a></span>'
754
+ + ' </p>'
755
+ + '</div>' ) ;
756
+ $ ( '#send2cgeo_settings_submit' ) . on ( 'click' , function ( ) {
757
+ save_settings ( ) ;
758
+ $ ( '#send2cgeo_settings' ) . css ( 'display' , 'none' ) ;
759
+ } ) ;
760
+ $ ( '#s2cg_openSettings' ) . on ( 'click' , function ( ) {
761
+ $ ( '#send2cgeo_settings' ) . css ( 'display' , 'unset' ) ;
762
+ } ) ;
763
+ }
586
764
}
587
765
588
766
start ( this ) ;
0 commit comments