@@ -15,6 +15,7 @@ function getOphirofoxConfigByName(search_name) {
1515
1616const DEFAULT_SETTINGS = {
1717 partner_name : "Pas d'intermédiaire" ,
18+ open_links_new_tab : false ,
1819} ;
1920
2021let current_settings = DEFAULT_SETTINGS ;
@@ -74,51 +75,47 @@ const ophirofox_config = getOphirofoxConfig();
7475 * @returns {Promise<HTMLAnchorElement> }
7576 */
7677async function ophirofoxEuropresseLink ( keywords , { publishedTime } = { } ) {
77- // Keywords is the article name
7878 keywords = keywords ? keywords . trim ( ) : document . querySelector ( "h1" ) . textContent ;
7979
80- // Trying generically to determine published time with meta tags (Open Graph values)
81- // Heuristics would suggest that it's normally UTC in the media world.
82- publishedTime = publishedTime || document . querySelector ( "meta[property='article:published_time'], meta[property='og:article:published_time'], meta[property='date:published_time']" )
83- ?. getAttribute ( "content" ) || '' ;
80+ publishedTime = publishedTime || document . querySelector ( "meta[property='article:published_time'], meta[property='og:article:published_time'], meta[property='date:published_time']" )
81+ ?. getAttribute ( "content" ) || '' ;
8482 let publishedTimeInstance = new Date ( publishedTime ) ;
8583
8684 if ( ! isNaN ( publishedTimeInstance ) ) {
87- // JavaScript, what a pleasure.
8885 publishedTime = publishedTimeInstance . toISOString ( ) . slice ( 0 , 10 ) ;
8986 } else {
90- publishedTime = ''
87+ publishedTime = '' ;
9188 }
9289
93- // Creating HTML anchor element
9490 const a = document . createElement ( "a" ) ;
9591 a . textContent = "Lire sur Europresse" ;
9692 a . className = "ophirofox-europresse" ;
97-
93+
9894 const setKeywords = ( ) => new Promise ( accept => {
9995 Promise . all ( [
100- // set request type (read, or readPDF)
10196 chrome . storage . local . set ( {
102- "ophirofox_request_type" :
103- {
104- 'type' : 'read'
105- }
97+ "ophirofox_request_type" : { 'type' : 'read' }
10698 } ) ,
10799 chrome . storage . local . set ( {
108- "ophirofox_read_request" :
109- {
100+ "ophirofox_read_request" : {
110101 'search_terms' : keywords ,
111102 'published_time' : publishedTime
112103 }
113104 } ) ,
114105 ] ) . then ( ( ) => accept ( ) ) ;
115106 } ) ;
107+
116108 a . onmousedown = setKeywords ;
117109 a . onclick = async function ( evt ) {
118110 evt . preventDefault ( ) ;
119- const [ { AUTH_URL } ] = await Promise . all ( [ ophirofox_config , setKeywords ( ) ] ) ;
120- window . location = AUTH_URL
121- }
111+ const [ { AUTH_URL } , settings ] = await Promise . all ( [ ophirofox_config , getSettings ( ) ] ) ;
112+ if ( settings . open_links_new_tab ) {
113+ window . open ( AUTH_URL , "_blank" ) ;
114+ } else {
115+ window . location = AUTH_URL ;
116+ }
117+ } ;
118+
122119 ophirofox_config . then ( ( { AUTH_URL } ) => { a . href = AUTH_URL } ) ;
123120 return a ;
124121}
@@ -130,35 +127,35 @@ async function ophirofoxEuropresseLink(keywords, { publishedTime } = {}) {
130127 * @returns {Promise<HTMLAnchorElement> }
131128 */
132129async function ophirofoxEuropressePDFLink ( media_id , publishedTime ) {
133- // Creating HTML anchor element
134130 const a = document . createElement ( "a" ) ;
135131 a . textContent = "Lire sur Europresse" ;
136132 a . className = "ophirofox-europresse" ;
137-
133+
138134 const setKeywords = ( ) => new Promise ( accept => {
139135 Promise . all ( [
140- // set request type (read, or readPDF)
141136 chrome . storage . local . set ( {
142- "ophirofox_request_type" :
143- {
144- 'type' : 'readPDF'
145- }
137+ "ophirofox_request_type" : { 'type' : 'readPDF' }
146138 } ) ,
147139 chrome . storage . local . set ( {
148- "ophirofox_readPDF_request" :
149- {
140+ "ophirofox_readPDF_request" : {
150141 'media_id' : media_id ,
151142 'published_time' : publishedTime
152143 }
153144 } ) ,
154145 ] ) . then ( ( ) => accept ( ) ) ;
155146 } ) ;
147+
156148 a . onmousedown = setKeywords ;
157149 a . onclick = async function ( evt ) {
158150 evt . preventDefault ( ) ;
159- const [ { AUTH_URL } ] = await Promise . all ( [ ophirofox_config , setKeywords ( ) ] ) ;
160- window . location = AUTH_URL
161- }
151+ const [ { AUTH_URL } , settings ] = await Promise . all ( [ ophirofox_config , getSettings ( ) ] ) ;
152+ if ( settings . open_links_new_tab ) {
153+ window . open ( AUTH_URL , "_blank" ) ;
154+ } else {
155+ window . location = AUTH_URL ;
156+ }
157+ } ;
158+
162159 ophirofox_config . then ( ( { AUTH_URL } ) => { a . href = AUTH_URL } ) ;
163160 return a ;
164161}
0 commit comments