Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Checkbox for JPG Files
- // @namespace http://tampermonkey.net/
- // @version 1.0
- // @description Creates checkboxes for filenames ending in .jpg and allows copying selected checkboxes to clipboard.
- // @author Your Name
- // @match https://animated-character-database.fandom.com/wiki/Special:UnusedFiles
- // @match https://animated-character-database.fandom.com/wiki/*
- // @grant GM_setClipboard
- // ==/UserScript==
- (function() {
- 'use strict';
- // Helper function to copy text to clipboard
- function copyToClipboard(text) {
- const el = document.createElement('textarea');
- el.value = text;
- document.body.appendChild(el);
- el.select();
- document.execCommand('copy');
- document.body.removeChild(el);
- }
- // Find all filenames ending in .jpg
- const fileElements = Array.from(document.querySelectorAll('a[href$=".jpg"]'));
- // Create checkboxes for each filename
- fileElements.forEach((element) => {
- const checkbox = document.createElement('input');
- checkbox.type = 'checkbox';
- const originalFilename = element.getAttribute('title');
- const cleanedFilename = removeParentheses(originalFilename);
- checkbox.dataset.imageName = cleanedFilename;
- element.parentNode.insertBefore(checkbox, element);
- }); //2201992 title
- // Create a "Copy to Clipboard" button
- const button = document.createElement('button');
- button.textContent = 'Copy to Clipboard';
- button.style.marginTop = '10px';
- button.addEventListener('click', () => {
- const selectedCheckboxes = Array.from(document.querySelectorAll('input[type="checkbox"]:checked'));
- const selectedFilenames = selectedCheckboxes.map((checkbox) => checkbox.dataset.imageName);
- const filenamesText = selectedFilenames.join('\n');
- copyToClipboard(filenamesText);
- alert('Selected filenames copied to clipboard!');
- });
- // Append the button to the bottom of the page
- document.body.appendChild(button);
- })();
- // Function to remove parentheses and content inside them
- function removeParentheses(text) {
- return text.replace(/\([^)]*\)/g, '');
- }
- // Process text nodes in the document
- function processTextNodes(node) {
- if (node.nodeType === Node.TEXT_NODE) {
- node.textContent = removeParentheses(node.textContent);
- } else {
- for (const childNode of node.childNodes) {
- processTextNodes(childNode);
- }
- }
- }
- // Start processing when the DOM is ready
- document.addEventListener('DOMContentLoaded', function() {
- processTextNodes(document.body);
- });
Advertisement
Add Comment
Please, Sign In to add comment