// Store ZIP links in memory
const zip1Links = JSON.parse(localStorage.getItem('wnacg-zip1-links')) || [];
const zip2Links = JSON.parse(localStorage.getItem('wnacg-zip2-links')) || [];
// Function to extract ThreadLink and DownloadLink from gallery items
function extractLinks() {
const galleryItems = document.querySelectorAll('li.li.gallary_item div.info');
galleryItems.forEach(item => {
const picBox = item.parentElement.querySelector('div.pic_box[class="cate-"] a');
if (picBox) {
const href = picBox.getAttribute('href');
const threadLink =
https://www.wnacg.com${href}
;
code
const downloadLink = threadLink.replace('/photos', '/download');
const title = picBox.getAttribute('title'); // Get Title attribute
if (title) {
addZIPButtons(item, downloadLink, title); // Pass title to addZIPButtons
}
}
});
}
// Function to add ZIP buttons to a gallery item's title
function addZIPButtons(titleElement, downloadLink, title) {
const zip1Button = document.createElement('span');
zip1Button.textContent = 'ZIP 1';
zip1Button.classList.add('custom-button');
zip1Button.addEventListener('click', (e) => {
e.preventDefault();
getZIPLinks(downloadLink, 0);
});
// Function to add all ZIP links to the download list
function addAllZipLinks() {
const galleryItems = document.querySelectorAll('li.li.gallary_item div.info');
galleryItems.forEach(item => {
const picBox = item.parentElement.querySelector('div.pic_box[class="cate-"] a');
if (picBox) {
const href = picBox.getAttribute('href');
const threadLink =
https://www.wnacg.com${href}
;
const downloadLink = threadLink.replace('/photos', '/download');
fetch(downloadLink)
.then(response => response.text())
.then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const zipLinks = doc.querySelectorAll('div#adsbox.ads.RMss1.ad.google-ads.download_btn a.down_btn.ads');
if (zipLinks[0]) zip1Links.push(zipLinks[0].href);
if (zipLinks[1]) zip2Links.push(zipLinks[1].href);
localStorage.setItem('wnacg-zip1-links', JSON.stringify(zip1Links));
localStorage.setItem('wnacg-zip2-links', JSON.stringify(zip2Links));
})
.catch(error => {
console.error('Error fetching ZIP links:', error);
});
}
});
}
// Function to create text files from stored links
function createTextFiles() {
createFileFromLinks(zip1Links, 'zip1_download_list.txt');
createFileFromLinks(zip2Links, 'zip2_download_list.txt');
}
// Function to create a downloadable text file
function createFileFromLinks(links, filename) {
const blob = new Blob([links.join('\n')], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
// Function to clear the list of copied links
function clearList() {
zip1Links.length = 0;
zip2Links.length = 0;
localStorage.removeItem('wnacg-zip1-links');
localStorage.removeItem('wnacg-zip2-links');
}
// Function to show unique titles in a new tab
function showUniqueTitles() {
const uniqueTitles = new Set();
const galleryItems = document.querySelectorAll('li.li.gallary_item div.info');
galleryItems.forEach(item => {
const picBox = item.parentElement.querySelector('div.pic_box[class="cate-"] a');
if (picBox) {
const title = picBox.getAttribute('title');
if (title) uniqueTitles.add(title);
}
});
const newTab = window.open();
newTab.document.write('
Unique Titles:
');
uniqueTitles.forEach(title => {
newTab.document.write(
${title}
);
});
newTab.document.write('
');
newTab.document.close();
}
// Run the script
extractLinks();
addDownloadListButtons();
})();
I have a tampermonkey script which is having some problems. Here is the list.
I would like to have the links copied alert removed.
Move the Create Text Files button to the right side of the Clear List Button.
The Clear List button should clear the memory instead of clear the buttons inside div.cc.filter
Instead of displaying the download list in the memory at the bottom of the page, I would like to open a new tab and display the Title attribute for picBox associated with the download list. Since Zip 1 and Zip 2 have the same Title attribute, therefore only need to display one set without duplicates.
The memory should be stored even if the page is refreshed.
Assistant
Let's address each of your points in order and update the Tampermonkey script accordingly:
1. Remove the Links Copied Alert:
Since there is no explicit links copied alert in the script you provided, I assume you're referring to an unwanted notification or console message. If you want to remove any console messages related to this, make sure you're not logging unnecessary information using console.log().
2. Move the "Create Text Files" Button:
Ensure that the "Create Text Files" button is correctly positioned to the right of the "Clear List" button. The buttons are appended in sequence, so you may need to adjust their order in the addDownloadListButtons() function.
3. Clear Memory Instead of Just Buttons:
The clear function already removes the links from localStorage. I will ensure the function also clears any cached links in memory.
4. Open a New Tab to Display Unique Titles:
This requires tweaking the function to capture unique titles and display them in a new tab.
5. Preserve Memory After Page Refresh:
The script already uses localStorage to persist data between page reloads, so this should work correctly as long as localStorage is properly used.
Here is the modified script with these adjustments:
javascript
User
Sorry...please modify this script instead.
// ==UserScript==
// @name Add ZIP Buttons
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Add ZIP buttons to wnacg.com gallery items
// @author You
// @match https://www.wnacg.com/*
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
code
Assistant
Let's adjust the Tampermonkey script to address your specific requests:
Remove the links copied alert.
Position the "Create Text Files" button to the right of the "Clear List" button.
Ensure that the "Clear List" button clears the memory instead of just removing elements from the div.cc.filter.
Display the unique titles by opening a new tab instead of showing the download list at the bottom.
Persist storage across page refreshes.
Here's the modified version of your script:
javascript
User
The download list shows in the tab should reflex the stored memory but without duplicates. In other words, if the download list consider of 3 pages of memory, the tab should have titles for all 3 pages instead of showing the current page only.
Also, please make the buttons turn grey for 3 second once they are pressed .
Assistant
To address your requirements, we need to do the following:
Ensure that the titles displayed in the new tab are derived from all stored ZIP links, avoiding duplicates, irrespective of the current page.
Implement a temporary feedback mechanism where buttons turn grey for 3 seconds upon being pressed.
Here’s how you can modify the Tampermonkey script to incorporate these changes:
javascript
User
the buttons are gone...only the first galleryItems has zip1 and zip2 buttons
Assistant
It looks like there was an issue with how the ZIP buttons were being added to each gallery item. I'll correct this and ensure that the buttons are properly attached to all the relevant items. Additionally, I'll ensure that the global title set is updated correctly and that the persistent storage is handled accurately.
Here is the revised script:
javascript
User
how do I lower the buttons located in div.cc.filter
Assistant
To vertically adjust the position of the buttons within div.cc.filter, you can utilize CSS to modify the margin or padding of the buttons themselves or adjust the styles of the parent container. Here’s a quick way to do it:
Adjust the CSS of the buttons: Increase the margin-top on the buttons to push them lower within their container.
Adjust the padding or margin of div.cc.filter: If you want to adjust the container itself, you can add padding or margin to the top of the container.
I’ll modify the script to add some margin at the top of the buttons to move them lower:
javascript
User
This is the only line you have added to the script?
margin-top: 10px; /* Add top margin to lower the buttons */
Assistant
Yes, the line margin-top: 10px; within the CSS block for .custom-button is intended to create additional space above each button, effectively lowering the buttons within their container (div.cc.filter). By changing this value, you can control how much the buttons are shifted downward vertically.
If you'd like to see a bigger adjustment to the position or want to further tweak their layout, you can modify this margin-top value or combine it with other CSS properties (like padding-top for the parent container) to achieve your desired positioning.
If additional adjustments are needed, consider inspecting the elements using browser developer tools to find any conflicting styles or structural elements that might be affecting the layout.
User
it is not lowering the buttons.
Assistant
If the margin-top adjustment didn't lower the buttons as expected, there could be several reasons why the change isn't taking effect. Let's explore a few possibilities and additional strategies:
Possible Causes and Solutions
CSS Specificity: If there are more specific CSS rules targeting the buttons, they might override the styles applied by the user script. Ensure that your styles have higher specificity or use !important to override other styles.
Container Style Conflicts: The parent container (div.cc.filter) might have styles that prevent the margin-top from having any visible effect, such as display: flex; or display: inline-block;.
Alternative Methods: Sometimes using margins doesn't have the desired effect due to the container's layout methods. Consider using padding within the container, adjusting the display settings, or applying a margin-top to the div.cc.filter itself.
Here's a revised style attempt. I'll add some additional styles and methods you can use to debug:
javascript
User
Thanks!
Assistant
You're welcome! If you have any more questions or need further assistance, feel free to ask. Happy coding!
// ==UserScript==
// @name Add ZIP Buttons
// @namespace http://tampermonkey.net/
// @version 1.3
// @description Add ZIP buttons to wnacg.com gallery items
// @author You
// @match https://www.wnacg.com/
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
// Add custom button style
GM_addStyle(`
.custom-button { padding: 1px 5px; font-size: 12px; color: #c11b68; background-color: #d4d4d4; border: 1px solid #c11b68; border-radius: 4px; cursor: pointer; margin-right: 10px; }
.custom-button:focus { background-color: #c11b68; color: #d4d4d4; }
`);
// Store ZIP links in memory
const zip1Links = JSON.parse(localStorage.getItem('wnacg-zip1-links')) || [];
const zip2Links = JSON.parse(localStorage.getItem('wnacg-zip2-links')) || [];
// Function to extract ThreadLink and DownloadLink from gallery items
function extractLinks() {
const galleryItems = document.querySelectorAll('li.li.gallary_item div.info');
galleryItems.forEach(item => {
const picBox = item.parentElement.querySelector('div.pic_box[class="cate-"] a');
if (picBox) {
const href = picBox.getAttribute('href');
const threadLink = `https://www.wnacg.com${href}`;
const downloadLink = threadLink.replace('/photos', '/download');
const title = picBox.getAttribute('title'); // Get Title attribute
if (title) {
addZIPButtons(item, downloadLink, title); // Pass title to addZIPButtons
}
}
});
}
// Function to add ZIP buttons to a gallery item's title
function addZIPButtons(titleElement, downloadLink, title) {
const zip1Button = document.createElement('span');
zip1Button.textContent = 'ZIP 1';
zip1Button.classList.add('custom-button');
zip1Button.addEventListener('click', (e) => {
e.preventDefault();
getZIPLinks(downloadLink, 0);
});
const zip2Button = document.createElement('span');
zip2Button.textContent = 'ZIP 2';
zip2Button.classList.add('custom-button');
zip2Button.addEventListener('click', (e) => {
e.preventDefault();
getZIPLinks(downloadLink, 1);
});
titleElement.appendChild(zip1Button);
titleElement.appendChild(zip2Button);
}
// Function to retrieve ZIP links from the download page
function getZIPLinks(downloadLink, index) {
fetch(downloadLink)
.then(response => response.text())
.then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const zipLinks = doc.querySelectorAll('div#adsbox.ads.RMss1.ad.google-ads.download_btn a.down_btn.ads');
if (zipLinks[index]) {
const zipLink = zipLinks[index].href;
if (index === 0) {
zip1Links.push(zipLink);
localStorage.setItem('wnacg-zip1-links', JSON.stringify(zip1Links));
} else {
zip2Links.push(zipLink);
localStorage.setItem('wnacg-zip2-links', JSON.stringify(zip2Links));
}
window.location.href = zipLink;
} else {
console.error('ZIP link not found.');
}
})
.catch(error => {
console.error('Error fetching ZIP links:', error);
});
}
// Function to add buttons in div.cc.filter
function addDownloadListButtons() {
const filterDiv = document.querySelector('div.cc.filter');
if (filterDiv) {
const addToDownloadListButton = document.createElement('span');
addToDownloadListButton.textContent = 'Add to Download List';
addToDownloadListButton.classList.add('custom-button');
addToDownloadListButton.addEventListener('click', (e) => {
e.preventDefault();
addAllZipLinks();
});
const clearListButton = document.createElement('span');
clearListButton.textContent = 'Clear List';
clearListButton.classList.add('custom-button');
clearListButton.addEventListener('click', (e) => {
e.preventDefault();
clearList();
});
const createTextFileButton = document.createElement('span');
createTextFileButton.textContent = 'Create Text Files';
createTextFileButton.classList.add('custom-button');
createTextFileButton.style.marginRight = '0'; // No right margin to move it closer to the other button
createTextFileButton.addEventListener('click', (e) => {
e.preventDefault();
createTextFiles();
});
filterDiv.appendChild(addToDownloadListButton);
filterDiv.appendChild(clearListButton);
filterDiv.appendChild(createTextFileButton);
}
}
// Function to add all ZIP links to the download list
function addAllZipLinks() {
const galleryItems = document.querySelectorAll('li.li.gallary_item div.info');
galleryItems.forEach(item => {
const picBox = item.parentElement.querySelector('div.pic_box[class="cate-"] a');
if (picBox) {
const href = picBox.getAttribute('href');
const threadLink = `https://www.wnacg.com${href}`;
const downloadLink = threadLink.replace('/photos', '/download');
fetch(downloadLink)
.then(response => response.text())
.then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const zipLinks = doc.querySelectorAll('div#adsbox.ads.RMss1.ad.google-ads.download_btn a.down_btn.ads');
if (zipLinks[0]) zip1Links.push(zipLinks[0].href);
if (zipLinks[1]) zip2Links.push(zipLinks[1].href);
localStorage.setItem('wnacg-zip1-links', JSON.stringify(zip1Links));
localStorage.setItem('wnacg-zip2-links', JSON.stringify(zip2Links));
})
.catch(error => {
console.error('Error fetching ZIP links:', error);
});
}
});
}
// Function to create text files from stored links
function createTextFiles() {
createFileFromLinks(zip1Links, 'zip1_download_list.txt');
createFileFromLinks(zip2Links, 'zip2_download_list.txt');
}
// Function to create a downloadable text file
function createFileFromLinks(links, filename) {
const blob = new Blob([links.join('\n')], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
// Function to clear the list of copied links
function clearList() {
while (zip1Links.length > 0) { zip1Links.pop(); }
while (zip2Links.length > 0) { zip2Links.pop(); }
localStorage.removeItem('wnacg-zip1-links');
localStorage.removeItem('wnacg-zip2-links');
}
// Function to show unique titles in a new tab
function showUniqueTitles() {
const uniqueTitles = new Set();
const galleryItems = document.querySelectorAll('li.li.gallary_item div.info');
galleryItems.forEach(item => {
const picBox = item.parentElement.querySelector('div.pic_box[class="cate-"] a');
if (picBox) {
const title = picBox.getAttribute('title');
if (title) uniqueTitles.add(title);
}
});
const newTab = window.open();
newTab.document.body.innerHTML = '<h1>Unique Titles:</h1><ul>' +
Array.from(uniqueTitles).map(title => `<li>${title}</li>`).join('') +
'</ul>';
}
// Run the script
extractLinks();
addDownloadListButtons();
})();
Additional Notes:
Formatting and Style: Ensure the CSS for .custom-button has proper margins configured to ensure spacing between buttons is as desired.
Error Handling: Consider adding more robust error checks and alternative fallbacks if network requests fail.
With these updates, the script should meet your requirements. Make sure you test the updated script thoroughly to confirm everything functions as expected.
// Add custom button style
GM_addStyle(`
.custom-button {
padding: 1px 5px;
font-size: 12px;
color: #c11b68;
background-color: #d4d4d4;
border: 1px solid #c11b68;
border-radius: 4px;
cursor: pointer;
margin-right: 0px;
margin-left: 10px;
}
.custom-button:focus {
background-color: #c11b68;
color: #d4d4d4;
border: 1px solid #d4d4d4;
}
`);
// Store ZIP links in memory
const zip1Links = [];
const zip2Links = [];
// Function to extract ThreadLink and DownloadLink from gallery items
function extractLinks() {
const galleryItems = document.querySelectorAll('li.li.gallary_item div.info');
galleryItems.forEach(item => {
const picBox = item.parentElement.querySelector('div.pic_box[class*="cate-"] a');
if (picBox) {
const href = picBox.getAttribute('href');
const threadLink = `https://www.wnacg.com${href}`;
const downloadLink = threadLink.replace('/photos', '/download');
// Add ZIP buttons to the gallery item's title
const title = item.querySelector('div.info_col');
if (title) {
addZIPButtons(title, downloadLink);
}
}
});
}
// Function to add ZIP buttons to a gallery item's title
function addZIPButtons(title, downloadLink) {
// Create ZIP 1 button
const zip1Button = document.createElement('span');
zip1Button.textContent = 'ZIP 1';
zip1Button.classList.add('custom-button');
zip1Button.addEventListener('click', (e) => {
e.preventDefault();
getZIPLinks(downloadLink, 0);
});
// Create ZIP 2 button
const zip2Button = document.createElement('span');
zip2Button.textContent = 'ZIP 2';
zip2Button.classList.add('custom-button');
zip2Button.addEventListener('click', (e) => {
e.preventDefault();
getZIPLinks(downloadLink, 1);
});
// Append buttons to the title
title.appendChild(zip1Button);
title.appendChild(zip2Button);
}
// Function to retrieve ZIP links from the download page
function getZIPLinks(downloadLink, index) {
if (!localStorage.getItem('wnacg-zip-links')) {
// Fetch the download link and add to the respective array
fetch(downloadLink)
.then(response => response.text())
.then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const zipLinks = doc.querySelectorAll('div#adsbox.ads.RMss1.ad.google-ads.download_btn a.down_btn.ads');
if (zipLinks[index]) {
const zipLink = zipLinks[index].href;
// Add link to respective array
if (index === 0) {
zip1Links.push(zipLink);
} else {
zip2Links.push(zipLink);
}
// Actually download the ZIP file
window.location.href = zipLink;
} else {
alert('ZIP link not found.');
}
})
.catch(error => {
console.error('Error fetching ZIP links:', error);
});
} else {
alert('You have already copied links from this page.');
}
}
// Function to add buttons in div.cc.filter
function addDownloadListButtons() {
const filterDiv = document.querySelector('div.cc.filter');
if (filterDiv) {
// Button to add to download list
const addToDownloadListButton = document.createElement('span');
addToDownloadListButton.textContent = 'Add to Download List';
addToDownloadListButton.classList.add('custom-button');
addToDownloadListButton.addEventListener('click', (e) => {
e.preventDefault();
addAllZipLinks(); // Call function to add links to memory
});
// Button to create text files
const createTextFileButton = document.createElement('span');
createTextFileButton.textContent = 'Create Text Files';
createTextFileButton.classList.add('custom-button');
createTextFileButton.addEventListener('click', (e) => {
e.preventDefault();
createTextFiles(); // Call function to create text files
});
// Button to show list
const showListButton = document.createElement('span');
showListButton.textContent = 'Show List';
showListButton.classList.add('custom-button');
showListButton.addEventListener('click', (e) => {
e.preventDefault();
showList(); // Call function to show list
});
// Button to clear list
const clearListButton = document.createElement('span');
clearListButton.textContent = 'Clear List';
clearListButton.classList.add('custom-button');
clearListButton.addEventListener('click', (e) => {
e.preventDefault();
clearList(); // Call function to clear list
});
// Append buttons to the filterDiv
filterDiv.appendChild(addToDownloadListButton);
filterDiv.appendChild(createTextFileButton);
filterDiv.appendChild(showListButton);
filterDiv.appendChild(clearListButton);
}
}
// Function to add all ZIP links to the download list
function addAllZipLinks() {
if (!localStorage.getItem('wnacg-zip-links')) {
const galleryItems = document.querySelectorAll('li.li.gallary_item div.info');
galleryItems.forEach(item => {
const picBox = item.parentElement.querySelector('div.pic_box[class*="cate-"] a');
if (picBox) {
const href = picBox.getAttribute('href');
const threadLink = `https://www.wnacg.com${href}`;
const downloadLink = threadLink.replace('/photos', '/download');
// Fetch the download link and add to the respective array
fetch(downloadLink)
.then(response => response.text())
.then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const zipLinks = doc.querySelectorAll('div#adsbox.ads.RMss1.ad.google-ads.download_btn a.down_btn.ads');
if (zipLinks[0]) zip1Links.push(zipLinks[0].href); // Add ZIP 1
if (zipLinks[1]) zip2Links.push(zipLinks[1].href); // Add ZIP 2
})
.catch(error => {
console.error('Error fetching ZIP links:', error);
});
}
});
alert('Added all ZIP links to the download list!');
} else {
alert('You have already copied links from this page.');
}
}
// Function to create text files from stored links
function createTextFiles() {
createFileFromLinks(zip1Links, 'zip1_download_list.txt');
createFileFromLinks(zip2Links, 'zip2_download_list.txt');
}
// Function to create a downloadable text file
function createFileFromLinks(links, filename) {
const blob = new Blob([links.join('\n')], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
// Function to show the list of copied links
function showList() {
const list = document.createElement('div');
list.innerHTML = `
<h3>Copied ZIP Links:</h3>
<ul>
<li>${zip1Links.join('</li><li>')}</li>
<li>${zip2Links.join('</li><li>')}</li>
</ul>
`;
document.body.appendChild(list);
}
// Function to clear the list of copied links
function clearList() {
zip1Links.splice(0, zip1Links.length);
zip2Links.splice(0, zip2Links.length);
document.querySelector('div.cc.filter').remove();
localStorage.removeItem('wnacg-zip-links');
}
// Run the script
extractLinks();
addDownloadListButtons(); // Add the new buttons
Removal of Alerts: Removed any alerts that might have been used earlier for debugging or user notifications regarding copied links.
Button Order: Ensured the button order places "Create Text Files" to the right of the "Clear List" button by modifying the order in which they are appended.
Show Unique Titles: Implemented a new function that opens a new tab displaying the unique titles found in the gallery items.
Persist Storage: Used localStorage to persist ZIP link data even when the page is refreshed, aiding in task continuation without starting from scratch.
This version of the script should fulfill your requests. Carefully calibrate and test it within your necessary environments to ensure compatibility and that all requirements are satisfactorily met.
Persistent Global Titles Storage: Implemented using localStorage to ensure titles across pages persist. The titles are stored in allTitles and updated with each page.
Button Feedback: Added a function greyOutButton that changes the button's color, creating a temporary visual effect when clicked.
This modified script should address your requirements, consolidating titles across pages and providing immediate user feedback with button state changes. You can test it in your environment to ensure it performs as expected.
Consistent Button Creation: Modified the extractLinks function to ensure buttons are added to each gallery item. Be sure the CSS selector for picBox and info correctly matches items on the page.
Improved Unique Title Handling: Titles are stored using Set but now properly converted to an array before being stored in localStorage.
Grey-Out Feedback: Implemented to provide user feedback on button interaction across all relevant button elements.
Please ensure that the selectors for your gallery items ('li.li.gallary_item', 'div.pic_box[class*="cate-"] a', etc.) properly represent the structure of the pages you're targeting to avoid missing elements.
// ==UserScript==
// @name Add ZIP Buttons
// @namespace http://tampermonkey.net/
// @version 1.4
// @description Add ZIP buttons to wnacg.com gallery items
// @author You
// @match https://www.wnacg.com/*
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
// Add custom button style
GM_addStyle(`
.custom-button {
padding: 1px 5px;
font-size: 12px;
color: #c11b68;
background-color: #d4d4d4;
border: 1px solid #c11b68;
border-radius: 4px;
cursor: pointer;
margin-left: 10px;
margin-top: 10px; /* Add top margin to lower the buttons */
transition: background-color 0.3s;
}
.custom-button:focus, .custom-button.greyed {
background-color: grey !important;
color: #d4d4d4 !important;
border: 1px solid #d4d4d4 !important;
}
`);
// Retrieve stored links or initialize them
const zip1Links = JSON.parse(localStorage.getItem('wnacg-zip1-links')) || [];
const zip2Links = JSON.parse(localStorage.getItem('wnacg-zip2-links')) || [];
const allTitles = new Set(JSON.parse(localStorage.getItem('wnacg-titles') || '[]'));
// Function to temporarily grey-out the button
function greyOutButton(button) {
button.classList.add('greyed');
setTimeout(() => {
button.classList.remove('greyed');
}, 3000);
}
function extractLinks() {
const galleryItems = document.querySelectorAll('li.li.gallary_item');
galleryItems.forEach(item => {
const picBox = item.querySelector('div.pic_box[class*="cate-"] a');
const info = item.querySelector('div.info');
if (picBox && info) {
const href = picBox.getAttribute('href');
const threadLink = `https://www.wnacg.com${href}`;
const downloadLink = threadLink.replace('/photos', '/download');
const title = picBox.getAttribute('title');
allTitles.add(title); // Add title to the global title set
addZIPButtons(info, downloadLink); // Correct the placement of buttons
}
});
localStorage.setItem('wnacg-titles', JSON.stringify(Array.from(allTitles)));
}
function addZIPButtons(titleElement, downloadLink) {
const zip1Button = document.createElement('span');
zip1Button.textContent = 'ZIP 1';
zip1Button.classList.add('custom-button');
zip1Button.addEventListener('click', (e) => {
e.preventDefault();
greyOutButton(zip1Button);
getZIPLinks(downloadLink, 0);
});
const zip2Button = document.createElement('span');
zip2Button.textContent = 'ZIP 2';
zip2Button.classList.add('custom-button');
zip2Button.addEventListener('click', (e) => {
e.preventDefault();
greyOutButton(zip2Button);
getZIPLinks(downloadLink, 1);
});
titleElement.appendChild(zip1Button);
titleElement.appendChild(zip2Button);
}
function getZIPLinks(downloadLink, index) {
fetch(downloadLink)
.then(response => response.text())
.then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const zipLinks = doc.querySelectorAll('div#adsbox.ads.RMss1.ad.google-ads.download_btn a.down_btn.ads');
if (zipLinks[index]) {
const zipLink = zipLinks[index].href;
if (index === 0) {
zip1Links.push(zipLink);
localStorage.setItem('wnacg-zip1-links', JSON.stringify(zip1Links));
} else {
zip2Links.push(zipLink);
localStorage.setItem('wnacg-zip2-links', JSON.stringify(zip2Links));
}
window.location.href = zipLink;
} else {
console.error('ZIP link not found.');
}
})
.catch(error => {
console.error('Error fetching ZIP links:', error);
});
}
// Function to create and append the necessary buttons
function addDownloadListButtons() {
const filterDiv = document.querySelector('div.cc.filter');
if (filterDiv) {
const addToDownloadListButton = document.createElement('span');
addToDownloadListButton.textContent = 'Add to Download List';
addToDownloadListButton.classList.add('custom-button');
addToDownloadListButton.addEventListener('click', (e) => {
e.preventDefault();
greyOutButton(addToDownloadListButton);
addAllZipLinks();
});
const clearListButton = document.createElement('span');
clearListButton.textContent = 'Clear List';
clearListButton.classList.add('custom-button');
clearListButton.addEventListener('click', (e) => {
e.preventDefault();
greyOutButton(clearListButton);
clearList();
});
const createTextFileButton = document.createElement('span');
createTextFileButton.textContent = 'Create Text Files';
createTextFileButton.classList.add('custom-button');
createTextFileButton.addEventListener('click', (e) => {
e.preventDefault();
greyOutButton(createTextFileButton);
createTextFiles();
});
const showListButton = document.createElement('span');
showListButton.textContent = 'Show List';
showListButton.classList.add('custom-button');
showListButton.addEventListener('click', (e) => {
e.preventDefault();
greyOutButton(showListButton);
showUniqueTitles();
});
filterDiv.appendChild(addToDownloadListButton);
filterDiv.appendChild(clearListButton);
filterDiv.appendChild(createTextFileButton);
filterDiv.appendChild(showListButton);
}
}
function addAllZipLinks() {
const galleryItems = document.querySelectorAll('li.li.gallary_item div.info');
galleryItems.forEach(item => {
const picBox = item.parentElement.querySelector('div.pic_box[class*="cate-"] a');
if (picBox) {
const href = picBox.getAttribute('href');
const threadLink = `https://www.wnacg.com${href}`;
const downloadLink = threadLink.replace('/photos', '/download');
fetch(downloadLink)
.then(response => response.text())
.then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const zipLinks = doc.querySelectorAll('div#adsbox.ads.RMss1.ad.google-ads.download_btn a.down_btn.ads');
if (zipLinks[0]) zip1Links.push(zipLinks[0].href);
if (zipLinks[1]) zip2Links.push(zipLinks[1].href);
localStorage.setItem('wnacg-zip1-links', JSON.stringify(zip1Links));
localStorage.setItem('wnacg-zip2-links', JSON.stringify(zip2Links));
})
.catch(error => {
console.error('Error fetching ZIP links:', error);
});
}
});
console.log('Added all ZIP links to the download list.');
}
function createTextFiles() {
createFileFromLinks(zip1Links, 'zip1_download_list.txt');
createFileFromLinks(zip2Links, 'zip2_download_list.txt');
}
function createFileFromLinks(links, filename) {
const blob = new Blob([links.join('\n')], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
function clearList() {
zip1Links.length = 0;
zip2Links.length = 0;
allTitles.clear();
localStorage.removeItem('wnacg-zip1-links');
localStorage.removeItem('wnacg-zip2-links');
localStorage.removeItem('wnacg-titles');
}
function showUniqueTitles() {
const titles = JSON.parse(localStorage.getItem('wnacg-titles')) || [];
const uniqueTitles = new Set(titles);
const newTab = window.open();
newTab.document.body.innerHTML = '<h1>Unique Titles:</h1><ul>' +
Array.from(uniqueTitles).map(title => `<li>${title}</li>`).join('') +
'</ul>';
}
extractLinks();
addDownloadListButtons();
})();
Key Adjustments:
CSS for Buttons: Added margin-top: 10px; to .custom-button in the CSS styles, which will add space above each button, effectively lowering it within its container in div.cc.filter.
Ensure Consistency: Make sure such styling fits within the existing style scheme of the page to maintain visual consistency.
Feel free to adjust the margin values according to your layout preferences. If the buttons still do not appear at the desired position, consider inspecting the parent container's styling or modify other relevant CSS properties.
// ==UserScript==
// @name Add ZIP Buttons
// @namespace http://tampermonkey.net/
// @version 1.4
// @description Add ZIP buttons to wnacg.com gallery items
// @author You
// @match https://www.wnacg.com/*
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
// Add custom style with a more specific selector and !important to ensure it takes effect
GM_addStyle(`
div.cc.filter .custom-button {
padding: 1px 5px;
font-size: 12px;
color: #c11b68;
background-color: #d4d4d4;
border: 1px solid #c11b68;
border-radius: 4px;
cursor: pointer;
margin-left: 10px;
margin-top: 20px !important; /* Adjust top margin with more specificity */
transition: background-color 0.3s;
}
`);
// The rest of your script...
// Function to create and append the necessary buttons
function addDownloadListButtons() {
const filterDiv = document.querySelector('div.cc.filter');
if (filterDiv) {
// You could also try setting padding-top or other styles here as needed
filterDiv.style.paddingTop = '20px'; // Adding padding can help separate content
const addToDownloadListButton = document.createElement('span');
addToDownloadListButton.textContent = 'Add to Download List';
addToDownloadListButton.classList.add('custom-button');
addToDownloadListButton.addEventListener('click', (e) => {
e.preventDefault();
greyOutButton(addToDownloadListButton);
addAllZipLinks();
});
const clearListButton = document.createElement('span');
clearListButton.textContent = 'Clear List';
clearListButton.classList.add('custom-button');
clearListButton.addEventListener('click', (e) => {
e.preventDefault();
greyOutButton(clearListButton);
clearList();
});
const createTextFileButton = document.createElement('span');
createTextFileButton.textContent = 'Create Text Files';
createTextFileButton.classList.add('custom-button');
createTextFileButton.addEventListener('click', (e) => {
e.preventDefault();
greyOutButton(createTextFileButton);
createTextFiles();
});
const showListButton = document.createElement('span');
showListButton.textContent = 'Show List';
showListButton.classList.add('custom-button');
showListButton.addEventListener('click', (e) => {
e.preventDefault();
greyOutButton(showListButton);
showUniqueTitles();
});
filterDiv.appendChild(addToDownloadListButton);
filterDiv.appendChild(clearListButton);
filterDiv.appendChild(createTextFileButton);
filterDiv.appendChild(showListButton);
}
}
// Other functions and initialization code...
extractLinks();
addDownloadListButtons();
})();
Additional Steps to Debug
Inspect the Elements: Use the browser's Developer Tools to inspect the buttons and their container (div.cc.filter) to see what styles are applied, where conflicts might arise, and how changes like padding-top affect the layout.
Check Display Style: If the container uses display: flex;, margins may behave differently. Consider adjusting the container with justify-content or using padding instead of margin.
Log and Adjust: Place console.log statements or directly manipulate the styles in the Developer Tools to understand what affects the layout.
This script snippet uses a more specific CSS selector and includes some padding directly to the filter div as well. These measures should help in adjusting the positioning of the buttons as desired.