@@ -47,13 +47,19 @@ const autoSource = (function () {
4747 initEventListeners ( ) {
4848 // Event listener for URL input change
4949 this . urlInput . addEventListener ( "change" , ( ) => this . clearRssUrl ( ) ) ;
50+ this . urlInput . addEventListener ( "blur" , ( event ) => this . handleFormSubmit ( event ) ) ;
5051
5152 // Event listener for form submit
5253 this . form . addEventListener ( "submit" , ( event ) => this . handleFormSubmit ( event ) ) ;
5354
55+ const $radios = this . form ?. querySelectorAll ( 'input[type="radio"]' ) ;
56+ Array . from ( $radios ) . forEach ( ( $radio ) => {
57+ $radio . addEventListener ( "change" , ( event ) => this . handleFormSubmit ( event ) ) ;
58+ } ) ;
59+
5460 // Event listener for RSS URL input focus
5561 this . rssUrlInput . addEventListener ( "focus" , ( ) => {
56- const strippedIframeSrc = this . iframe . src . replace ( "#items" , "" ) . trim ( ) ;
62+ const strippedIframeSrc = this . iframe . src . trim ( ) ;
5763 if ( this . rssUrlInput . value . trim ( ) !== strippedIframeSrc ) {
5864 this . updateIframeSrc ( this . rssUrlInput . value . trim ( ) ) ;
5965 }
@@ -93,13 +99,20 @@ const autoSource = (function () {
9399
94100 if ( this . isValidUrl ( url ) ) {
95101 const encodedUrl = this . encodeUrl ( url ) ;
96- const autoSourceUrl = this . generateAutoSourceUrl ( encodedUrl ) ;
102+ const params = { } ;
103+ const strategy = this . form ?. querySelector ( 'input[name="strategy"]:checked' ) ?. value ;
104+ if ( strategy ) {
105+ params [ "strategy" ] = strategy ;
106+ }
107+
108+ const autoSourceUrl = this . generateAutoSourceUrl ( encodedUrl , params ) ;
97109
98110 this . rssUrlInput . value = autoSourceUrl ;
99111 this . rssUrlInput . select ( ) ;
100112
101- if ( window . location . search !== `?url=${ url } ` ) {
102- window . history . pushState ( { } , "" , `?url=${ url } ` ) ;
113+ const targetSearch = `?url=${ url } &strategy=${ strategy } ` ;
114+ if ( window . location . search !== targetSearch ) {
115+ window . history . pushState ( { } , "" , targetSearch ) ;
103116 }
104117 }
105118 }
@@ -132,17 +145,20 @@ const autoSource = (function () {
132145 * @param {string } encodedUrl - The base64 encoded URL.
133146 * @returns {string } The generated auto-source URL.
134147 */
135- generateAutoSourceUrl ( encodedUrl ) {
148+ generateAutoSourceUrl ( encodedUrl , params = { } ) {
136149 const baseUrl = new URL ( window . location . origin ) ;
137- return `${ baseUrl } ${ BASE_PATH } /${ encodedUrl } ` ;
150+
151+ const url = new URL ( `${ baseUrl } ${ BASE_PATH } /${ encodedUrl } ` ) ;
152+ url . search = new URLSearchParams ( params ) . toString ( ) ;
153+ return url . toString ( ) ;
138154 }
139155
140156 /**
141157 * Updates the iframe source.
142158 * @param {string } rssUrlValue - The RSS URL value.
143159 */
144160 updateIframeSrc ( rssUrlValue ) {
145- this . iframe . src = rssUrlValue === "" ? "" : `${ rssUrlValue } #items ` ;
161+ this . iframe . src = rssUrlValue === "" ? "about://blank " : `${ rssUrlValue } ` ;
146162 }
147163 }
148164
@@ -187,7 +203,7 @@ const autoSource = (function () {
187203 */
188204 async copyText ( ) {
189205 try {
190- const textToCopy = this . rssUrlField . value ;
206+ const textToCopy = this . rssUrlWithAuth ;
191207 await navigator . clipboard . writeText ( textToCopy ) ;
192208 } catch ( error ) {
193209 console . error ( "Failed to copy text to clipboard:" , error ) ;
@@ -198,7 +214,7 @@ const autoSource = (function () {
198214 * Opens the link specified in the text field.
199215 */
200216 openLink ( ) {
201- const linkToOpen = this . rssUrlField ?. value ;
217+ const linkToOpen = this . rssUrlWithAuth ;
202218
203219 if ( typeof linkToOpen === "string" && linkToOpen . trim ( ) !== "" ) {
204220 window . open ( linkToOpen , "_blank" , "noopener,noreferrer" ) ;
@@ -209,6 +225,10 @@ const autoSource = (function () {
209225 * Subscribes to the feed specified in the text field.
210226 */
211227 async subscribeToFeed ( ) {
228+ window . open ( this . rssUrlWithAuth ) ;
229+ }
230+
231+ get rssUrlWithAuth ( ) {
212232 const feedUrl = this . rssUrlField . value ;
213233 const storedUser = LocalStorageFacade . getOrAsk ( "username" ) ;
214234 const storedPassword = LocalStorageFacade . getOrAsk ( "password" ) ;
@@ -217,9 +237,7 @@ const autoSource = (function () {
217237 url . username = storedUser ;
218238 url . password = storedPassword ;
219239
220- const feedUrlWithAuth = `feed:${ url . toString ( ) } ` ;
221-
222- window . open ( feedUrlWithAuth ) ;
240+ return `feed:${ url . toString ( ) } ` ;
223241 }
224242
225243 resetCredentials ( ) {
0 commit comments