File tree 5 files changed +81
-0
lines changed
5 files changed +81
-0
lines changed Original file line number Diff line number Diff line change 82
82
"rem" : {},
83
83
"request-idle-callback" : {},
84
84
"typescript-happy-forward-ref" : {},
85
+ "is-safari" : {},
85
86
"-- separator extensions" : {
86
87
"type" : " separator" ,
87
88
"title" : " Extensions"
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : isSafari
3
+ ---
4
+
5
+ # isSafari
6
+
7
+ import ExportMetaInfo from ' ../components/export-meta-info' ;
8
+
9
+ <ExportMetaInfo />
10
+
11
+ Since Safari browser is a known modern Internet Explorer, you should just check if the browser is Safari and apply the necessary polyfills or special logics.
12
+
13
+ ## Usage
14
+
15
+ ``` tsx copy
16
+ import { isSafari } from ' foxact/is-safari' ;
17
+
18
+ isSafari (); // true or false
19
+ ```
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : Open in New Tab
3
+ ---
4
+
5
+ # Open in New Tab
6
+
7
+ import ExportMetaInfo from ' ../components/export-meta-info' ;
8
+
9
+ <ExportMetaInfo />
10
+
11
+ Open a URL in a new tab. Use ` window.open ` on the Safari browser (since nowadays Safari is known as a modern Internet Explorer) and ` document.createElement('a') ` on other browsers.
12
+
13
+ ## Usage
14
+
15
+ ``` tsx copy
16
+ import { openInNewTab } from ' foxact/open-in-new-tab' ;
17
+
18
+ openInNewTab (' https://skk.moe' );
19
+ ```
Original file line number Diff line number Diff line change
1
+ export function isSafari ( ) {
2
+ if ( typeof window === 'undefined' ) {
3
+ return false ;
4
+ }
5
+ if ( typeof navigator === 'undefined' ) {
6
+ return false ;
7
+ }
8
+ if ( typeof navigator . userAgent !== 'string' ) {
9
+ return false ;
10
+ }
11
+ if ( / v e r s i o n \/ [ \d . _ ] .* ?s a f a r i / i. test ( navigator . userAgent ) ) {
12
+ return true ;
13
+ }
14
+ // eslint-disable-next-line sukka/prefer-single-boolean-return -- cleaner code
15
+ if ( / m o b i l e s a f a r i [ \d . _ ] + / i. test ( navigator . userAgent ) ) {
16
+ return true ;
17
+ }
18
+ return false ;
19
+ }
Original file line number Diff line number Diff line change
1
+ import { isSafari } from '../is-safari' ;
2
+
3
+ export function openInNewTab ( url : string ) {
4
+ if ( typeof window === 'undefined' ) {
5
+ return ;
6
+ }
7
+
8
+ if ( isSafari ( ) ) {
9
+ window . open ( url , '_blank' ) ;
10
+ return ;
11
+ }
12
+
13
+ const a = document . createElement ( 'a' ) ;
14
+ a . href = url ;
15
+ a . target = '_blank' ;
16
+ a . rel = 'noopener noreferrer' ;
17
+ document . body . appendChild ( a ) ;
18
+ a . click ( ) ;
19
+
20
+ Promise . resolve ( ) . finally ( ( ) => {
21
+ a . remove ( ) ;
22
+ } ) ;
23
+ }
You can’t perform that action at this time.
0 commit comments