8
8
// @include /^https?://www\.geocaching\.com/play/owner/(published|unpublished|archived)/
9
9
// @include /^https?://www\.geocaching\.com/play/owner/(published|unpublished|archived)/events/
10
10
// @include /^https?://www\.geocaching\.com/seek/(cache_details\.|nearest\.|)/
11
- // @include /^https?://www\.geocaching\.com/my/recentlyviewedcaches\./
11
+ // @include /^https?://www\.geocaching\.com/my/( recentlyviewedcaches|default) \./
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
+ + ( isUseWithoutThirdPartyCookies ( )
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 isUseWithoutThirdPartyCookies ( ) {
163
+ return GM_getValue ( 'useWithoutThirdPartyCookies' , false ) ;
164
+ }
165
+
150
166
function s2cgGCMain ( ) {
151
167
// check for premium membership (parts of the page content are different)
152
168
function premiumCheck ( ) {
@@ -278,15 +294,26 @@ function s2cgGCMain() {
278
294
279
295
// Sending
280
296
var cachesToSend = $ ( '[s2cgeo-send]' ) ;
281
- function sendCache ( c ) {
282
- var GCCode = $ ( cachesToSend [ c ] ) . attr ( 's2cgeo-send' ) ;
283
- $ ( cachesToSend [ c ] ) . find ( '.s2cgeo' ) . html ( '<iframe name="' + GCCode + '" src=\"https://send2.cgeo.org/add.html?cache=' + GCCode + '\" width="80" height="55">' ) ;
297
+ function sendCache ( i ) {
298
+ var GCCode = $ ( cachesToSend [ i ] ) . attr ( 's2cgeo-send' ) ;
299
+ if ( isUseWithoutThirdPartyCookies ( ) ) {
300
+ var padding = i % 10 * 30 + 10 ;
301
+ let sendCache = window . open ( 'https://send2.cgeo.org/add.html?cache=' + GCCode , 'send' + GCCode , 'width=200,height=100,top=' + padding + ',left=' + padding + ',menubar=no,status=no' ) ;
302
+ window . setTimeout (
303
+ function ( ) {
304
+ sendCache . close ( ) ;
305
+ } ,
306
+ 900
307
+ ) ;
308
+ } else {
309
+ $ ( cachesToSend [ i ] ) . find ( '.s2cgeo' ) . html ( '<iframe name="' + GCCode + '" src=\"https://send2.cgeo.org/add.html?cache=' + GCCode + '\" width="80" height="55">' ) ;
310
+ }
284
311
alreadySend ++ ;
285
312
$ ( '#s2cgeo-process' ) . html ( alreadySend + '/' + cachesToSend . length + ' caches sent' ) ;
286
- if ( c + 1 < cachesToSend . length ) {
313
+ if ( i + 1 < cachesToSend . length ) {
287
314
window . setTimeout (
288
315
function ( ) {
289
- sendCache ( c + 1 ) ;
316
+ sendCache ( i + 1 ) ;
290
317
} ,
291
318
100
292
319
)
@@ -298,30 +325,40 @@ function s2cgGCMain() {
298
325
// This function add the send2cgeo buttons on geocaching.com
299
326
// Because jQuery is not supported by some pages, the window.s2geo() function does not work.
300
327
// The following function is a workaround to solve this problem.
301
- function buildButton ( GCCode , anchorElement , height , imgClass = '' ) {
328
+ function buildButton ( GCCode , anchor , height , imgClass = '' ) {
302
329
// Add s2cg button.
303
330
var html = '<a id="s2cg-' + GCCode + '" href="javascript:void(0);" title="Send to c:geo">'
304
331
+ '<img class="' + imgClass + '" src="https://send2.cgeo.org/send2cgeo.png" height="' + height + '"/>'
305
332
+ '</a>' ;
306
333
307
- $ ( anchorElement ) . append ( html ) ;
334
+ $ ( anchor ) . append ( html ) ;
308
335
309
336
$ ( '#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" ,
337
+ if ( isUseWithoutThirdPartyCookies ( ) ) {
338
+ 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' ) ;
339
+ window . setTimeout (
318
340
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
- }
341
+ sendCache . close ( ) ;
342
+ } ,
343
+ 3000
324
344
) ;
345
+ } else {
346
+ // show the box and the "please wait" text
347
+ $ ( "#send2cgeo, #send2cgeo div" ) . fadeIn ( ) ;
348
+ // hide iframe for now and wait for page to be loaded
349
+ $ ( "#send2cgeo iframe" )
350
+ . hide ( )
351
+ . off ( "load" )
352
+ . attr ( "src" , "https://send2.cgeo.org/add.html?cache=" + GCCode )
353
+ . on ( "load" ,
354
+ function ( ) {
355
+ // hide "please wait text" and show iframe
356
+ $ ( "#send2cgeo div" ) . hide ( ) ;
357
+ // hide box after 3 seconds
358
+ $ ( this ) . css ( "display" , "block" ) . parent ( ) . delay ( 3000 ) . fadeOut ( ) ;
359
+ }
360
+ ) ;
361
+ }
325
362
} ) ;
326
363
}
327
364
@@ -342,6 +379,7 @@ function s2cgGCMain() {
342
379
+ '<iframe style="' + iframeStyle + '"></iframe>'
343
380
+ '</div>' ) ;
344
381
382
+ // This function add the send2cgeo buttons on geocaching.com
345
383
// Send to c:geo on browsemap (old map)
346
384
if ( document . location . href . match ( / \. c o m \/ m a p / ) ) {
347
385
var template = $ ( "#cacheDetailsTemplate" ) . html ( ) ;
@@ -555,7 +593,6 @@ function s2cgGCMain() {
555
593
var text = $ ( this ) . find ( '.geocache-details' ) . text ( ) . split ( '|' ) ;
556
594
text = text [ 0 ] . trim ( ) ;
557
595
var GCCode = text . substr ( 0 , text . length - 3 ) . trim ( ) ;
558
- console . log ( GCCode ) ;
559
596
560
597
removeIfAlreadyExists ( '#s2cg-' + GCCode , $ ( '#s2cg-' + GCCode ) . parent ( ) ) ;
561
598
@@ -583,6 +620,187 @@ function s2cgGCMain() {
583
620
584
621
oc . innerHTML = oc . innerHTML . replace ( '</p>' , html ) ;
585
622
}
623
+
624
+ // This will add settings
625
+ function save_settings ( ) {
626
+ GM_setValue ( 'useWithoutThirdPartyCookies' , $ ( '#useWithoutThirdPartyCookies' ) . is ( ':checked' ) ) ;
627
+ }
628
+
629
+ function buildToggle ( id , label , info = '' ) {
630
+ return '<div class="s2cg_toggle">'
631
+ + ' <label>' + label
632
+ + ' <input type="checkbox" id="' + id + '"' + ( GM_getValue ( id , false ) ? ' checked' : '' ) + '><span class="slider"></span>'
633
+ + ' </label>'
634
+ + ( info != ''
635
+ ? ' <label for="' + id + '_info" class="s2cg_infoBtn"> ?</label>'
636
+ + ' <input type="checkbox" id="' + id + '_info" class="s2cg_info">'
637
+ + ' <div class="s2cg_info">' + info + '</div>'
638
+ : '' )
639
+ + '</div>'
640
+ }
641
+
642
+ // Long info text
643
+ var thirdPartyCookiesInfo = 'Chrome blocks third-party cookies by default, because they <b>can be</b> malicious. '
644
+ + 'You can also block third-party cookies in other browsers.<br>"Send to c:geo" uses '
645
+ + 'cookies on geocaching.com and opencaching.de and is therefore a third-party cookie.'
646
+ + '<br>With this option, the cookies are not set via the geocaching.com and opencaching.de '
647
+ + 'pages, but in a pop-up window so that you can continue to use "Send to c:geo".<br>'
648
+ + '<b>Attention: Sending multiple Caches does not work on the search page </b>'
649
+ + '(https://www.geocaching.com/play/search)' ;
650
+
651
+ var settingsHTML = '<div id="send2cgeo_settings" style="display:none;">'
652
+ + ' <div id="s2cg_settings_content">'
653
+ + ' <div id="s2cg_settings_header">'
654
+ + ' <h1>Send to c:geo settings</h1>'
655
+ + ' </div>'
656
+ // Add options
657
+ + buildToggle ( 'useWithoutThirdPartyCookies' , 'Use Send to c:geo without third-party cookies' , thirdPartyCookiesInfo )
658
+ // Save-Button
659
+ + ' <input type="button" id="send2cgeo_settings_submit" value="Save">'
660
+ + ' </div>'
661
+ + '</div>' ;
662
+
663
+ var settingsCSS = '#send2cgeo_settings {'
664
+ + ' position: fixed;'
665
+ + ' background: rgba(31, 31, 31, .7);'
666
+ + ' top: 0;'
667
+ + ' left: 0;'
668
+ + ' width: 100%;'
669
+ + ' height: 100%;'
670
+ + ' z-index: 1111;'
671
+ + ' color: #fff;'
672
+ + '}'
673
+
674
+ + '#s2cg_settings_content {'
675
+ + ' position: absolute;'
676
+ + ' top: 50%;'
677
+ + ' left: 50%;'
678
+ + ' width: 60%;'
679
+ + ' -webkit-transform: translate(-50%, -50%);'
680
+ + ' -ms-transform: translate(-50%, -50%);'
681
+ + ' transform: translate(-50%, -50%);'
682
+ + ' background: rgba(31, 31, 31, 1);'
683
+ + ' padding: 1em;'
684
+ + ' border-radius: 1em;'
685
+ + '}'
686
+
687
+ + '#s2cg_settings_content p, .s2cg_toggle label, #send2cgeo_settings_submit {'
688
+ + ' font-size: ' + ( document . location . href . match ( / \. d e \/ m y h o m e \. p h p / ) ? '1.5' : '1' ) + 'em !important;'
689
+ + '}'
690
+
691
+ + '#send2cgeo_settings_submit {'
692
+ + ' margin-top: 1em;'
693
+ + ' color: rgba(31, 31, 31, 1);'
694
+ + ' border-radius: 5px;'
695
+ + ' cursor: pointer;'
696
+ + ' padding: 0 8px;'
697
+ + '}'
698
+
699
+ + '.s2cg_toggle {'
700
+ + ' padding-left: 1em;'
701
+ + '}'
702
+
703
+ + '.s2cg_toggle label {'
704
+ + ' position: relative;'
705
+ + ' display: inline-block;'
706
+ + ' text-transform: none;'
707
+ + '}'
708
+
709
+ + '.s2cg_toggle input {'
710
+ + ' display: none;'
711
+ + '}'
712
+
713
+ + '.s2cg_toggle .slider {'
714
+ + ' position: absolute;'
715
+ + ' cursor: pointer;'
716
+ + ' margin-left: .5em;'
717
+ + ' width: 2em;'
718
+ + ' height: 1em;'
719
+ + ' background: #c32e04; /* red */'
720
+ + ' transition: all .3s ease-in-out;'
721
+ + ' border-radius: 1em;'
722
+ + '}'
723
+
724
+ + '.s2cg_toggle .slider:before {'
725
+ + ' position: absolute;'
726
+ + ' content: "";'
727
+ + ' height: .6em;'
728
+ + ' width: .6em;'
729
+ + ' left: .2em;'
730
+ + ' bottom: .2em;'
731
+ + ' background: white;'
732
+ + ' border-radius: 50%;'
733
+ + ' transition: all .3s ease-in-out;'
734
+ + '}'
735
+
736
+ + '.s2cg_toggle input:checked + .slider {'
737
+ + ' background: #5a9900; /* green */'
738
+ + '}'
739
+
740
+ + '.s2cg_toggle input:checked + .slider:before {'
741
+ + ' -webkit-transform: translateX(1em);'
742
+ + ' -ms-transform: translateX(1em);'
743
+ + ' transform: translateX(1em);'
744
+ + '}'
745
+
746
+ + '.s2cg_info {'
747
+ + ' display: none;'
748
+ + '}'
749
+
750
+ + 'input.s2cg_info:checked + div.s2cg_info {'
751
+ + ' display: block;'
752
+ + '}'
753
+
754
+ + 'div.s2cg_info {'
755
+ + ' margin: 0 0 1em 1.5em;'
756
+ + '}'
757
+
758
+ + '.s2cg_infoBtn {'
759
+ + ' cursor:pointer;'
760
+ + ' margin-left:3em;'
761
+ + ' border:2px solid #fff;'
762
+ + ' border-radius:50%;'
763
+ + ' width: 1.5em;'
764
+ + ' height: 1.5em;'
765
+ + ' padding-left: .3em;'
766
+ + ' font-weight: bold;'
767
+ + ' box-sizing: border-box;'
768
+ + '}'
769
+
770
+ + '.s2cg_infoBtn:hover {'
771
+ + ' background: #9f9f9f;'
772
+ + '}' ;
773
+
774
+ if ( document . location . href . match ( / \. c o m \/ a c c o u n t \/ d a s h b o a r d / ) || document . location . href . match ( / \. c o m \/ m y \/ d e f a u l t .a s p x / ) || document . location . href . match ( / \. d e \/ m y h o m e \. p h p / ) ) {
775
+ $ ( 'head' ) . append ( '<style>' + settingsCSS + '</style>' ) ;
776
+ $ ( 'body' ) . append ( settingsHTML ) ;
777
+ // geocaching.com
778
+ // new Dashboard
779
+ if ( document . location . href . match ( / \. c o m \/ a c c o u n t \/ d a s h b o a r d / ) ) {
780
+ $ ( '.bio-meta' ) . append ( '<a id="s2cg_openSettings" href="javascript:void(0)" style="display:block;">Send to c:geo settings</a>' ) ;
781
+ }
782
+ // new Dashboard
783
+ if ( document . location . href . match ( / \. c o m \/ m y \/ d e f a u l t .a s p x / ) ) {
784
+ $ ( '#ctl00_ContentBody_WidgetMiniProfile1_memberProfileLink' ) . parent ( ) . append ( ' | <a id="s2cg_openSettings" href="javascript:void(0)">Send to c:geo settings</a>' ) ;
785
+ }
786
+ // opencaching.de
787
+ if ( document . location . href . match ( / \. d e \/ m y h o m e \. p h p / ) ) {
788
+ $ ( '.content2-pagetitle' ) . after ( '<div class="content2-container bg-blue02" style="margin-top:20px;">'
789
+ + ' <p class="content-title-noshade-size3">'
790
+ + ' <img src="https://send2.cgeo.org/send2cgeo.png" style="margin-right:10px;" height="22px" />'
791
+ + ' Send to c:geo <span class="content-title-link"><a id="s2cg_openSettings" href="javascript:void(0)">Settings</a></span>'
792
+ + ' </p>'
793
+ + '</div>' ) ;
794
+ }
795
+ // Open and Save settings
796
+ $ ( '#s2cg_openSettings' ) . on ( 'click' , function ( ) {
797
+ $ ( '#send2cgeo_settings' ) . css ( 'display' , 'unset' ) ;
798
+ } ) ;
799
+ $ ( '#send2cgeo_settings_submit' ) . on ( 'click' , function ( ) {
800
+ save_settings ( ) ;
801
+ $ ( '#send2cgeo_settings' ) . css ( 'display' , 'none' ) ;
802
+ } ) ;
803
+ }
586
804
}
587
805
588
806
start ( this ) ;
0 commit comments