平台红绿灯脚本

// ==UserScript==
// @name         平台红绿灯视频评估扩展
// @namespace    http://tampermonkey.net/
// @version      2025-09-15
// @description  try to take over the world!
// @author       You
// @match        https://pilothub.sankuai.com/evaluation-process-platform/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=sankuai.com
// @grant        none
// ==/UserScript==


(function() {
    'use strict';
    setTimeout(()=>{
        const observer = new MutationObserver((mutations) => {
            for (const mut of mutations) {
                mut.addedNodes.forEach(node => {
                    if (node.nodeType === Node.ELEMENT_NODE) {
                        if (node.matches?.('video')) {
                            processVideo(node);
                        }
                        node.querySelectorAll?.('video')?.forEach(processVideo);
                    }
                });
            }
        });
        //observer.observe(document.body, { childList: true, subtree: true });
        let newWindow;
        let task = document.querySelectorAll('.task-content-section')[0]
        //task.style.maxHeight="300px";
        let task_box = document.querySelectorAll('.fixed-section')[0]
        task_box.style.maxHeight="40vh";

        // 创建倒计时功能的函数(带重启功能)
        let createCountdown_timeLeft = 60;
        let createCountdown_timer= null;

        function copyText(str) {
            // 创建一个临时的 textarea 元素
            const tempTextArea = document.createElement("textarea");
            tempTextArea.value = str;

            // 将临时元素添加到文档中(不可见)
            document.body.appendChild(tempTextArea);

            // 选中临时元素中的文本
            tempTextArea.select();
            tempTextArea.setSelectionRange(0, 99999); // 对于移动设备的支持

            try {
                // 执行复制命令
                document.execCommand("copy");
                // 可选:给用户一个视觉反馈
                console.log("已复制到剪贴板:", str);
            } catch (err) {
                console.error("复制失败:", err);
            }

            // 移除临时元素
            document.body.removeChild(tempTextArea);
        }
        // 修改填充大小
        try{
            document.querySelectorAll('.content-header')[0].style.padding=0
            document.querySelectorAll('.section-header')[0].style.padding=0
            document.querySelectorAll('.standard-title')[0].style.margin=0
            document.querySelectorAll('.standard-title')[0].style.padding=0
            //fillQuillEditor("/")
            document.querySelectorAll('.evaluation-panel')[0].style.width='820px'
            document.querySelectorAll('.fixed-section')[0].style.maxHeight='42vh'
            document.querySelectorAll('.content-section')[0].style.marginTop='0'
            document.querySelectorAll('.task-selector')[0].style.marginBottom='0'
            document.querySelectorAll('.radio-options')[0].style.display='flex'
            document.querySelectorAll('.radio-options')[0].style.flexFlow='wrap'
            document.querySelectorAll('.radio-options')[1].style.display='flex'
            document.querySelectorAll('.radio-options')[1].style.flexFlow='wrap'
            document.querySelectorAll('.radio-options')[2].style.display='flex'
            document.querySelectorAll('.radio-options')[2].style.flexFlow='wrap'
            document.querySelectorAll('.radio-options')[3].style.display='flex'
            document.querySelectorAll('.radio-options')[3].style.flexFlow='wrap'
            document.querySelectorAll('.radio-item')[0].click()
            document.querySelectorAll('.radio-item')[4].click()
            document.querySelectorAll('.radio-item')[14].click()
            document.querySelectorAll('.radio-item')[16].click()
            document.querySelectorAll('.value-text')[2].click()
            let iframe = document.querySelector('.visualization-iframe')
            let iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
            let qmInput = iframeDoc.querySelector('.ivu-input-with-suffix')
            let nodeId = document.querySelectorAll('.value-text')[2].textContent
            iframeDoc.querySelector('.visualization-pane-trigger').click()
            iframeDoc.querySelectorAll('.map-btn')[2].click()
            if(nodeId!=null||nodeId){
                setNativeValue(qmInput,document.querySelectorAll('.value-text')[2].textContent)
                iframeDoc.querySelector('.ivu-input-search-icon').click()
                setTimeout(()=>{
                    iframeDoc.querySelectorAll('.map-btn')[16].click()
                },200)
                setTimeout(()=>{
                    iframeDoc.querySelectorAll('.map-btn')[16].click()
                },400)
            }
            document.querySelector('.sidebar-icon').click()
            //clickByClass('media-link',0)
        }catch(err){
            console.log(err)
        }
        createCountdown()
        setTimeout(()=>{
            document.querySelectorAll('video')[0].style.height='850px'
            document.querySelectorAll('video')[0].style.width='478.13px'
            document.querySelectorAll('video')[0].style.zIndex='10'
            document.querySelectorAll('video')[0].style.position='absolute'
            document.querySelectorAll('.media-preview-modal')[0].style.width="400px"
            document.querySelectorAll('.media-preview-modal')[0].style.height="20%"
            document.querySelectorAll('.media-preview-modal')[0].style.marginLeft="400px"
            document.addEventListener('keydown', function(event) {
                // 检查按下的键是否是 "Escape"
                if (event.key === 'Escape' || event.key === 'Esc') { // 兼容不同浏览器
                    // 获取目标按钮
                    const closeButton = document.querySelectorAll('.close-btn')[0];
                    if (closeButton) {
                        // 触发点击事件或其他关闭逻辑
                        closeButton.click(); // 或者执行其他操作,如 closeButton.dispatchEvent(...)
                    }
                }
            });
        },200)
        document.addEventListener('keydown', function(event) {
            // 检查是否按下 Alt + Q
            // 注意:event.key 是不区分大小写的字符,但建议用 toLowerCase() 确保匹配
            if (event.altKey && event.key.toLowerCase() ===  'q') {
                event.preventDefault();
                fillQuillEditor("抢黄灯")
            }
        });
        document.addEventListener('keydown', function(event) {
            // 检查是否按下 Alt + Q
            // 注意:event.key 是不区分大小写的字符,但建议用 toLowerCase() 确保匹配
            if (event.altKey && event.key.toLowerCase() ===  'y') {
                event.preventDefault();
                fillQuillEditor("疑似闯灯")
            }
        });
        document.addEventListener('keydown', function(event) {
            // 检查是否按下 Alt + Q
            // 注意:event.key 是不区分大小写的字符,但建议用 toLowerCase() 确保匹配
            if (event.altKey && event.key ===  '1') {
                event.preventDefault();

                const button = document.querySelectorAll('.radio-item')[1]
                if (button) {
                    button.click()
                    //document.querySelectorAll('.radio-item')[4].click()
                }
            }
        });
        document.addEventListener('keydown', function(event) {
            // 检查是否按下 Alt + Q
            // 注意:event.key 是不区分大小写的字符,但建议用 toLowerCase() 确保匹配
            if (event.altKey && event.key ===  '2') {
                event.preventDefault();

                const button = document.querySelectorAll('.radio-item')[2]
                if (button) {
                    button.click()
                    document.querySelectorAll('.radio-item')[7].click()
                }
            }
        });
        document.addEventListener('keydown', function(event) {
            // 检查是否按下 Alt + Q
            // 注意:event.key 是不区分大小写的字符,但建议用 toLowerCase() 确保匹配
            if (event.altKey && event.key ===  '3') {
                event.preventDefault();

                const button = document.querySelectorAll('.radio-item')[3]
                if (button) {
                    button.click()
                    document.querySelectorAll('.radio-item')[7].click()
                }
            }
        });
        document.addEventListener('keydown', function(event) {
            // 检查是否按下 Alt + Q
            // 注意:event.key 是不区分大小写的字符,但建议用 toLowerCase() 确保匹配
            if (event.altKey && event.key.toLowerCase() ===  '`') {
                // 阻止默认行为(可选,比如避免浏览器菜单被打开)
                event.preventDefault();

                // 获取第一个 .close-btn 元素
                const submitButton = document.querySelectorAll('.ivu-btn')[2]
                if (submitButton) {
                    // 触发点击事件(或你想要的操作)
                    // 创建一个 keydown 事件,模拟按下 Escape 键
                    const escEvent = new KeyboardEvent('keydown', {
                        key: 'Escape',
                        code: 'Escape',
                        keyCode: 27,        // 兼容旧代码(可选)
                        which: 27,          // 兼容旧代码(可选)
                        bubbles: true,      // 事件冒泡
                        cancelable: true    // 可取消
                    });

                    // 在 document 上派发该事件
                    document.dispatchEvent(escEvent);
                    submitButton.click();
                    document.querySelectorAll('video').forEach(processVideo);
                }
            }
        });
        document.querySelectorAll('h4')[0].innerText='剩余任务:'+String(Number(document.querySelectorAll('.ivu-select-dropdown-list')[0].childNodes.length)-1)
        copyText(document.querySelectorAll('.value-text')[0].textContent.trim())
        if(document.querySelectorAll('.value-text')[0].textContent.trim().split(':')[0]=='https'){
            openVideoInNewWindow(document.querySelectorAll('.value-text')[0].textContent.trim())
        }


        // 监听是否完成单次评测
        let end = document.querySelectorAll('.ivu-btn ,.ivu-btn-primary, .ivu-btn-large')[2]
        // 添加点击事件,点击跳转下一个
        end.addEventListener('click', function (event) {
            event.preventDefault(); // 阻止默认行为
            try{
                newWindow.close();
            }catch(e){

            }
            setTimeout(()=>{
                document.querySelectorAll('.radio-item')[0].click()
                document.querySelectorAll('.radio-item')[4].click()
                document.querySelectorAll('.radio-item')[14].click()
                document.querySelectorAll('.radio-item')[16].click()
                let iframe = document.querySelector('.visualization-iframe')
                let iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
                let qmInput = iframeDoc.querySelector('.ivu-input-with-suffix')
                let nodeId = document.querySelectorAll('.value-text')[2].textContent
                if(nodeId!=null||nodeId){
                    setNativeValue(qmInput,document.querySelectorAll('.value-text')[2].textContent)
                    iframeDoc.querySelector('.ivu-input-search-icon').click()
                }
                //clickByClass('media-link',0)
                setTimeout(()=>{
                    document.querySelectorAll('video')[0].style.height='850px'
                    document.querySelectorAll('video')[0].style.width='478.13px'
                    document.querySelectorAll('video')[0].style.zIndex='10'
                    document.querySelectorAll('video')[0].style.position='absolute'
                    document.querySelectorAll('.media-preview-modal')[0].style.width="400px"
                    document.querySelectorAll('.media-preview-modal')[0].style.height="20%"
                    document.querySelectorAll('.media-preview-modal')[0].style.marginLeft="400px"
                    document.addEventListener('keydown', function(event) {
                        // 检查按下的键是否是 "Escape"
                        if (event.key === 'Escape' || event.key === 'Esc') { // 兼容不同浏览器
                            // 获取目标按钮
                            const closeButton = document.querySelectorAll('.close-btn')[0];
                            if (closeButton) {
                                // 触发点击事件或其他关闭逻辑
                                closeButton.click(); // 或者执行其他操作,如 closeButton.dispatchEvent(...)
                            }
                        }
                    });
                },200)
                //fillQuillEditor("/")
                document.querySelectorAll('h4')[0].innerText='剩余任务:'+String(Number(document.querySelectorAll('.ivu-select-dropdown-list')[0].childNodes.length)-1)
                //document.querySelectorAll('.value-text')[2].click()
                document.querySelectorAll('.content-header')[0].style.padding=0
                document.querySelectorAll('.section-header')[0].style.padding=0
                document.querySelectorAll('.standard-title')[0].style.margin=0
                document.querySelectorAll('.standard-title')[0].style.padding=0
                document.querySelectorAll('.content-section')[0].style.marginTop='0'
                document.querySelectorAll('.task-selector')[0].style.marginBottom='0'
                document.querySelectorAll('.evaluation-panel')[0].style.width='820px'
                document.querySelectorAll('.fixed-section')[0].style.maxHeight='42vh'
                document.querySelectorAll('.radio-options')[0].style.display='flex'
                document.querySelectorAll('.radio-options')[0].style.flexFlow='wrap'
                document.querySelectorAll('.radio-options')[1].style.display='flex'
                document.querySelectorAll('.radio-options')[1].style.flexFlow='wrap'
                document.querySelectorAll('.radio-options')[2].style.display='flex'
                document.querySelectorAll('.radio-options')[2].style.flexFlow='wrap'
                document.querySelectorAll('.radio-options')[3].style.display='flex'
                document.querySelectorAll('.radio-options')[3].style.flexFlow='wrap'
                copyText(document.querySelectorAll('.value-text')[0].textContent.trim())
                if(document.querySelectorAll('.value-text')[0].textContent.trim().split(':')[0]=='https'){
                    openVideoInNewWindow(document.querySelectorAll('.value-text')[0].textContent.trim())
                }
            },1000)

        });
        setInterval(()=>{
            let task = document.querySelectorAll('.task-content-section')[0]
            let spans = task.querySelectorAll('.value-text');

            spans.forEach(span => {
                // 检查是否已经添加过处理(通过 class 判断)
                if (span.classList.contains('copy-ready')) {
                    return; // 已处理过,跳过
                }else{
                    // 添加“超出一行隐藏”样式
                    span.style.display = 'block';
                    span.style.overflow = 'hidden';
                    span.style.textOverflow = 'ellipsis';
                    span.style.whiteSpace = 'nowrap';
                    span.style.cursor = 'pointer';
                    document.querySelectorAll('.media-link')[0].addEventListener('click', function (event) {
                        event.preventDefault(); // 阻止默认行为
                    })


                    // 添加点击事件
                    span.addEventListener('click', function (event) {
                        event.preventDefault(); // 阻止默认行为
                        const text = this.innerText.trim();
                        copyText(text);
                        // 如果是以 https 开头,打开视频窗口
                        if (text.split(':')[0] === 'https') {
                            //video-preview
                            //const thumb =await getVideoThumbnail(text);
                            //document.querySelector('.video-preview').innerHTML += `<img src="${thumb}" />`;
                            document.addEventListener('keydown', function(event) {
                                // 检查按下的键是否是 "Escape"
                                if (event.key === 'Escape' || event.key === 'Esc') { // 兼容不同浏览器
                                    // 获取目标按钮
                                    const closeButton = document.querySelectorAll('.close-btn')[0];
                                    if (closeButton) {
                                        // 触发点击事件或其他关闭逻辑
                                        closeButton.click(); // 或者执行其他操作,如 closeButton.dispatchEvent(...)
                                    }
                                }
                            });
                            openVideoInNewWindow(text);
                        }
                        setTimeout(()=>{
                            document.querySelectorAll('video')[0].style.height='850px'
                            document.querySelectorAll('video')[0].style.zIndex='10'
                            document.querySelectorAll('video')[0].style.position='absolute'
                            document.querySelectorAll('.media-preview-modal')[0].style.width="400px"
                            document.querySelectorAll('.media-preview-modal')[0].style.height="20%"
                            document.querySelectorAll('.media-preview-modal')[0].style.marginLeft="400px"
                        },200)
                    });

                    // 添加标记 class,表示已处理
                    span.classList.add('copy-ready');
                }
            });
        },1500)

        // 处理单个 video 元素:提取首帧并插入 canvas 到 .video-preview
        async function processVideo(videoEl) {
            if (videoEl.dataset.processed) return; // 防重
            videoEl.dataset.processed = 'true';

            // 查找对应的 .video-preview 容器(根据你的 DOM 结构调整)
            const previewContainer = document.querySelector('.video-preview');
            let img1 = document.createElement('div');
            img1.id='img1';
            img1.style.position="absolute";
            img1.style.left="580px";
            img1.style.top="87px";
            //let img2 = document.createElement('div');
            //img2.id='img2';
            //img2.style.position="absolute";
            //img2.style.right="590px";
            //img2.style.top="87px";
            previewContainer.appendChild(img1)
            //previewContainer.appendChild(img2)
            if (!previewContainer) {
                console.warn('未找到 .video-preview 容器', videoEl);
                return;
            }

            try {
                // 等待视频元数据加载完成
                if (videoEl.readyState < videoEl.HAVE_METADATA) {
                    await new Promise((resolve, reject) => {
                        const onLoaded = () => resolve();
                        const onError = () => reject(new Error('视频加载失败'));
                        videoEl.addEventListener('loadeddata', onLoaded, { once: true });
                        videoEl.addEventListener('error', onError, { once: true });
                    });
                }

                // 跳转到第 0 秒(第一帧)
                videoEl.currentTime = 0.001;

                // 等待 seek 完成
                await new Promise(resolve => {
                    const onSeeked = () => {
                        videoEl.removeEventListener('seeked', onSeeked);
                        resolve();
                    };
                    videoEl.addEventListener('seeked', onSeeked, { once: true });
                });

                // 创建 canvas 并绘制当前帧
                const canvas = document.createElement('canvas');
                const ctx = canvas.getContext('2d');

                // 设置 canvas 尺寸(按视频原始比例,最大宽 640)
                const maxWidth = 640;
                const scale = Math.min(1, maxWidth / (videoEl.videoWidth || 1));
                const width = (videoEl.videoWidth || 320) * scale;
                const height = (videoEl.videoHeight || 180) * scale;

                canvas.width = 445;
                canvas.height = 791;
                canvas.style.maxWidth = '100%';
                canvas.style.height = 'auto';
                canvas.title = '视频首帧预览';

                ctx.drawImage(videoEl, 0, 0, width, height);

                // 清空容器并插入 canvas
                img1.innerHTML = '';
                img1.appendChild(canvas);
            } catch (err) {
                console.error('处理视频首帧失败:', err.message, videoEl);
                img1.textContent = '首帧加载失败';
            }
        }

        function clickByClass(classname,index){
            const button = document.getElementsByClassName(classname)[index];
            const event = new MouseEvent('click', {
                bubbles: true,
                cancelable: true,
                view: window
            });
            button.dispatchEvent(event);
        }
        //输入框选中
        function setNativeValue(element, value) {
            // 直接设置 textarea 的值
            element.value = value;

            // 创建并分派 input 事件
            const event = new Event('input', { bubbles: true });
            element.dispatchEvent(event);

            // 如果需要,也可以分派 change 事件
            const changeEvent = new Event('change', { bubbles: true });
            element.dispatchEvent(changeEvent);
        }
        function fillQuillEditor(content) {
            const qlEditor = document.querySelector('.ql-editor'); // 可替换为更精确的选择器

            if (!qlEditor) {
                console.error('未找到 Quill 编辑器');
                return false;
            }

            // 设置内容(纯文本)
            qlEditor.textContent = content;

            // 或者设置 HTML 内容
            // qlEditor.innerHTML = '<p>' + content.replace(/\n/g, '</p><p>') + '</p>';

            // 必须触发事件
            ['input', 'change', 'focus'].forEach(eventType => {
                const event = new Event(eventType, { bubbles: true, cancelable: true });
                qlEditor.dispatchEvent(event);
            });

            console.log('Quill 内容已填入:', content);
            return true;
        }

        function openVideoInNewWindow(videoUrl) {
            if (!videoUrl || videoUrl === '-') {
                return;
            }

            // 判断是否为 FLV(支持带参数的 URL,如 xxx.flv?token=...)
            const isFlv = /\.flv(\?|#|$)/i.test(videoUrl);

            const htmlContent = `
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Video Player</title>
    <!-- Plyr CSS -->
    <link rel="stylesheet" href="https://cdn.plyr.io/3.7.8/plyr.css" />
    <style>
        body, html {
            margin: 0;
            padding: 0;
            height: 100%;
            background: #000;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        #player {
            width: 100%;
            height: 100%;
            object-fit: contain;
        }
    </style>
</head>
<body>
    <!-- 注意:添加 preload="auto" 和 muted 是关键 -->
    <video
        id="player"
        playsinline
        controls
        preload="auto"
        muted
    ></video>

    <!-- Plyr JS -->
    <script src="https://cdn.plyr.io/3.7.8/plyr.polyfilled.js"></script>

    ${isFlv ? '<script src="https://cdn.jsdelivr.net/npm/flv.js@1.5.0/dist/flv.min.js"></script>' : ''}

    <script>
        (function() {
            const videoUrl = ${JSON.stringify(videoUrl)};
            const isFlv = ${isFlv};
            const video = document.getElementById('player');

            // === 处理 FLV ===
            if (isFlv) {
                if (typeof flvjs === 'undefined') {
                    alert('FLV.js failed to load.');
                    return;
                }
                if (!flvjs.isSupported()) {
                    alert('FLV playback is not supported in this browser.');
                    return;
                }

                const flvPlayer = flvjs.createPlayer({
                    type: 'flv',
                    url: videoUrl,
                    // 关键配置:禁用懒加载,确保尽快加载首帧
                    lazyLoad: false,
                    lazyLoadMaxDuration: 1,
                    deferLoadAfterSourceOpen: false,
                    autoCleanupSourceBuffer: true
                });

                flvPlayer.attachMediaElement(video);
                flvPlayer.load();

                // 可选:监听元数据到达后尝试 seek(0)
                flvPlayer.on(flvjs.Events.METADATA_ARRIVED, () => {
                    if (video.currentTime !== 0) {
                        video.currentTime = 0;
                    }
                });
            }
            // === 处理 MP4 / 其他原生格式 ===
            else {
                video.src = videoUrl;
                // 确保从 0 开始(应对 edit list)
                video.addEventListener('loadedmetadata', () => {
                    if (video.currentTime > 0) {
                        video.currentTime = 0;
                    }
                });
            }

            // === 自动播放(静音提高成功率)===
            //video.play().catch(e => {
            //    console.warn('Auto-play failed (user gesture may be required):', e);
                // 即使失败,Plyr 仍会显示播放按钮
            //});

            // === 初始化 Plyr ===
            const plyrInstance = new Plyr(video, {
                tooltips: { controls: true },
                fullscreen: { enabled: true, fallback: true, iosNative: true },
                autoplay: false, // 由上层 JS 控制 play()
                disableContextMenu: true
            });
                // 自动调整视频大小以适应窗口
                function resizeVideo() {
                    const player = document.getElementById('player');
                    const windowHeight = window.innerHeight;
                    player.style.height = (windowHeight * 1) + 'px'; // 设置视频高度为窗口高度的90%
                }

                // 初始调整视频大小
                resizeVideo();

                // 监听窗口大小变化事件
                window.onresize = resizeVideo;
        })();
    </script>
</body>
</html>
    `;

            // 打开新窗口
            const features = 'width=450,height=900,left=0,top=0,resizable=yes,scrollbars=yes';
            newWindow = window.open('', '_blank', features);
            if (newWindow) {
                newWindow.document.write(htmlContent);
                newWindow.document.close();
            } else {
                alert('请允许弹出窗口以播放视频。');
            }
        }

        function openVideoInNewWindow1(videoUrl) {
            if(!videoUrl||videoUrl=='-'){
                return;
            }
            //window.open(videoUrl, '_blank');
            //return;
            // 创建一个包含视频播放器的基本HTML字符串
            const videoHtml = `
        <!DOCTYPE html>
        <html>
        <head>
            <title>Video Player</title>
            <style>
                body, html {
                    margin: 0;
                    padding: 0;
                    height: 100%;
                    overflow: hidden;
                }
                .video-container {
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    background:black;
                    width: 100%;
                    height: 100%;
                }
                video,img {
                    width: 100%;
                    height: 100%; /* 设置视频高度为窗口高度的90% */
                }
            </style>
        </head>
        <body>
            <div class="video-container">
                <video id="videoPlayer" controls>
                    <source src="${videoUrl}" type="video/mp4"> <!-- 假设是MP4格式 -->
                    Your browser does not support the video tag.
                </video>
            </div>
            <script>
                // 自动调整视频大小以适应窗口
                function resizeVideo() {
                    const player = document.getElementById('videoPlayer');
                    const windowHeight = window.innerHeight;
                    player.style.height = (windowHeight * 1) + 'px'; // 设置视频高度为窗口高度的90%
                }

                // 初始调整视频大小
                resizeVideo();

                // 监听窗口大小变化事件
                window.onresize = resizeVideo;
            </script>
        </body>
        </html>
    `;

            // 打开新窗口并写入HTML内容
            newWindow = window.open('', '_blank', 'width=450,height=900,left=0,top=0,resizable=yes,scrollbars=yes');
            if (newWindow) {
                const match = videoUrl.match(/\/([^/?]+)\.mp4\?/);
                if (match && match[1]) {
                    console.log('视频名称:', match[1] + '.mp4');
                } else {
                    console.log('未能匹配到视频名称');
                }
                newWindow.document.write(videoHtml);
                newWindow.document.close(); // 必须调用以完成文档加载
            } else {
                alert('Please allow popups for this website.');
            }
        }



        // 保存原始的页面标题
        const originalTitle = document.title;

        // 定义计时器变量
        let timer = null;
        let seconds = 0;

        // 监听页面可见性变化
        document.addEventListener('visibilitychange', function() {
            if (document.visibilityState === 'hidden') {
                // 用户离开页面,开始计时
                seconds = 0;
                updateTitle();
                timer = setInterval(updateTitle, 1000);
            } else {
                // 用户返回页面,清除计时器并恢复原始标题
                if (timer) {
                    clearInterval(timer);
                    timer = null;
                }
                document.title = originalTitle;
            }
        });

        // 更新标题的函数
        function updateTitle() {
            seconds++;
            if(seconds%30==0){
                const formatDate = (date) => {
                    return new Intl.DateTimeFormat('zh-CN', {
                        year: 'numeric',
                        month: '2-digit',
                        day: '2-digit',
                        hour: '2-digit',
                        minute: '2-digit',
                        second: '2-digit',
                        hour12: false // 使用24小时制
                    }).format(date).replace(/\//g, '-'); // 将日期中的 / 替换为 -
                };
                let id=document.querySelector("#app > div > div > div.main > div.content.visualization-content > div > micro-app > micro-app-body > div > div > div.evaluation-panel > div.panel-content > div.fixed-section > div.task-selector > div > div > div:nth-child(1) > div > div.ivu-select-selection > div > span").textContent
                fetch("https://pilothub.sankuai.com/evaluation/api/v1/task/time/update", {
                    "headers": {
                        "accept": "application/json, text/plain, */*",
                        "accept-language": "zh-CN,zh;q=0.9",
                        "content-type": "application/json",
                        "priority": "u=1, i",
                        "sec-ch-ua": "\"Chromium\";v=\"140\", \"Not=A?Brand\";v=\"24\", \"Google Chrome\";v=\"140\"",
                        "sec-ch-ua-mobile": "?0",
                        "sec-ch-ua-platform": "\"Windows\"",
                        "sec-fetch-dest": "empty",
                        "sec-fetch-mode": "cors",
                        "sec-fetch-site": "same-origin"
                    },
                    "referrer": "https://pilothub.sankuai.com/evaluation-process-platform/tasks-evaluation?taskId=33031",
                    "body": "{\"taskIds\":\""+id+"\",\"misId\":\"wb_lantian03\",\"beginActualWork\":\""+formatDate(new Date())+"\"}",
                    "method": "POST",
                    mode: "cors",
                    credentials: "include"
                });
                console.log("执行了一次刷新时间:",formatDate(new Date()))
            }
            if (seconds >= 120) {
                // 达到2分钟(120秒),显示提示信息
                document.title = '赶快回来做case';
            } else {
                // 显示当前计时秒数
                document.title = `离开页面 ${seconds} 秒`;
            }
        }


        // 创建倒计时功能的函数(带重启功能)
        function createCountdown() {
            let timeLeft = createCountdown_timeLeft
            let timer = createCountdown_timer; // 用于存储定时器引用

            // 1. 创建倒计时容器 (div)
            const container = document.createElement('div');
            container.id = 'countdown-container';
            container.style.position = 'fixed';
            container.style.top = '0';
            container.style.left = '15vw';
            container.style.width = '24%';
            container.style.zIndex = '1000';
            container.style.textAlign = 'center';
            container.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
            container.style.padding = '2px 0';
            // 添加手型光标,提示可点击
            container.style.cursor = 'pointer';

            // 2. 创建倒计时显示元素 (span)
            const countdown = document.createElement('span');
            countdown.id = 'countdown';
            countdown.style.fontSize = '2rem';
            countdown.style.fontWeight = 'bold';
            countdown.style.transition = 'all 0.3s ease';
            countdown.style.display = 'inline-block';

            // 初始状态:显示开始按钮
            countdown.textContent = '开始倒计时';
            countdown.style.color = '#4CAF50'; // 绿色按钮

            // 3. 将 span 添加到 div 容器中
            container.appendChild(countdown);

            // 4. 将整个容器插入到页面的 body 最前面
            document.body.insertBefore(container, document.body.firstChild);

            // 5. 定义更新倒计时的函数
            function updateCountdown() {
                // 更新显示的数字
                countdown.textContent = timeLeft;

                // 根据剩余时间动态改变样式
                if (timeLeft > 30) {
                    countdown.style.color = '#4CAF50';
                    countdown.style.transform = 'scale(1)';
                    countdown.style.textShadow = 'none';
                } else if (timeLeft > 10) {
                    countdown.style.color = '#FF9800';
                    countdown.style.transform = 'scale(1.2)';
                    countdown.style.textShadow = '0 0 5px rgba(255, 152, 0, 0.5)';
                } else {
                    const opacity = (timeLeft % 2 === 0) ? '1' : '0.7';
                    const glowSize = (timeLeft % 2 === 0) ? '10px' : '16px';
                    countdown.style.color = '#F44336';
                    countdown.style.transform = 'scale(1.2)';
                    countdown.style.opacity = opacity;
                    countdown.style.textShadow = `0 0 ${glowSize} rgba(244, 67, 54, 0.8)`;
                }

                timeLeft--;

                if (timeLeft < 0) {
                    clearInterval(timer);
                    timer = null; // 清空定时器引用
                    countdown.textContent = '倒计时结束!点击重新开始';
                    countdown.style.color = '#ccc';
                    countdown.style.transform = 'scale(1)';
                    countdown.style.textShadow = 'none';
                    countdown.style.opacity = '1';
                }
            }

            // 6. 定义启动倒计时的函数
            function startCountdown() {
                // 如果已经有定时器在运行,则先清除(防止重复)
                if (timer) {
                    clearInterval(timer);
                }

                // 重置时间为60
                timeLeft = 60;

                // 立即更新一次显示(显示60)
                updateCountdown();

                // 启动新的定时器
                timer = setInterval(updateCountdown, 1000);
            }

            // 7. 为容器添加点击事件监听
            document.querySelectorAll('.ivu-btn ,.ivu-btn-primary, .ivu-btn-large')[2].addEventListener('click', function() {
                // 如果定时器不存在(即未运行或已结束),则启动倒计时
                if (!timer) {
                    startCountdown();
                }else{
                    createCountdown_timeLeft = -1;
                    clearInterval(timer);
                    startCountdown();
                }
                // 如果定时器存在(正在运行),点击可以停止(可选功能)
                // else {
                //     clearInterval(timer);
                //     timer = null;
                //     countdown.textContent = '已暂停,点击继续';
                //     countdown.style.color = '#FFEB3B';
                // }
                // 当前设计:只允许通过点击开始/重新开始
            });
        }

        console.log('修改end')
    },6000)

})();
// ==UserScript==
// @name         逆行视频评估脚本
// @namespace    http://tampermonkey.net/
// @version      2025-08-29
// @description  try to take over the world!
// @author       lambert
// @match        *://pilothub.map.st.sankuai.com/*

// @icon         https://www.google.com/s2/favicons?sz=64&domain=sankuai.com
// @grant        none
// ==/UserScript==


(function() {
    'use strict';
    setTimeout(()=>{
        let newWindow;
        let task = document.querySelectorAll('.task-content-section')[0]
        task.style.maxHeight="500px";
        let task_box = document.querySelectorAll('.fixed-section')[0]
        task_box.style.maxHeight="65vh";

        function copyText(str) {
            // 创建一个临时的 textarea 元素
            const tempTextArea = document.createElement("textarea");
            tempTextArea.value = str;

            // 将临时元素添加到文档中(不可见)
            document.body.appendChild(tempTextArea);

            // 选中临时元素中的文本
            tempTextArea.select();
            tempTextArea.setSelectionRange(0, 99999); // 对于移动设备的支持

            try {
                // 执行复制命令
                document.execCommand("copy");
                // 可选:给用户一个视觉反馈
                console.log("已复制到剪贴板:", str);
            } catch (err) {
                console.error("复制失败:", err);
            }

            // 移除临时元素
            document.body.removeChild(tempTextArea);
        }


        // 监听是否完成单次评测
        let end = document.querySelectorAll('.ivu-btn ,.ivu-btn-primary, .ivu-btn-large')[2].click()
        // 添加点击事件,点击跳转下一个
        end.addEventListener('click', function () {
            newWindow.close()
        });
        // 获取目标节点并处理其下的 span
        if (task) {
            let spans = task.querySelectorAll('span');

            spans.forEach(span => {
                // 添加“超出一行隐藏”样式
                span.style.display = 'block';
                span.style.overflow = 'hidden';
                span.style.textOverflow = 'ellipsis';
                span.style.whiteSpace = 'nowrap';

                // 添加点击事件,点击复制文本内容
                span.addEventListener('click', function () {
                    copyText(this.innerText.trim()); // 使用 trim() 去除首尾空白
                    if(this.innerText.trim().split(':')[0]=='https'){
                        //window.open(this.innerText.trim(), "_blank");
                        //window.open(this.innerText.trim(), '_blank', 'width=542,height=1000,left=50px,top=0,resizable=yes,scrollbars=yes');
                        openVideoInNewWindow(this.innerText.trim())
                    }
                });

                // 可选:添加手型光标,提示可点击
                span.style.cursor = 'pointer';
            });
        }

        function openVideoInNewWindow(videoUrl) {
            if(!videoUrl||videoUrl=='-'){
                copyVideoId()
                return;
            }
            // 创建一个包含视频播放器的基本HTML字符串
            const videoHtml = `
        <!DOCTYPE html>
        <html>
        <head>
            <title>Video Player</title>
            <style>
                body, html {
                    margin: 0;
                    padding: 0;
                    height: 100%;
                    overflow: hidden;
                }
                .video-container {
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    background:black;
                    width: 100%;
                    height: 100%;
                }
                video,img {
                    width: 100%;
                    height: 100%; /* 设置视频高度为窗口高度的90% */
                }
            </style>
        </head>
        <body>
            <div class="video-container">
                <!--
                <video id="videoPlayer" controls>
                    <source src="${videoUrl}" type="video/mp4">
                </video>
                -->
                <img src="${videoUrl}"></img>
            </div>
            <script>
                // 自动调整视频大小以适应窗口
                function resizeVideo() {
                    const player = document.getElementById('videoPlayer');
                    const windowHeight = window.innerHeight;
                    player.style.height = (windowHeight * 1) + 'px'; // 设置视频高度为窗口高度的90%
                }

                // 初始调整视频大小
                resizeVideo();

                // 监听窗口大小变化事件
                window.onresize = resizeVideo;
            </script>
        </body>
        </html>
    `;

            // 打开新窗口并写入HTML内容
            newWindow = window.open('', '_blank', 'width=542,height=1000,left=0,top=0,resizable=yes,scrollbars=yes');
            if (newWindow) {
                const match = videoUrl.match(/\/([^/?]+)\.mp4\?/);
                if (match && match[1]) {
                    console.log('视频名称:', match[1] + '.mp4');
                } else {
                    console.log('未能匹配到视频名称');
                }
                newWindow.document.write(videoHtml);
                newWindow.document.close(); // 必须调用以完成文档加载
            } else {
                alert('Please allow popups for this website.');
            }
        }

        console.log('修改end')
    },7000)

    // Your code here...
})();

posted @ 2025-11-07 16:00  lambertlt  阅读(0)  评论(0)    收藏  举报