Created
August 11, 2024 14:08
-
-
Save book000/f300385613d2d78125fa86fa78432828 to your computer and use it in GitHub Desktop.
toggling all bookmarks to public or private
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This script is for toggling all bookmarks on pixiv to public or private. | |
Open your own pixiv user page, switch to the bookmarks tab, and then run this script in the browser console. | |
(e.g., https://www.pixiv.net/users/{userId}/bookmarks/artworks) | |
*/ | |
/** | |
* Wait for an element to appear in the DOM and resolve with it. | |
* | |
* @param {string} selector - The CSS selector to wait for. | |
* @param {number} timeout - The maximum time to wait in milliseconds. Default is 180000 (3 minutes). | |
* @returns {Promise<Element>} - The element that was found | |
* @throws {Error} - If the element is not found within the timeout. | |
*/ | |
async function waitElement(selector, timeout = 180000) { | |
return new Promise((resolve, reject) => { | |
const timer = setTimeout(() => { | |
reject(new Error("timeout")); | |
}, timeout); | |
const interval = setInterval(() => { | |
const element = document.querySelector(selector); | |
if (element) { | |
clearInterval(interval); | |
clearTimeout(timer); | |
resolve(element); | |
} | |
}, 100); | |
}); | |
} | |
/** | |
* Toggle all bookmarks to public or private. | |
*/ | |
async function toggleAllRestrict() { | |
console.log("toggleAllRestrict()"); | |
// Edit bookmarks | |
console.log('Wait "Edit bookmarks" button'); | |
const editBookmarkElement = await waitElement(".sc-1dg0za1-7"); | |
console.log('Click "Edit bookmarks" button'); | |
editBookmarkElement.click(); | |
// Select all | |
console.log('Wait "Select all" button'); | |
const selectAllElement = await waitElement(".sc-13ywrd6-6"); | |
console.log('Click "Select all" button'); | |
selectAllElement.click(); | |
// Set as public or Set as private | |
console.log('Wait "Set as public" or "Set as private" button'); | |
const setPublicOrPrivateElement = await waitElement( | |
"div.sc-1ij5ui8-0:nth-child(4) > div:nth-child(1) > div:nth-child(1)" | |
); | |
console.log('Click "Set as public" or "Set as private" button'); | |
setPublicOrPrivateElement.click(); | |
} | |
/** | |
* Entry point | |
*/ | |
async function main() { | |
while (true) { | |
await toggleAllRestrict(); | |
await new Promise((resolve) => setTimeout(resolve, 1000)); | |
} | |
} | |
// Run the main function | |
(async () => { | |
await main(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment