Pixiv like/unlike manager

Manager like/unlike for artworks

目前為 2024-10-08 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Pixiv like/unlike manager
// @namespace    http://tampermonkey.net/
// @version      2.3
// @description  Manager like/unlike for artworks
// @icon         https://s.pximg.net/www/js/build/89b113d671067311.svg
// @match        https://www.pixiv.net/*
// @grant        none
// @license      CC BY-NC-ND 4.0
// ==/UserScript==


/*
Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License

Copyright (c) 2024 [Your Name]

You are free to:
- Adapt — remix, transform, and build upon the material

Under the following terms:
- Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- NonCommercial — You may not use the material for commercial purposes.
- NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material.

For more information, please visit:
https://creativecommons.org/licenses/by-nc-nd/4.0/
*/

(function() {
    'use strict';

    const popup = document.createElement('div');
    popup.style.position = 'fixed';
    popup.style.top = '800px';
    popup.style.left = '20px';
    popup.style.backgroundColor = 'rgb(51, 51, 51)';
    popup.style.border = '1px solid #ccc';
    popup.style.borderRadius = '5px';
    popup.style.padding = '15px';
    popup.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.2)';
    popup.style.zIndex = '1000';
    popup.style.opacity = '0.5';
    popup.style.pointerEvents = 'none';
    popup.style.width = '200px';
    popup.style.cursor = 'move';
    popup.style.pointerEvents = 'auto';


    popup.onmousedown = function(event) {
        let shiftX = event.clientX - popup.getBoundingClientRect().left;
        let shiftY = event.clientY - popup.getBoundingClientRect().top;

        function moveAt(pageX, pageY) {
            popup.style.left = pageX - shiftX + 'px';
            popup.style.top = pageY - shiftY + 'px';
        }

        function onMouseMove(event) {
            moveAt(event.pageX, event.pageY);
        }

        document.addEventListener('mousemove', onMouseMove);

        popup.onmouseup = function() {
            document.removeEventListener('mousemove', onMouseMove);
            popup.onmouseup = null;
        };
    };

    popup.ondragstart = function() {
        return false;
    };

    const likeButton = document.createElement('button');
    likeButton.innerText = 'Like';
    likeButton.style.cursor = 'pointer';
    likeButton.style.pointerEvents = 'auto';
    likeButton.style.backgroundColor = '#28a745';
    likeButton.style.color = 'white';
    likeButton.style.border = 'none';
    likeButton.style.borderRadius = '5px';
    likeButton.style.padding = '10px';
    likeButton.style.marginBottom = '10px';
    likeButton.style.width = '100%';

    const unlikedButton = document.createElement('button');
    unlikedButton.innerText = 'Unliked';
    unlikedButton.style.cursor = 'pointer';
    unlikedButton.style.pointerEvents = 'auto';
    unlikedButton.style.backgroundColor = '#dc3545';
    unlikedButton.style.color = 'white';
    unlikedButton.style.border = 'none';
    unlikedButton.style.borderRadius = '5px';
    unlikedButton.style.padding = '10px';
    unlikedButton.style.width = '100%';

    const message = document.createElement('div');
    message.style.marginTop = '10px';
    message.style.color = 'white';
    message.style.fontWeight = 'bold';
    message.style.textAlign = 'center';

    popup.appendChild(likeButton);
    popup.appendChild(unlikedButton);
    popup.appendChild(message);

    document.body.appendChild(popup);





    let lastUrl = window.location.href;

    function checkForNewArtwork() {
        if (window.location.href !== lastUrl) {
            lastUrl = window.location.href;
            message.innerText = 'New artwork loaded. Ready to like or unlike.';
        }
    }

    window.onpopstate = checkForNewArtwork;

    const observer = new MutationObserver(() => {
        checkForNewArtwork();
    });

    observer.observe(document.body, { childList: true, subtree: true });


    likeButton.onclick = function() {
        const buttons = document.querySelectorAll('button.sc-kgq5hw-0');
        let likedCount = 0;
        let totalButtons = 0;

        message.innerText = 'Scanning...';

        buttons.forEach(button => {
            const svg = button.querySelector('svg.sc-j89e3c-1');
            if (svg && svg.classList.contains('fYcrPo')) {
                totalButtons++;
                message.innerText = `Found ${totalButtons} artworks to like`;
            }
        });

        if (totalButtons === 0) {
            message.innerText = 'All artworks liked';
            return;
        } else {
            message.innerText = `Total ${totalButtons} artworks to like`
        }

        buttons.forEach((button, index) => {
            const svg = button.querySelector('svg.sc-j89e3c-1');
            if (svg && svg.classList.contains('fYcrPo')) {
                const randomDelay = Math.random() * 900 + 100;

                setTimeout(() => {
                    button.click();
                    likedCount++;
                    message.innerText = `Liked ${likedCount}/${totalButtons} artworks`;
                }, randomDelay);
            }
        });
    };

    unlikedButton.onclick = function() {
        const buttons = document.querySelectorAll('button.sc-kgq5hw-0');
        let unlikedCount = 0;
        let totalButtons = 0;

        message.innerText = 'Scanning...';

        buttons.forEach(button => {
            const svg = button.querySelector('svg.sc-j89e3c-1');
            if (svg && svg.classList.contains('bXjFLc')) {
                totalButtons++;
                message.innerText = `Found ${totalButtons} artworks to unlike`;
            }
        });

        if (totalButtons === 0) {
            message.innerText = 'All artworks unliked';
            return;
        } else {
            message.innerText = `Total ${totalButtons} artworks to unlike`
        }

        buttons.forEach((button, index) => {
            const svg = button.querySelector('svg.sc-j89e3c-1');
            if (svg && svg.classList.contains('bXjFLc')) {
                const randomDelay = Math.random() * 900 + 100;

                setTimeout(() => {
                    button.click();
                    unlikedCount++;
                    message.innerText = `Unliked ${unlikedCount}/${totalButtons} artworks`;
                }, randomDelay);
            }
        });
    };

    checkForNewArtwork();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址