Skip to content

Commit

Permalink
adapt paste display latest pastes
Browse files Browse the repository at this point in the history
  • Loading branch information
socraticDevBlog committed Apr 21, 2024
1 parent a6cfd54 commit 46035f8
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pastebin.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h1 style="color: orange">poor man cloud-native pastebin</h1>
<div id="responseContainer"></div>
</p>
<h3 class="subtitle">your most recent pastes:</h3>
<div id="strings"></div>
<div id="latestPasteUrls"></div>
</div>
</div>
<div class="col-xs-3"></div>
Expand Down Expand Up @@ -119,22 +119,21 @@ <h3 class="subtitle">your most recent pastes:</h3>
}
}

async function displayStrings() {
async function displayPasteUrls() {
const pastebinAPI = "https://paste.socratic.dev/paste/api/pastes";

try {
const response = await fetch(pastebinAPI);
const data = await response.json();

// Get the div where we'll display the strings
const stringsDiv = document.getElementById('strings');
// Get the div where we'll display the latest Paste Urls
const urlsDiv = document.getElementById("latestPasteUrls");

// Display each string
data.forEach(string => {
// Display each Url
data.forEach(url => {
const p = document.createElement('p');
const url = `https://paste.socratic.dev/paste?id=${encodeURIComponent(string)}`;
p.innerHTML = `<a href="${url}" target="_blank">${url}</a>`;
stringsDiv.appendChild(p);
urlsDiv.appendChild(p);
});
} catch (error) {
console.error("Error fetching strings from API:", error);
Expand All @@ -143,7 +142,7 @@ <h3 class="subtitle">your most recent pastes:</h3>
}

window.onload = function() {
displayStrings();
displayPasteUrls();
};
</script>
<div style="margin-top: 260px;">
Expand Down

0 comments on commit 46035f8

Please sign in to comment.