mirror of
https://github.com/gigirassy/plaster.git
synced 2024-12-23 18:39:07 +00:00
Update client.js
This commit is contained in:
parent
65650e4dfa
commit
fd14c7353d
@ -1,7 +1,24 @@
|
||||
document.getElementById('fetchBtn').addEventListener('click', async () => {
|
||||
document.getElementById('fetchBtn').addEventListener('click', () => {
|
||||
const urlInput = document.getElementById('pasteUrl').value;
|
||||
|
||||
// Perform a redirection by using the input URL directly
|
||||
const redirectUrl = `/fetch-paste?url=${encodeURIComponent(urlInput)}`;
|
||||
window.location.href = redirectUrl; // This redirects the user to the raw paste URL
|
||||
// Extract the Paste ID from the provided Pastebin URL
|
||||
const pasteId = getPasteId(urlInput);
|
||||
|
||||
if (pasteId) {
|
||||
// Redirect to the raw paste route on your server
|
||||
window.location.href = `http://localhost:3000/${pasteId}`;
|
||||
} else {
|
||||
alert('Please enter a valid Pastebin URL.');
|
||||
}
|
||||
});
|
||||
|
||||
function getPasteId(url) {
|
||||
// Check if the URL is a valid Pastebin URL and extract the Paste ID
|
||||
const regex = /pastebin\.com\/(?:raw\/)?([a-zA-Z0-9]+)/;
|
||||
const match = url.match(regex);
|
||||
|
||||
if (match) {
|
||||
return match[1]; // Return the Paste ID
|
||||
}
|
||||
return null; // Invalid Pastebin URL
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user