Sleazy Fork is available in English.

Jable一键下载收藏

Jable一键下载视频,并自动点击收藏

От 16.10.2023. Виж последната версия.

// ==UserScript==
// @name         Jable一键下载收藏
// @namespace    https://greasyfork.org/zh-CN/scripts/474848-jable%E4%B8%80%E9%94%AE%E4%B8%8B%E8%BD%BD%E6%94%B6%E8%97%8F
// @version      1.2.2
// @description  Jable一键下载视频,并自动点击收藏
// @author       Pandex
// @match        https://jable.tv/*
// @match        https://fs1.app/*
// @icon         https://assets-cdn.jable.tv/assets/icon/favicon-32x32.png
// @grant        none
// @license      MPL
// ==/UserScript==

(function() {
    'use strict';

    var isVideoPage = false;
    if (!!location.href.match(/https:\/\/(jable\.tv|fs1\.app)\/videos\/*\/*/)) {
        isVideoPage = true;
    }

    function detectDownload() {
        var saveFileDirectory = "D:\\videos\\jav";
        var downloadParams = ' --maxThreads "48" --minThreads "16" --retryCount "100" --timeOut "100" --enableDelAfterDone';

        let Base64 = {
            encode(str) {
                return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
                    function toSolidBytes(match, p1) {
                        return String.fromCharCode('0x' + p1);
                    }));
            },
            decode(str) {
                // Going backwards: from bytestream, to percent-encoding, to original string.
                return decodeURIComponent(atob(str).split('').map(function (c) {
                    return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
                }).join(''));
            }
        };


        var logined = false;
        var userNameEl = document.querySelector('.d-lg-block');
        if (userNameEl && userNameEl.innerText != '登入') {
            logined = true;
        }

        var title_path = '#site-content > div > div > div:nth-child(1) > section.video-info.pb-3 > div.info-header > div.header-left > h4';
        var title_el = document.querySelector(title_path);
        var title = title_el.innerText;
        var url = hlsUrl;

        var download_btn = document.createElement("a");
        download_btn.className="addtion";
        download_btn.id="download_m3u8";
        var params = '"' + url + '"' + '  --saveName "' + title + '" --workDir "' + saveFileDirectory + '"' + downloadParams;
        console.log('params:', params);
        params = Base64.encode(params);
        var downloadLink =  'm3u8dl://' + params;
        download_btn.href = 'javascript:void(0);';
        if (logined) {
            download_btn.innerText = '下载并收藏';
        } else {
            download_btn.innerText = '下载(无法收藏,未登录)';
        }
        download_btn.style.display = 'inline-block';
        download_btn.style.padding = '10px 20px';
        download_btn.style.background = 'cornflowerblue';
        download_btn.style.color = 'white';
        download_btn.style.fontSize = '18px';
        download_btn.style.margin = '0 10px';
        download_btn.style.borderRadius = '5px';
        title_el.appendChild(download_btn);

        function checkClickLike() {
            const download = () => {
                console.log('开始下载', downloadLink);
                window.open(downloadLink, '_blank');
            };
            const likeBtn = document.querySelector("#site-content > div > div > div:nth-child(1) > section.video-info.pb-3 > div.text-center > div > button.btn.btn-action.fav.mr-2");
            if (likeBtn) {
                if (likeBtn.classList.contains('active')) {
                    var r = confirm("你已收藏此影片,可能下载过,是否继续下载?");
                    if (r == true) {
                        download();
                    } else {
                        console.log('取消下载');
                    }
                } else {
                    likeBtn.click();
                    download();
                }
            } else {
                download();
            }
        }
        document.getElementById("download_m3u8").addEventListener("click", function(){
            checkClickLike();
        });
    }
    if (isVideoPage) {
        detectDownload();
    }
    // update website CSS
    function updateJableCSS(){
        const container = document.querySelector("#site-content > div.container");
        if (container) {
            container.style.setProperty('max-width', '2000px', 'important');
        }
        const likeHeart = document.querySelector("#site-content > div > div > div:nth-child(1) > section.video-info.pb-3 > div.text-center > div > button.btn.btn-action.fav.mr-2 > svg");
        if (likeHeart) {
            likeHeart.color = 'gray';
        }

        function removeTitleWhiteSpace() {
            var titleElements = document.querySelectorAll('.video-img-box .title');
            // Remove the white-space property from each title element
            titleElements.forEach(function(titleElement) {
                titleElement.style.whiteSpace = 'normal';
            });
            var subTitleElements = document.querySelectorAll('.video-img-box .sub-title');
            subTitleElements.forEach(function(subTitleElement) {
                let innerText = subTitleElement.innerText;
                if (!innerText) {
                    return;
                }
                let innerTexts = innerText.split('\n');
                if (!innerTexts || innerTexts.length < 2) {
                    return;
                }
                let playText = innerTexts[0];
                let likeText = innerTexts[1];
                if (!playText || !likeText) {
                    return;
                }
                let playCount = parseInt(playText.replaceAll(' ', ''));
                let likeCount = parseInt(likeText)
                if (playCount > 1000000 || likeCount > 10000) {
                    subTitleElement.style.background = 'hotpink';
                    subTitleElement.style.color = 'aliceblue';
                }
            });
        }

        function observeMutations() {
            var targetNode = document.body;
            var observerOptions = {
                childList: true, // Observe direct children being added or removed
                subtree: true // Observe all descendants of the target node
            };
            var observer = new MutationObserver(function(mutationsList, observer) {
                removeTitleWhiteSpace();
            });
            observer.observe(targetNode, observerOptions);
        }
        window.addEventListener('load', function() {
            removeTitleWhiteSpace();
            observeMutations();
        });
    }
    updateJableCSS();
})();