11let proxyServer = "https://api.allorigins.win/get?url=" ;
2+ const tagListEmpty = `
3+ <div class="card">
4+ <div class="card-body">
5+ <p class="text-center mt-3">No tags found. Please try entering a URL and search. </p>
6+ </div>
7+ </div>`
28
39function formatResponseTime ( milliseconds ) {
410 if ( milliseconds < 1000 ) {
@@ -20,8 +26,9 @@ async function checkSEO() {
2026 document . getElementById ( 'status' ) . innerHTML = '' ;
2127 document . getElementById ( "loadingStatus" ) . innerHTML = "Approaching website ..."
2228
23- if ( ! url ) {
24- document . getElementById ( 'status' ) . textContent = ` Please enter a valid URL.` ;
29+ if ( ! url || ! checkUrl ( url ) ) {
30+ document . getElementById ( 'status' ) . textContent = ` Please enter a valid URL, Eg : (https://www.example.com)` ;
31+ document . getElementById ( 'tag-list' ) . innerHTML = tagListEmpty ;
2532 return ;
2633 }
2734
@@ -38,19 +45,19 @@ async function checkSEO() {
3845 if ( ! response . ok ) {
3946 throw new Error ( 'Failed to fetch the URL' ) ;
4047 } ;
41-
48+
4249 document . getElementById ( "loadingStatus" ) . innerHTML = "Getting response from the website ..." ;
4350 const data = await response . json ( ) ;
44-
45- // End timing
4651 const endTime = performance . now ( ) ;
4752 const responseTime = endTime - startTime ;
48- //document.getElementById("responseTime").innerHTML = responseTime.toFixed(2);
53+
4954 document . getElementById ( "loadingStatus" ) . innerHTML = "Got response 200 and start analyzing html..." ;
50- const html = data . contents ; // HTML content of the fetched URL
55+
56+ const html = data . contents ;
5157 const parser = new DOMParser ( ) ;
52- const doc = await parser . parseFromString ( html , 'text/html' ) ; // Parse HTML to DOM
58+ const doc = await parser . parseFromString ( html , 'text/html' ) ;
5359 document . getElementById ( "loadingStatus" ) . innerHTML = "Processing result for display..." ;
60+
5461 // Get all <meta> tags from the document
5562 const metaTags = doc . getElementsByTagName ( 'meta' ) ;
5663 const tagList = document . getElementById ( 'tag-list' ) ;
@@ -61,15 +68,15 @@ async function checkSEO() {
6168 const name = tag . getAttribute ( 'name' ) ;
6269 const property = tag . getAttribute ( 'property' ) ;
6370 const content = tag . getAttribute ( 'content' ) ;
64-
71+ const httpEquiv = tag . getAttribute ( 'http-equiv' ) ;
6572 // Create the base object for the meta tag
6673 let tagObject = {
67- "Tag name" : name || property || "Unknown" ,
74+ "Tag name" : name || property || httpEquiv || "Unknown name " ,
6875 "Content" : content || "No Content" ,
6976 "isMatch" : content ? true : false ,
70- "IsFacebook" : ( property && property . includes ( 'og:' ) ) ? true : false ,
71- "IsTwitter" : ( name && name . includes ( 'twitter' ) ) ? true : false ,
72- "isGoogle" : ( name && name . includes ( 'google' ) ) ? true : false ,
77+ "IsFacebook" : ( property && property . includes ( 'og:' ) ) ,
78+ "IsTwitter" : ( name && name . includes ( 'twitter' ) ) ,
79+ "isGoogle" : ( name && name . includes ( 'google' ) ) ,
7380 "fullTag" : tag . outerHTML
7481 } ;
7582
@@ -90,6 +97,7 @@ async function checkSEO() {
9097
9198 // Add icon if isMatch is Yes
9299 let iconHTML = "" ;
100+
93101 if ( tagObject [ "isMatch" ] ) {
94102 iconHTML = `<i class="bi bi-check-circle text-success ms-auto"></i> ` ;
95103 } else {
@@ -129,7 +137,7 @@ async function checkSEO() {
129137
130138 // Display the overall status
131139 if ( jsonResults . length > 0 ) {
132- document . getElementById ( 'result' ) . innerHTML = `<span class="badge bg-success rounded-pill">${ jsonResults . length } </span> meta tags found in ${ formatResponseTime ( responseTime ) } ` ;
140+ document . getElementById ( 'result' ) . innerHTML = `<span class="badge bg-success rounded-pill">${ jsonResults . length } </span> meta tags found in ${ formatResponseTime ( responseTime ) } ` ;
133141 } else {
134142 document . getElementById ( 'status' ) . textContent = 'No meta tags found.' ;
135143 }
@@ -140,12 +148,7 @@ async function checkSEO() {
140148 }
141149}
142150
143- document . getElementById ( 'tag-list' ) . innerHTML = `
144- <div class="card">
145- <div class="card-body">
146- <p class="text-center mt-3">No tags found. Please try entering a URL and search. </p>
147- </div>
148- </div>` ;
151+ document . getElementById ( 'tag-list' ) . innerHTML = tagListEmpty ;
149152
150153document . getElementById ( 'checkBtn' ) . addEventListener ( 'click' , async ( ) => {
151154 document . getElementById ( 'loading' ) . innerHTML = ` <div class="spinner-border mt-5" role="status"><span class="visually-hidden">Loading...</span></div> </br> Searching meta tags , it may take while, we have to wait for response </br>` ;
@@ -154,18 +157,29 @@ document.getElementById('checkBtn').addEventListener('click', async () => {
154157 document . getElementById ( "loadingStatus" ) . innerHTML = "" ;
155158} ) ;
156159
157- $ ( document ) . ready ( function ( ) {
158-
160+ function checkUrl ( input ) {
161+ try {
162+ return new URL ( input ) ;
163+ } catch ( e ) {
164+ return false ;
165+ }
166+ }
167+
168+ $ ( document ) . ready ( function ( ) {
169+
159170 let options = {
160171 html : true ,
161- title : "Optional: HELLO(Will overide the default-the inline title)" ,
162- //html element
163- //content: $("#popover-content")
164- content : $ ( '[data-name="popover-content"]' )
165- //Doing below won't work. Shows title only
166- //content: $("#popover-content").html()
167-
172+ content : $ ( '[data-name="popover-content"]' ) ,
168173 }
169- let exampleEl = document . getElementById ( 'setProxy' )
170- new bootstrap . Popover ( exampleEl , options )
174+ let exampleEl = document . getElementById ( 'setProxy' ) ;
175+ let popover = new bootstrap . Popover ( exampleEl , options ) ;
176+
177+ $ ( '#saveProxyServer' ) . click ( function ( event ) {
178+ event . preventDefault ( ) ;
179+ proxyServer = checkUrl ( $ ( '#proxyServerInput' ) . val ( ) ) ;
180+
181+ if ( ! proxyServer ) return ;
182+
183+ popover . hide ( ) ;
184+ } ) ;
171185} )
0 commit comments