Skip to content

Commit 3eeeb07

Browse files
committed
make proxy server change workable
1 parent 95c341c commit 3eeeb07

File tree

2 files changed

+50
-34
lines changed

2 files changed

+50
-34
lines changed

checker.js

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
let 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

39
function 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

150153
document.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
})

index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@
5757
<div hidden >
5858
<div data-name="popover-content">
5959
<div class="input-group">
60-
<input type="text" class="form-control form-control-sm" value="https://api.allorigins.win/get?url=" placeholder="Enter proxy server url" name="proxyName" value="">
60+
<input type="url" id="proxyServerInput" class="form-control form-control-sm" value="https://api.allorigins.win/get?url=" placeholder="Enter proxy server url" name="proxyName">
6161
<div class="input-group-btn">
62-
<button class="btn btn-primary" type="submit">
62+
<button id="saveProxyServer" style="margin-left: 5px;" class="btn btn-primary" type="submit">
6363
<i class="bi bi-check2-circle"></i>
6464
</button>
6565
</div>
66+
6667
</div>
68+
<div style="display: block;"><small ><a href="">Why you need to change ?</a></small></div>
6769
</div>
6870
</div>
6971
<a id="setProxy" tabindex="0" style="height: 47px; margin-left: 5px; border-radius: 5px;" class="btn btn-lg btn-secondary" role="button" data-bs-toggle="popover" title="Change proxy server" ><i class="bi bi-gear-wide-connected"></i></a>
@@ -83,7 +85,7 @@
8385
</div>
8486
<div class="col-4">
8587
<div class="alert alert-primary d-flex flex-column align-items-center text-center" role="alert">
86-
<i class="bi bi-type-bold mb-2" style="font-size: 2rem;"></i>
88+
<i class="bi bi-journal-album mb-2" style="font-size: 2rem;"></i>
8789
<div>
8890
<strong>Tip 1:</strong> Use descriptive and keyword-rich titles to improve your page's visibility.
8991
</div>

0 commit comments

Comments
 (0)