help me write a Tampermonkey script works in https://pomf.lain.la/ to copy urls to the clipboard.
Create a Copy All URL button in form#upload-form.js to copy all hrel values inside span.file-url from ul#upload-filelist to the clipboard.
Assistant
Sure! Below is a Tampermonkey script that adds a "Copy All URLs" button to the form#upload-form.js on the specified website. The button will copy all href values inside span.file-url from ul#upload-filelist to the clipboard when clicked.
Here’s how to set it up:
Install the Tampermonkey extension for your browser, if you haven't already.
Create a new script in Tampermonkey and paste the code below into it.
javascript
// ==UserScript==
// @name Copy All URLs from Pomf
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Adds a button to copy all file URLs to clipboard
// @author Your Name
// @match https://pomf.lain.la/
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Create the Copy All URLs button
const copyButton = document.createElement('button');
copyButton.innerText = 'Copy All URLs';
copyButton.style.margin = '10px';
copyButton.style.padding = '5px 10px';
copyButton.style.cursor = 'pointer';
// Append button to the form
const uploadForm = document.querySelector('form#upload-form.js');
if (uploadForm) {
uploadForm.appendChild(copyButton);
}
// Add event listener to the button
copyButton.addEventListener('click', function() {
const urls = [];
const fileList = document.querySelectorAll('ul#upload-filelist span.file-url a');
fileList.forEach(link => {
urls.push(link.href);
});
// Copy all URLs to clipboard
if (urls.length > 0) {
const textToCopy = urls.join('\n');
navigator.clipboard.writeText(textToCopy).then(() => {
alert('URLs copied to clipboard!');
}).catch(err => {
console.error('Failed to copy: ', err);
alert('Failed to copy URLs to clipboard.');
});
} else {
alert('No URLs found to copy.');
}
});
})();
Explanation of the Script:
@name: The name of your script.
@namespace: A unique namespace for your script.
@version: The script version.
@description: Short description of what the script does.
@author: Your name or alias.
@match: Specifies the page where the script will run. In this case, it's set to your specified URL.
@grant: Defines permissions. None are needed for this script.
Script Functionality:
The script creates a button labeled "Copy All URLs."
When clicked, it gathers all the href values from the span.file-url elements inside ul#upload-filelist.
It joins these URLs into a single string separated by new lines.
It uses the Clipboard API to copy the concatenated string to the clipboard.
It provides user feedback via alert messages.
Usage:
Once the script is active, navigate to the specified website, upload files, and click the "Copy All URLs" button to copy the links to your clipboard.
Feel free to customize the script as needed.
User
Please increase the size of the button and change the background to red and the label in dark red.
Please remove notification
Assistant
Sure! Here's the modified Tampermonkey script that increases the size of the button, changes the background color to red, and updates the label color to dark red. I've also removed the notification alerts.
javascript
// ==UserScript==
// @name Copy All URLs from Pomf
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Adds a button to copy all file URLs to clipboard
// @author Your Name
// @match https://pomf.lain.la/
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Create the Copy All URLs button
const copyButton = document.createElement('button');
copyButton.innerText = 'Copy All URLs';
// Style the button
copyButton.style.margin = '10px';
copyButton.style.padding = '10px 20px'; // Increased padding for size
copyButton.style.fontSize = '16px'; // Increased font size
copyButton.style.backgroundColor = 'red'; // Red background
copyButton.style.color = 'darkred'; // Dark red text
copyButton.style.border = 'none';
copyButton.style.borderRadius = '5px';
copyButton.style.cursor = 'pointer';
// Append button to the form
const uploadForm = document.querySelector('form#upload-form.js');
if (uploadForm) {
uploadForm.appendChild(copyButton);
}
// Add event listener to the button
copyButton.addEventListener('click', function() {
const urls = [];
const fileList = document.querySelectorAll('ul#upload-filelist span.file-url a');
fileList.forEach(link => {
urls.push(link.href);
});
// Copy all URLs to clipboard
if (urls.length > 0) {
const textToCopy = urls.join('\n');
navigator.clipboard.writeText(textToCopy).catch(err => {
console.error('Failed to copy: ', err);
});
}
});
})();
User
please change background color to #c11b68 add mouse hover color to a darker shade of #c11b68. Give the button a 1 pixel border.
When pressed, change the label to white for 1 second.
Assistant
Here's the updated Tampermonkey script with your requested modifications:
The button's background color is now #c11b68.
A darker shade for the hover effect is added.
The button has a 1-pixel border.
When the button is pressed, the label changes to white for one second.
Here's the modified script:
javascript
// ==UserScript==
// @name Copy All URLs from Pomf
// @namespace http://tampermonkey.net/
// @version 1.2
// @description Adds a button to copy all file URLs to clipboard
// @author Your Name
// @match https://pomf.lain.la/
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Create the Copy All URLs button
const copyButton = document.createElement('button');
copyButton.innerText = 'Copy All URLs';
// Style the button
copyButton.style.margin = '10px';
copyButton.style.padding = '10px 20px'; // Increased padding for size
copyButton.style.fontSize = '16px'; // Increased font size
copyButton.style.backgroundColor = '#c11b68'; // Set background to #c11b68
copyButton.style.color = 'darkred'; // Dark red text
copyButton.style.border = '1px solid #8b0f4f'; // 1-pixel border
copyButton.style.borderRadius = '5px';
copyButton.style.cursor = 'pointer';
// Mouse hover effect
copyButton.style.transition = 'background-color 0.3s';
copyButton.addEventListener('mouseover', function() {
copyButton.style.backgroundColor = '#a51a59'; // Darker shade on hover
});
copyButton.addEventListener('mouseout', function() {
copyButton.style.backgroundColor = '#c11b68'; // Reset color
});
// Append button to the form
const uploadForm = document.querySelector('form#upload-form.js');
if (uploadForm) {
uploadForm.appendChild(copyButton);
}
// Add event listener to the button
copyButton.addEventListener('click', function() {
const urls = [];
const fileList = document.querySelectorAll('ul#upload-filelist span.file-url a');
fileList.forEach(link => {
urls.push(link.href);
});
// Copy all URLs to clipboard
if (urls.length > 0) {
const textToCopy = urls.join('\n');
navigator.clipboard.writeText(textToCopy).catch(err => {
console.error('Failed to copy: ', err);
});
// Change label color to white temporarily
copyButton.style.color = 'white';
setTimeout(() => {
copyButton.style.color = 'darkred'; // Change back to dark red after 1 second
}, 1000);
}
});
})();
User
when span.file-url is not present, by pressing the added button, it will jump to a page with an error "ERROR: (500) No file was uploaded" and in the console the following error apperas.
/upload.php?output=html:1
code
POST https://pomf.lain.la/upload.php?output=html 500 (Internal Server Error)
chext_driver.js:505 Initialized driver at: Tue Dec 24 2024 01:15:30 GMT+0800 (Hong Kong Standard Time)
chext_driver.js:58 [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952
ol @ chext_driver.js:58
ml @ chext_driver.js:57
ml @ chext_driver.js:57
pu @ chext_driver.js:175
Hz @ chext_driver.js:363
bA @ chext_driver.js:408
ea @ chext_driver.js:411
B.pa @ chext_driver.js:243
pa @ chext_driver.js:409
H @ chext_driver.js:414
R @ chext_driver.js:349
(anonymous) @ chext_driver.js:349
S @ chext_driver.js:233
H @ chext_driver.js:349
R @ chext_driver.js:349
B @ chext_driver.js:449
deactivate @ chext_driver.js:449
Ux @ chext_driver.js:225
Vx @ chext_driver.js:224
I @ chext_driver.js:474
ay @ chext_driver.js:226
ny @ chext_driver.js:231
ly @ chext_driver.js:229
chext_driver.js:58 [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952
ol @ chext_driver.js:58
ml @ chext_driver.js:57
ml @ chext_driver.js:57
pu @ chext_driver.js:175
Hz @ chext_driver.js:363
bA @ chext_driver.js:408
ea @ chext_driver.js:411
B.pa @ chext_driver.js:243
pa @ chext_driver.js:409
H @ chext_driver.js:414
R @ chext_driver.js:349
(anonymous) @ chext_driver.js:349
S @ chext_driver.js:233
H @ chext_driver.js:349
R @ chext_driver.js:349
B @ chext_driver.js:449
deactivate @ chext_driver.js:449
Ux @ chext_driver.js:225
Vx @ chext_driver.js:224
I @ chext_driver.js:474
ay @ chext_driver.js:226
ny @ chext_driver.js:231
ly @ chext_driver.js:229
chext_driver.js:58 [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952
ol @ chext_driver.js:58
ml @ chext_driver.js:57
ml @ chext_driver.js:57
pu @ chext_driver.js:175
Hz @ chext_driver.js:363
ea @ chext_driver.js:376
B.pa @ chext_driver.js:243
pa @ chext_driver.js:374
Oz @ chext_driver.js:378
Pz @ chext_driver.js:387
I @ chext_driver.js:405
fm @ chext_driver.js:66
B.L @ chext_driver.js:238
gt @ chext_driver.js:162
(anonymous) @ chext_driver.js:228
(anonymous) @ yue_hant_t_i0_und.js:3
(anonymous) @ yue_hant_t_i0_und.js:3
chext_driver.js:58 [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive. See
ol @ chext_driver.js:58
ml @ chext_driver.js:57
ml @ chext_driver.js:57
pu @ chext_driver.js:175
Hz @ chext_driver.js:363
ea @ chext_driver.js:376
B.pa @ chext_driver.js:243
pa @ chext_driver.js:374
Oz @ chext_driver.js:378
Pz @ chext_driver.js:387
I @ chext_driver.js:405
fm @ chext_driver.js:66
B.L @ chext_driver.js:238
Zs @ chext_driver.js:159
H @ chext_driver.js:414
R @ chext_driver.js:349
(anonymous) @ chext_driver.js:349
S @ chext_driver.js:233
H @ chext_driver.js:349
R @ chext_driver.js:349
B @ chext_driver.js:449
activate @ chext_driver.js:449
Ux @ chext_driver.js:225
ay @ chext_driver.js:226
ny @ chext_driver.js:231
ly @ chext_driver.js:229
chext_loader.js:71 Initialized chextloader at: 1734974130872
Assistant
To prevent the issue where clicking the "Copy All URLs" button results in an error when no URLs are present (e.g., when span.file-url elements are not found), we can modify the script to check for the presence of span.file-url before attempting the copy operation. If no URLs are found, we can handle it gracefully without causing an internal server error.
Updated Tampermonkey Script
Here’s the modified script:
javascript
User
problem still exists.
Assistant
To handle the situation of missing span.file-url elements more robustly and prevent the internal server error, we can ensure that the click handler does not attempt to copy URLs or execute any further actions when there are no files uploaded. However, if it's still producing an error upon clicking the button, we'll modify the logic further to explicitly check for the ul#upload-filelist presence and its children before executing actions.
Here's the updated Tampermonkey script with enhanced error handling to avoid navigation to an error page when no files are uploaded:
javascript
User
/upload.php?output=html:1
code
POST https://pomf.lain.la/upload.php?output=html 500 (Internal Server Error)
chext_driver.js:505 Initialized driver at: Tue Dec 24 2024 01:22:22 GMT+0800 (Hong Kong Standard Time)
chext_driver.js:58 [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952
ol @ chext_driver.js:58
ml @ chext_driver.js:57
ml @ chext_driver.js:57
pu @ chext_driver.js:175
Hz @ chext_driver.js:363
bA @ chext_driver.js:408
ea @ chext_driver.js:411
B.pa @ chext_driver.js:243
pa @ chext_driver.js:409
H @ chext_driver.js:414
R @ chext_driver.js:349
(anonymous) @ chext_driver.js:349
S @ chext_driver.js:233
H @ chext_driver.js:349
R @ chext_driver.js:349
B @ chext_driver.js:449
deactivate @ chext_driver.js:449
Ux @ chext_driver.js:225
Vx @ chext_driver.js:224
I @ chext_driver.js:474
ay @ chext_driver.js:226
ny @ chext_driver.js:231
ly @ chext_driver.js:229
chext_driver.js:58 [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952
ol @ chext_driver.js:58
ml @ chext_driver.js:57
ml @ chext_driver.js:57
pu @ chext_driver.js:175
Hz @ chext_driver.js:363
bA @ chext_driver.js:408
ea @ chext_driver.js:411
B.pa @ chext_driver.js:243
pa @ chext_driver.js:409
H @ chext_driver.js:414
R @ chext_driver.js:349
(anonymous) @ chext_driver.js:349
S @ chext_driver.js:233
H @ chext_driver.js:349
R @ chext_driver.js:349
B @ chext_driver.js:449
deactivate @ chext_driver.js:449
Ux @ chext_driver.js:225
Vx @ chext_driver.js:224
I @ chext_driver.js:474
ay @ chext_driver.js:226
ny @ chext_driver.js:231
ly @ chext_driver.js:229
chext_driver.js:58 [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952
ol @ chext_driver.js:58
ml @ chext_driver.js:57
ml @ chext_driver.js:57
pu @ chext_driver.js:175
Hz @ chext_driver.js:363
ea @ chext_driver.js:376
B.pa @ chext_driver.js:243
pa @ chext_driver.js:374
Oz @ chext_driver.js:378
Pz @ chext_driver.js:387
I @ chext_driver.js:405
fm @ chext_driver.js:66
B.L @ chext_driver.js:238
gt @ chext_driver.js:162
(anonymous) @ chext_driver.js:228
(anonymous) @ yue_hant_t_i0_und.js:3
(anonymous) @ yue_hant_t_i0_und.js:3
chext_driver.js:58 [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive. See
ol @ chext_driver.js:58
ml @ chext_driver.js:57
ml @ chext_driver.js:57
pu @ chext_driver.js:175
Hz @ chext_driver.js:363
ea @ chext_driver.js:376
B.pa @ chext_driver.js:243
pa @ chext_driver.js:374
Oz @ chext_driver.js:378
Pz @ chext_driver.js:387
I @ chext_driver.js:405
fm @ chext_driver.js:66
B.L @ chext_driver.js:238
Zs @ chext_driver.js:159
H @ chext_driver.js:414
R @ chext_driver.js:349
(anonymous) @ chext_driver.js:349
S @ chext_driver.js:233
H @ chext_driver.js:349
R @ chext_driver.js:349
B @ chext_driver.js:449
activate @ chext_driver.js:449
Ux @ chext_driver.js:225
ay @ chext_driver.js:226
ny @ chext_driver.js:231
ly @ chext_driver.js:229
chext_loader.js:71 Initialized chextloader at: 1734974542387
Assistant
Since the issue persists, let's take a step back and identify precisely how we can prevent the internal server error when no files have been uploaded. The goal is to ensure that no submission or request is inadvertently made when there are no span.file-url elements, and consequently, no URLs available for copying.
In the previous scripts, the logic we have used was aimed at merely checking if the URLs exist. However, it appears that some form of submission is still being triggered, which could relate to how the browser environment is processing the clicks on the button.
Full Solution:
Prevent Default Behavior: We'll ensure the button does not invoke any default behaviors that could lead to unintended form submissions.
Use Event.preventDefault(): This method halts any default actions (like form submission) that the button might trigger by default.
Check for the presence of uploaded files: Rechecking before executing the copy operation and ensuring that we are not calling any methods that could trigger a server request if there are no links.
Here’s an updated script with those mechanisms:
javascript
User
// Style the button
copyButton.style.margin = '10px';
copyButton.style.padding = '30px 20px'; // Increased padding for size
copyButton.style.fontSize = '20px'; // Increased font size
copyButton.style.backgroundColor = '#ecbad1'; // Set background to #ecbad1
copyButton.style.color = 'darkred'; // Dark red text
copyButton.style.border = '1px solid #d35f95'; // 1-pixel border
copyButton.style.borderRadius = '4px';
copyButton.style.cursor = 'pointer';
How do I move the button up by 2 pixels?
Assistant
To move the button up by 2 pixels, you can adjust the margin property. Specifically, you can modify the margin-top of the button to decrease its vertical spacing, thereby effectively moving it up. Since the current margin applies 10px for all sides, you may want to either change the top margin alone or decrease the total margin a bit.
Here’s how to adjust it:
javascript
// Adjusting the margin to move the button up by 2 pixels
copyButton.style.margin = '8px 10px 10px 10px'; // Top margin set to 8px (moves up 2px)
Complete Styling Example:
Here's how the button styling might look with the adjustment included:
javascript
// Style the button
copyButton.style.margin = '8px 10px 10px 10px'; // Move the button up by 2 pixels
copyButton.style.padding = '30px 20px'; // Increased padding for size
copyButton.style.fontSize = '20px'; // Increased font size
copyButton.style.backgroundColor = '#ecbad1'; // Set background to #ecbad1
copyButton.style.color = 'darkred'; // Dark red text
copyButton.style.border = '1px solid #d35f95'; // 1-pixel border
copyButton.style.borderRadius = '4px';
copyButton.style.cursor = 'pointer';
Explanation:
In margin: '8px 10px 10px 10px';, the first value (8px) is the top margin. By reducing it from 10px to 8px, you're effectively moving the button up by 2 pixels.
The subsequent values are for right, bottom, and left margins respectively and remain unchanged.
Usage:
Replace your current button style section with the above lines in your existing script. This will move the button up slightly as you requested.
Not yet included in a published release.
Changes Made:
Button Size: Adjusted the padding and font size to make the button larger.
copyButton.style.padding = '10px 20px'; increases the button's padding.
copyButton.style.fontSize = '16px'; increases the font size.
Button Background and Text Color: Set the button's background color to red and the text color to dark red.
copyButton.style.backgroundColor = 'red';
copyButton.style.color = 'darkred';
Removed Alert Notifications: The script no longer shows alerts after copying the URLs. It only logs errors to the console if the copying action fails.
Usage:
Just like before, after installing the script, navigate to the specified site, and click the new red button to copy all the URLs without any notifications.
Changes Made:
Background Color: Set to #c11b68, which is a shade of magenta.
Hover Effect: On mouse over, the background color changes to a darker shade #a51a59.
Border: Added a 1-pixel solid border with the color #8b0f4f.
Temporary Color Change on Click: When the button is pressed, the text color changes to white for one second, then reverts back to dark red.
Usage:
As before, after installing the script, navigate to the specified site, and click the button to copy all URLs. You'll see the button's text color change temporarily when clicked, and it will also change colors on hover.
// ==UserScript==
// @name Copy All URLs from Pomf
// @namespace http://tampermonkey.net/
// @version 1.3
// @description Adds a button to copy all file URLs to clipboard
// @author Your Name
// @match https://pomf.lain.la/
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Create the Copy All URLs button
const copyButton = document.createElement('button');
copyButton.innerText = 'Copy All URLs';
// Style the button
copyButton.style.margin = '10px';
copyButton.style.padding = '10px 20px'; // Increased padding for size
copyButton.style.fontSize = '16px'; // Increased font size
copyButton.style.backgroundColor = '#c11b68'; // Set background to #c11b68
copyButton.style.color = 'darkred'; // Dark red text
copyButton.style.border = '1px solid #8b0f4f'; // 1-pixel border
copyButton.style.borderRadius = '5px';
copyButton.style.cursor = 'pointer';
// Mouse hover effect
copyButton.style.transition = 'background-color 0.3s';
copyButton.addEventListener('mouseover', function() {
copyButton.style.backgroundColor = '#a51a59'; // Darker shade on hover
});
copyButton.addEventListener('mouseout', function() {
copyButton.style.backgroundColor = '#c11b68'; // Reset color
});
// Append button to the form
const uploadForm = document.querySelector('form#upload-form.js');
if (uploadForm) {
uploadForm.appendChild(copyButton);
}
// Add event listener to the button
copyButton.addEventListener('click', function() {
const urls = [];
const fileList = document.querySelectorAll('ul#upload-filelist span.file-url a');
fileList.forEach(link => {
urls.push(link.href);
});
// If there are URLs, copy them to clipboard
if (urls.length > 0) {
const textToCopy = urls.join('\n');
navigator.clipboard.writeText(textToCopy).catch(err => {
console.error('Failed to copy: ', err);
});
// Change label color to white temporarily
copyButton.style.color = 'white';
setTimeout(() => {
copyButton.style.color = 'darkred'; // Change back to dark red after 1 second
}, 1000);
} else {
// Handle the case where no URLs are found
// Optionally, you can notify the user in a different way (e.g., console log)
console.warn('No URLs found to copy. Please make sure files are uploaded.');
}
});
})();
Changes Made:
Conditional Check:
Before copying URLs, the script now checks if any URLs were found. If the urls array is empty, it handles the case gracefully by logging a warning to the console (console.warn).
Graceful Exit:
If no URLs are found, the script will not trigger any unintended behavior like navigating to an error page.
Usage:
After installing the updated script, clicking the "Copy All URLs" button will now only attempt to copy the URLs if they exist. If not, a warning will simply be logged in the console, allowing you to debug any potential issues with file uploads without causing an undesirable navigation or console spam.
This way, you'll avoid the potential "500 Internal Server Error" caused by an empty submission.
// ==UserScript==
// @name Copy All URLs from Pomf
// @namespace http://tampermonkey.net/
// @version 1.4
// @description Adds a button to copy all file URLs to clipboard
// @author Your Name
// @match https://pomf.lain.la/
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Create the Copy All URLs button
const copyButton = document.createElement('button');
copyButton.innerText = 'Copy All URLs';
// Style the button
copyButton.style.margin = '10px';
copyButton.style.padding = '10px 20px'; // Increased padding for size
copyButton.style.fontSize = '16px'; // Increased font size
copyButton.style.backgroundColor = '#c11b68'; // Set background to #c11b68
copyButton.style.color = 'darkred'; // Dark red text
copyButton.style.border = '1px solid #8b0f4f'; // 1-pixel border
copyButton.style.borderRadius = '5px';
copyButton.style.cursor = 'pointer';
// Mouse hover effect
copyButton.style.transition = 'background-color 0.3s';
copyButton.addEventListener('mouseover', function() {
copyButton.style.backgroundColor = '#a51a59'; // Darker shade on hover
});
copyButton.addEventListener('mouseout', function() {
copyButton.style.backgroundColor = '#c11b68'; // Reset color
});
// Append button to the form
const uploadForm = document.querySelector('form#upload-form.js');
if (uploadForm) {
uploadForm.appendChild(copyButton);
}
// Add event listener to the button
copyButton.addEventListener('click', function() {
// Check if the file list exists and has elements
const fileList = document.querySelector('ul#upload-filelist');
if (fileList && fileList.children.length > 0) {
const urls = [];
const fileLinks = fileList.querySelectorAll('span.file-url a');
fileLinks.forEach(link => {
urls.push(link.href);
});
// If there are URLs, copy them to clipboard
if (urls.length > 0) {
const textToCopy = urls.join('\n');
navigator.clipboard.writeText(textToCopy).catch(err => {
console.error('Failed to copy: ', err);
});
// Change label color to white temporarily
copyButton.style.color = 'white';
setTimeout(() => {
copyButton.style.color = 'darkred'; // Change back to dark red after 1 second
}, 1000);
} else {
// Handle the case where no URLs are found
console.warn('No file URLs found to copy.');
}
} else {
// Handle the case where there are no uploaded files
console.warn('No files uploaded. Please upload files before trying to copy.');
}
});
})();
Key Changes and Checks:
Checking the File List:
Before trying to gather URLs, the script now checks if the ul#upload-filelist exists and whether it has any child elements (fileList && fileList.children.length > 0).
Error Handling:
If the fileList is not present or has no children, it logs a warning to the console rather than attempting to perform a copy operation, thus preventing the navigation error.
No URL Logic:
Added handling where it logs appropriate console messages when no files are uploaded or URLs are found to guide the user through using the script correctly.
Conclusion:
This update should prevent the internal server error you previously encountered by ensuring that no network requests are made when there are no files uploaded. The console logs will help diagnose if actions are attempted when they shouldn't be. Ensure that any necessary uploads are performed before clicking the button. Test this updated script, and it should resolve the issue effectively!
// ==UserScript==
// @name Copy All URLs from Pomf
// @namespace http://tampermonkey.net/
// @version 1.5
// @description Adds a button to copy all file URLs to clipboard
// @author Your Name
// @match https://pomf.lain.la/
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Create the Copy All URLs button
const copyButton = document.createElement('button');
copyButton.innerText = 'Copy All URLs';
// Style the button
copyButton.style.margin = '10px';
copyButton.style.padding = '10px 20px'; // Increased padding for size
copyButton.style.fontSize = '16px'; // Increased font size
copyButton.style.backgroundColor = '#c11b68'; // Set background to #c11b68
copyButton.style.color = 'darkred'; // Dark red text
copyButton.style.border = '1px solid #8b0f4f'; // 1-pixel border
copyButton.style.borderRadius = '5px';
copyButton.style.cursor = 'pointer';
// Mouse hover effect
copyButton.style.transition = 'background-color 0.3s';
copyButton.addEventListener('mouseover', function() {
copyButton.style.backgroundColor = '#a51a59'; // Darker shade on hover
});
copyButton.addEventListener('mouseout', function() {
copyButton.style.backgroundColor = '#c11b68'; // Reset color
});
// Append button to the form
const uploadForm = document.querySelector('form#upload-form.js');
if (uploadForm) {
uploadForm.appendChild(copyButton);
}
// Add event listener to the button
copyButton.addEventListener('click', function(event) {
event.preventDefault(); // Prevent default form submission
const fileList = document.querySelector('ul#upload-filelist');
// Check if the file list exists and has elements
if (fileList && fileList.children.length > 0) {
const urls = [];
const fileLinks = fileList.querySelectorAll('span.file-url a');
fileLinks.forEach(link => {
urls.push(link.href);
});
// If there are URLs, copy them to clipboard
if (urls.length > 0) {
const textToCopy = urls.join('\n');
navigator.clipboard.writeText(textToCopy).catch(err => {
console.error('Failed to copy: ', err);
});
// Change label color to white temporarily
copyButton.style.color = 'white';
setTimeout(() => {
copyButton.style.color = 'darkred'; // Change back to dark red after 1 second
}, 1000);
} else {
console.warn('No file URLs found to copy.');
}
} else {
console.warn('No files uploaded. Please upload files before trying to copy.');
}
});
})();
Key Adjustments:
Preventing Default Behavior: The inclusion of event.preventDefault() ensures that clicking the button does not cause any form submission or page reload that could lead to the internal server error.
Consolidated Checks: The logic remains the same, ensuring that both the file list's existence and its children are checked before proceeding with any operations.
Usage:
Install this updated script in Tampermonkey, navigate to the relevant webpage, and test the button. The goal is to ensure no requests are being made if the conditions are not met for copying URLs.
This should effectively handle the issue you're facing. If the problem still persists, we might have to investigate whether there are other elements on the form that respond to the click or cause the request to be triggered inadvertently.