JavLibrary MissAV 早知道

针对javlibrary的AVID展示missav的链接,并判断是否已发布,已发布则展示视频预览,需要搭配jav老司机使用

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         JavLibrary MissAV 早知道
// @namespace    https://sleazyfork.org/zh-CN/scripts/507734-javlibrary-missav-%E6%97%A9%E7%9F%A5%E9%81%93
// @version      0.8
// @description  针对javlibrary的AVID展示missav的链接,并判断是否已发布,已发布则展示视频预览,需要搭配jav老司机使用
// @match        *://*.javlibrary.com/*
// @grant        GM_xmlhttpRequest
//0.6:增加了对无码的判断
//0.7:增加预览视频,默认无码视频;如果不存在则显示默认有码视频
//0.8:优化展示位置
// ==/UserScript==

(function() {
    'use strict';

    function createVideoPlayer(videoSrc) {
        const videoPlayer = document.createElement('video');
        videoPlayer.src = videoSrc;
        videoPlayer.autoplay = true;
        videoPlayer.loop = true;
        videoPlayer.muted = true;
        videoPlayer.style.width = '100%';
        videoPlayer.style.maxWidth = '320px';
        return videoPlayer;
    }

    function displayMissAVLink() {
        var videoWebplayer = document.querySelector('div#video_webplayer');
        
        if (videoWebplayer) {
            var avidElement = document.querySelector('td#avid');
            
            if (avidElement) {
                var avid = avidElement.getAttribute('avid');
                var missAVLink = document.querySelector('a[title="需解封印"]');
                
                if (missAVLink) {
                    var missAVUrl = 'https://missav.com/search/' + avid;
                    missAVLink.href = missAVUrl;
                    missAVLink.textContent = avid + ' 检查中...';
                    missAVLink.style.color = 'blue';
                    missAVLink.style.textDecoration = 'underline';
                    
                    GM_xmlhttpRequest({
                        method: "GET",
                        url: missAVUrl,
                        onload: function(response) {
                            if (response.status === 200) {
                                if (response.responseText.includes("event: 'videoSearch'")) {
                                    missAVLink.style.backgroundColor = 'blue';
                                    let linkText = 'missav: '+ avid + ' 已发布';
                                    
                                    const uncensoredLeakRegex = /<span[^>]*class="[^"]*(?:absolute|bottom-1|left-1|rounded-lg|px-2|py-1|text-xs|text-nord5|bg-blue-800|bg-opacity-75)[^"]*"[^>]*>\s*無碼流出\s*<\/span>/i;
                                    const isUncensoredLeak = uncensoredLeakRegex.test(response.responseText);
                                    
                                    if (isUncensoredLeak) {
                                        linkText += ' 无码已流出';
                                    }
                                    
                                    missAVLink.textContent = linkText;
                                    missAVLink.style.color = 'white';

                                    // 查找视频源并创建播放器
                                    let videoSrc = '';
                                    if (isUncensoredLeak) {
                                        const uncensoredLinkRegex = new RegExp(`<a[^>]*href="[^"]*${avid}-uncensored-leak"[^>]*>`, 'i');
                                        const uncensoredLinkMatch = response.responseText.match(uncensoredLinkRegex);
                                        if (uncensoredLinkMatch) {
                                            const uncensoredSection = response.responseText.slice(uncensoredLinkMatch.index);
                                            const videoMatch = uncensoredSection.match(/<video[^>]*data-src="([^"]*\.mp4)"[^>]*>/i);
                                            if (videoMatch) {
                                                videoSrc = videoMatch[1];
                                            }
                                        }
                                    } else {
                                        const videoMatch = response.responseText.match(/<video[^>]*data-src="([^"]*\.mp4)"[^>]*>/i);
                                        if (videoMatch) {
                                            videoSrc = videoMatch[1];
                                        }
                                    }

                                    if (videoSrc) {
                                        const videoPlayer = createVideoPlayer(videoSrc);
                                        missAVLink.parentNode.appendChild(videoPlayer);
                                    }
                                } else {
                                    missAVLink.style.backgroundColor = 'gray';
                                    missAVLink.textContent = 'missav: '+ avid + ' 未发布';
                                    missAVLink.style.color = 'white';
                                }
                            } else {
                                missAVLink.style.backgroundColor = 'red';
                                missAVLink.textContent = 'missav: '+ avid + ' 链接错误';
                                missAVLink.style.color = 'white';
                            }
                        }
                    });
                }
            }
        }
    }

    window.addEventListener('load', displayMissAVLink);
})();