Compare commits

..

No commits in common. "68e701dd2186043881ee0be735e28992cb30da17" and "e2c1fdb3833555568d8957198e806b439e3368ce" have entirely different histories.

6 changed files with 19 additions and 94 deletions

View File

@ -2,10 +2,6 @@
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,18 +1,10 @@
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,7 +5,5 @@ 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,11 +12,10 @@
"nodejs",
"express"
],
"author": "nune",
"author": "Your Name",
"license": "CC0",
"dependencies": {
"express": "^4.18.2",
"node-fetch": "^2.6.7",
"cookie-parser": "^1.4.7"
"node-fetch": "^2.6.7"
}
}

View File

@ -1,79 +1,23 @@
document.addEventListener('DOMContentLoaded', async () => {
const fetchBtn = document.getElementById('fetchBtn');
const pasteUrlInput = document.getElementById('pasteUrl');
const autoCopyCheckbox = document.getElementById('autoCopyCheckbox');
// Load default state for the checkbox
const defaultAutoCopy = await getDefaultAutoCopy();
const userPreference = getCookie('autoCopyEnabled');
autoCopyCheckbox.checked = userPreference !== null ? userPreference === 'true' : defaultAutoCopy;
// 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;
});
document.getElementById('fetchBtn').addEventListener('click', () => {
const urlInput = document.getElementById('pasteUrl').value;
// Extract the Paste ID from the provided Pastebin URL
const pasteId = getPasteId(urlInput);
if (pasteId) {
window.location.href = `/${pasteId}`;
} else {
alert('Please enter a valid Pastebin URL.');
}
});
// 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;
}
// 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=/`;
}
function getCookie(name) {
const match = document.cookie.match(new RegExp(`(?:^|; )${name}=([^;]*)`));
return match ? decodeURIComponent(match[1]) : null;
if (match) {
return match[1]; // Return the Paste ID
}
return null; // Invalid Pastebin URL
}

View File

@ -54,10 +54,6 @@
<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>