@@ -2,11 +2,21 @@ if ('serviceWorker' in navigator) {
2
2
navigator . serviceWorker . register ( 'serviceworker.js' , { scope : '/ultimatedotnetcheatsheet/' } ) ;
3
3
}
4
4
5
- document . addEventListener ( "DOMContentLoaded" , applyCopyButton ) ;
5
+ document . addEventListener ( "DOMContentLoaded" , onLoaded ) ;
6
6
7
- window . onscroll = function ( ) { scrollFunction ( ) } ;
7
+ window . onscroll = function ( ) {
8
+ const scrollBtn = document . getElementById ( 'navigate-top' ) ;
9
+ if ( document . body . scrollTop > 100
10
+ || document . documentElement . scrollTop > 100 ) {
11
+ scrollBtn . style . display = 'block' ;
12
+ }
13
+ else {
14
+ scrollBtn . style . display = 'none' ;
15
+ }
16
+ } ;
8
17
9
- function applyCopyButton ( ) {
18
+ function onLoaded ( ) {
19
+ //apply copy buttons
10
20
const preElements = document . querySelectorAll ( 'pre' ) ;
11
21
12
22
preElements . forEach ( pre => {
@@ -20,10 +30,16 @@ function applyCopyButton() {
20
30
navigator . clipboard . writeText ( codeToCopy ) . then ( ( ) => {
21
31
notify ( 'Code copied to clipboard' ) ;
22
32
} ) . catch ( err => {
23
- notify ( 'Failed to copy code: ' + err ) ;
33
+ notify ( 'Failed to copy code: ' + err ) ;
24
34
} ) ;
25
35
} ) ;
26
36
} ) ;
37
+
38
+ //link fixing
39
+ Array . from ( document . links )
40
+ . filter ( link => link . hostname != window . location . hostname )
41
+ . forEach ( link => link . target = '_blank' ) ;
42
+
27
43
}
28
44
29
45
function notify ( message ) {
@@ -35,16 +51,6 @@ function notify(message) {
35
51
} , 800 ) ;
36
52
}
37
53
38
- function scrollFunction ( ) {
39
- const scrollBtn = document . getElementById ( 'navigate-top' ) ;
40
- if ( document . body . scrollTop > 100
41
- || document . documentElement . scrollTop > 100 ) {
42
- scrollBtn . style . display = 'block' ;
43
- } else {
44
- scrollBtn . style . display = 'none' ;
45
- }
46
- }
47
-
48
54
function scrollToTop ( ) {
49
55
document . body . scrollTop = 0 ;
50
56
document . documentElement . scrollTop = 0 ;
0 commit comments