@@ -3,27 +3,27 @@ const https = require('https')
3
3
const TurndownService = require ( 'turndown' )
4
4
const createNote = require ( './createNote' )
5
5
6
- import { hashHistory } from 'react-router'
6
+ import { push } from 'connected- react-router'
7
7
import ee from 'browser/main/lib/eventEmitter'
8
8
9
- function validateUrl ( str ) {
10
- if ( / ^ (?: (?: (?: h t t p s ? | f t p ) : ) ? \/ \/ ) (?: \S + (?: : \S * ) ? @ ) ? (?: (? ! (?: 1 0 | 1 2 7 ) (?: \. \d { 1 , 3 } ) { 3 } ) (? ! (?: 1 6 9 \. 2 5 4 | 1 9 2 \. 1 6 8 ) (?: \. \d { 1 , 3 } ) { 2 } ) (? ! 1 7 2 \. (?: 1 [ 6 - 9 ] | 2 \d | 3 [ 0 - 1 ] ) (?: \. \d { 1 , 3 } ) { 2 } ) (?: [ 1 - 9 ] \d ? | 1 \d \d | 2 [ 0 1 ] \d | 2 2 [ 0 - 3 ] ) (?: \. (?: 1 ? \d { 1 , 2 } | 2 [ 0 - 4 ] \d | 2 5 [ 0 - 5 ] ) ) { 2 } (?: \. (?: [ 1 - 9 ] \d ? | 1 \d \d | 2 [ 0 - 4 ] \d | 2 5 [ 0 - 4 ] ) ) | (?: (?: [ a - z \u00a1 - \uffff 0 - 9 ] - * ) * [ a - z \u00a1 - \uffff 0 - 9 ] + ) (?: \. (?: [ a - z \u00a1 - \uffff 0 - 9 ] - * ) * [ a - z \u00a1 - \uffff 0 - 9 ] + ) * (?: \. (?: [ a - z \u00a1 - \uffff ] { 2 , } ) ) .? ) (?: : \d { 2 , 5 } ) ? (?: [ / ? # ] \S * ) ? $ / i. test ( str ) ) {
11
- return true ;
9
+ function validateUrl ( str ) {
10
+ if ( / ^ (?: (?: (?: h t t p s ? | f t p ) : ) ? \/ \/ ) (?: \S + (?: : \S * ) ? @ ) ? (?: (? ! (?: 1 0 | 1 2 7 ) (?: \. \d { 1 , 3 } ) { 3 } ) (? ! (?: 1 6 9 \. 2 5 4 | 1 9 2 \. 1 6 8 ) (?: \. \d { 1 , 3 } ) { 2 } ) (? ! 1 7 2 \. (?: 1 [ 6 - 9 ] | 2 \d | 3 [ 0 - 1 ] ) (?: \. \d { 1 , 3 } ) { 2 } ) (?: [ 1 - 9 ] \d ? | 1 \d \d | 2 [ 0 1 ] \d | 2 2 [ 0 - 3 ] ) (?: \. (?: 1 ? \d { 1 , 2 } | 2 [ 0 - 4 ] \d | 2 5 [ 0 - 5 ] ) ) { 2 } (?: \. (?: [ 1 - 9 ] \d ? | 1 \d \d | 2 [ 0 - 4 ] \d | 2 5 [ 0 - 4 ] ) ) | (?: (?: [ a - z \u00a1 - \uffff 0 - 9 ] - * ) * [ a - z \u00a1 - \uffff 0 - 9 ] + ) (?: \. (?: [ a - z \u00a1 - \uffff 0 - 9 ] - * ) * [ a - z \u00a1 - \uffff 0 - 9 ] + ) * (?: \. (?: [ a - z \u00a1 - \uffff ] { 2 , } ) ) .? ) (?: : \d { 2 , 5 } ) ? (?: [ / ? # ] \S * ) ? $ / i. test ( str ) ) {
11
+ return true
12
12
} else {
13
- return false ;
13
+ return false
14
14
}
15
15
}
16
16
17
17
function createNoteFromUrl ( url , storage , folder , dispatch = null , location = null ) {
18
18
return new Promise ( ( resolve , reject ) => {
19
- let td = new TurndownService ( ) ;
19
+ let td = new TurndownService ( )
20
20
21
- if ( ! validateUrl ( url ) ) {
22
- reject ( { result : false , error : " Please check your URL is in correct format. (Example, https://www.google.com)" } )
21
+ if ( ! validateUrl ( url ) ) {
22
+ reject ( { result : false , error : ' Please check your URL is in correct format. (Example, https://www.google.com)' } )
23
23
}
24
24
25
25
let request = http
26
- if ( url . includes ( 'https' ) ) {
26
+ if ( url . includes ( 'https' ) ) {
27
27
request = https
28
28
}
29
29
@@ -39,7 +39,7 @@ function createNoteFromUrl (url, storage, folder, dispatch = null, location = nu
39
39
html . innerHTML = data
40
40
41
41
let scripts = html . getElementsByTagName ( 'script' )
42
- for ( let i = scripts . length - 1 ; i >= 0 ; i -- ) {
42
+ for ( let i = scripts . length - 1 ; i >= 0 ; i -- ) {
43
43
scripts [ i ] . parentNode . removeChild ( scripts [ i ] )
44
44
}
45
45
@@ -48,7 +48,7 @@ function createNoteFromUrl (url, storage, folder, dispatch = null, location = nu
48
48
49
49
html . innerHTML = ''
50
50
51
- if ( dispatch !== null ) {
51
+ if ( dispatch !== null ) {
52
52
createNote ( storage , {
53
53
type : 'MARKDOWN_NOTE' ,
54
54
folder : folder ,
@@ -61,10 +61,10 @@ function createNoteFromUrl (url, storage, folder, dispatch = null, location = nu
61
61
type : 'UPDATE_NOTE' ,
62
62
note : note
63
63
} )
64
- hashHistory . push ( {
64
+ dispatch ( push ( {
65
65
pathname : location . pathname ,
66
66
query : { key : noteHash }
67
- } )
67
+ } ) )
68
68
ee . emit ( 'list:jump' , noteHash )
69
69
ee . emit ( 'detail:focus' )
70
70
resolve ( { result : true , error : null } )
@@ -86,9 +86,8 @@ function createNoteFromUrl (url, storage, folder, dispatch = null, location = nu
86
86
console . error ( 'error in parsing URL' , e )
87
87
reject ( { result : false , error : e } )
88
88
} )
89
- req . end ( ) ;
89
+ req . end ( )
90
90
} )
91
-
92
91
}
93
92
94
- module . exports = createNoteFromUrl ;
93
+ module . exports = createNoteFromUrl
0 commit comments