Compare commits

..

13 Commits

Author SHA1 Message Date
nune
68e701dd21
Update README.md 2024-12-19 19:45:49 -05:00
nune
6c123e39ae
Update compose.yml 2024-12-19 19:44:56 -05:00
nune
0328c8fb4b
Update client.js 2024-12-19 19:39:15 -05:00
nune
71fc7aab22
Update app.js 2024-12-19 19:38:42 -05:00
nune
3ac7f784af
Update package.json 2024-12-19 19:28:08 -05:00
nune
4daf9bcb78
Update package.json 2024-12-19 19:25:15 -05:00
nune
1021a81f1c
Update package.json 2024-12-19 19:20:35 -05:00
nune
b5e185ab6b
Update client.js 2024-12-19 19:15:55 -05:00
nune
7a1cb27f5b
Update index.html 2024-12-19 19:13:56 -05:00
nune
3be15e71cb
Update app.js 2024-12-19 19:12:43 -05:00
nune
24b0d577e9
Update README.md 2024-12-19 18:57:38 -05:00
nune
4e25322071
Update README.md 2024-12-19 18:55:06 -05:00
nune
7cfdc5ba03
Update package.json 2024-12-19 13:49:56 -05:00
6 changed files with 94 additions and 19 deletions

View File

@ -2,6 +2,10 @@
Fetches raw data and displays it. Took like 20 minutes to make the first build.
It's extremely simple, so it's under CC0. If you want to improve it, simply submit a pull request.
That's all.
Disclaimer: The first build was made using a language learning model, and then significantly tweaked by a human being (me). This might be outside of people's comfort zones, so I'd thought it'd be important to note this.
## To do:
* Implement (togglable!) fetching of paste views, creator usernames, favorites, and expiration/creation dates.
* Togglable, just-for-fun ASCII art of TFA characters on front page bottom-right corner. Owners can also change this ASCII art by mounting TXT files as a volume.
### Instances
| link | country | notes |
|---------------------------|---------|-------------------|

8
app.js
View File

@ -1,10 +1,18 @@
const express = require('express');
const fetch = require('node-fetch');
const cookieParser = require('cookie-parser');
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.static('public'));
app.use(cookieParser());
const autoCopyDefault = process.env.AUTO_COPY_DEFAULT === 'true';
app.get('/auto-copy-default', (req, res) => {
res.json({ autoCopyDefault });
});
// Route to handle raw Pastebin requests
app.get('/:pasteId', async (req, res) => {

View File

@ -5,5 +5,7 @@ services:
image: ghcr.io/gigirassy/plaster
ports:
- "35200:3000" # change host port if needed
environment:
AUTO_COPY_DEFAULT: "false" # if enabled, this will automatically copy paste contents to the clipboard on main page
restart: always
container_name: plaster

View File

@ -12,10 +12,11 @@
"nodejs",
"express"
],
"author": "Your Name",
"author": "nune",
"license": "CC0",
"dependencies": {
"express": "^4.18.2",
"node-fetch": "^2.6.7"
"node-fetch": "^2.6.7",
"cookie-parser": "^1.4.7"
}
}

View File

@ -1,23 +1,79 @@
document.getElementById('fetchBtn').addEventListener('click', () => {
const urlInput = document.getElementById('pasteUrl').value;
document.addEventListener('DOMContentLoaded', async () => {
const fetchBtn = document.getElementById('fetchBtn');
const pasteUrlInput = document.getElementById('pasteUrl');
const autoCopyCheckbox = document.getElementById('autoCopyCheckbox');
// Extract the Paste ID from the provided Pastebin URL
const pasteId = getPasteId(urlInput);
// Load default state for the checkbox
const defaultAutoCopy = await getDefaultAutoCopy();
const userPreference = getCookie('autoCopyEnabled');
autoCopyCheckbox.checked = userPreference !== null ? userPreference === 'true' : defaultAutoCopy;
if (pasteId) {
window.location.href = `/${pasteId}`;
} else {
alert('Please enter a valid Pastebin URL.');
}
// Save user preference to a cookie when the checkbox changes
autoCopyCheckbox.addEventListener('change', () => {
setCookie('autoCopyEnabled', autoCopyCheckbox.checked, 365);
});
// Handle "Go to Raw Paste" button click
fetchBtn.addEventListener('click', async () => {
const urlInput = pasteUrlInput.value.trim();
const pasteId = getPasteId(urlInput);
if (!pasteId) {
alert('Please enter a valid Pastebin URL.');
return;
}
const frontendUrl = `/${pasteId}`;
// If auto-copy is enabled, fetch and copy the paste contents
if (autoCopyCheckbox.checked) {
try {
const response = await fetch(frontendUrl);
if (response.ok) {
const pasteContents = await response.text();
await navigator.clipboard.writeText(pasteContents);
alert('Raw paste contents copied to clipboard!');
} else {
alert('Failed to fetch paste contents.');
}
} catch (error) {
alert('Error copying to clipboard: ' + error.message);
}
}
// Redirect to the frontend paste URL
window.location.href = frontendUrl;
});
});
// Utility function to get the default auto-copy value from the server
async function getDefaultAutoCopy() {
try {
const response = await fetch('/auto-copy-default');
if (response.ok) {
const data = await response.json();
return data.autoCopyDefault;
}
} catch (error) {
console.error('Error fetching auto-copy default:', error);
}
return false; // Default fallback
}
// Extract Paste ID from the given 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);
return match ? match[1] : null;
}
if (match) {
return match[1]; // Return the Paste ID
// Utility functions to manage cookies
function setCookie(name, value, days) {
const expires = new Date(Date.now() + days * 86400000).toUTCString();
document.cookie = `${name}=${value}; expires=${expires}; path=/`;
}
return null; // Invalid Pastebin URL
function getCookie(name) {
const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`));
return match ? decodeURIComponent(match[1]) : null;
}

View File

@ -54,6 +54,10 @@
<p>All issues regarding paste content should be reported to <a href="https://pastebin.com">Pastebin</a>. In addition, if you want a real alternative to Pastebin, <a href="https://privatebin.info">check out Privatebin!</a></p>
<input type="text" id="pasteUrl" placeholder="Enter Pastebin URL">
<button id="fetchBtn">go!</button>
<label>
<input type="checkbox" id="autoCopyCheckbox">
auto-copy paste contents?
</label>
<script src="client.js" defer></script>
<p><a href="https://github.com/gigirassy/plaster">source code</a> is licensed under the public domain</p></div>
</body>