可以在油猴内执行点击元素的代码

在视频播放过程中,中间会出现停止,每次都需要点击视频上的“跳过”按钮(见图片上红圈部分)才能继续播放,我用gpt生成的js代码放入油猴内,不能执行,在F12控制台可以查找到元素,直接用.clickf却可以执行,请设计一个在油猴内可以执行的对“跳过”按钮进行自动点击的代码,谢谢!

img


下面的代码是“跳过”按钮上下部分的在F12控制台中复制的代码:

<div id="app"><div class="capsule-play-fullscreen-container"><div class="capsule-player"><div id="capsule-container" class="capsule-container  hide-control"><div id="player-video" style="width: 100%; height: 100%;"><div class="react-player-video xgplayer xgplayer-pc xgplayer-skin-default xgplayer-is-autoplay xgplayer-playing xgplayer-pause" style="position: relative; width: 100%; height: 100%;"><video class="" autoplay="" playsinline="true" webkit-playsinline="true" x5-playsinline="true" tabindex="2" mediatype="video" src="blob:https://capsule.seewo.com/15b74961-3350-45ac-b2c6-2b25efe1a658" style="width: 100%; height: 100%;"></video><div class="react-player-hide-animation-pc react-player-hide-animation-hide-pc"><div class="react-player-hide-animation-touch-board"></div><div class="sc-gKPRtg cokkJQ react-player-controls-pc"><div class="sc-eDvSVe ilXlJq"><div class="sc-hLBbgP DofRY"><div class="react-player-pc-progress"><div class="react-player-pc-progress-slider-container"><div class="react-player-pc-progress-slider-outer"><div class="react-player-pc-progress-slider-cache" style="width: 97.5653%;"></div><div class="react-player-pc-progress-slider-played" style="width: 84.0078%;"><div class="react-player-pc-progress-slider-btn"></div></div></div><div class="react-player-pc-progress-dot" style="left: 84.0285%;"></div></div><div class="react-player-pc-progress-point" style="left: 712.281px; display: none;">05:03</div><div class="react-player-pc-progress-thumbnail" style="visibility: visible; width: 190px; height: 106px; background-size: 1900px 742px; background-image: url(&quot;https://cstore-public.seewo.com/knowledge-capsule-pub/7v8oda-3gXIDva_m4wANH&quot;); background-position: 0px -636px; left: 643px; top: -110px; display: none;"></div></div></div><div class="sc-hLBbgP fYFNNt"><div class="react-player-pc-play"><span role="img" class="svgicon icon"><svg width="1em" height="1em" viewBox="0 0 32 32" fill="currentColor" aria-hidden="true" focusable="false" class=""><path fill-rule="evenodd" clip-rule="evenodd" d="M10 10.532c0-1.554 1.696-2.514 3.029-1.715l9.113 5.468c1.294.777 1.294 2.653 0 3.43l-9.113 5.468c-1.333.8-3.029-.16-3.029-1.715V10.532Z"></path></svg></span></div></div><div class="sc-hLBbgP eljEhF"><div class="react-player-pc-progress-time">04:53 / 05:49</div></div><div class="sc-hLBbgP jiLCAg"><div class="react-player-pc-playback-rate"><div class="playback-rate-btn">倍速</div><div class="playback-pc-rate-list-wrap" style="display: none;"><div class="playback-pc-rate-list"><div class="playback-pc-rate-item">2.0x</div><div class="playback-pc-rate-item">1.5x</div><div class="playback-pc-rate-item">1.25x</div><div class="playback-pc-rate-item playback-pc-rate-current-item">1.0x</div><div class="playback-pc-rate-item">0.75x</div><div class="playback-pc-rate-item">0.5x</div></div></div></div></div><div class="sc-hLBbgP gCeklV"><div class="react-player-pc-volume"><div class="volume-icon"><span role="img" class="svgicon icon"><svg width="1em" height="1em" viewBox="0 0 32 32" fill="currentColor" aria-hidden="true" focusable="false" class=""><path d="M20.955 19.276c.665-.98 1.045-2.113 1.045-3.322a5.874 5.874 0 0 0-1.007-3.265M24.419 20.958C25.425 19.484 26 17.776 26 15.954c0-1.818-.573-3.523-1.576-4.996" stroke="#fff" stroke-width="2" stroke-linecap="round"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M17 9.232a2.41 2.41 0 0 0-.384-1.315c-.65-.996-1.902-1.215-2.794-.488l-3.679 2.992H8c-1.105 0-2 1-2 2.232v6.694c0 1.233.895 2.232 2 2.232l2.142-.001 3.68 2.994c.342.278.755.428 1.178.428 1.105 0 2-1 2-2.231V9.232ZM15 9v14l-4.207-3.54L8 19.463v-6.924h2.795L15 9Z"></path></svg></span></div><div class="volume-pc-slider-wrap" style="display: none;"><div class="volume-pc-slider"><div class="volume-pc-numb">80%</div><div class="rc-slider rc-slider-vertical"><div class="rc-slider-rail"></div><div class="rc-slider-track" style="bottom: 0%; height: 80%;"></div><div class="rc-slider-step"></div><div class="rc-slider-handle" tabindex="0" role="slider" aria-valuemin="0" aria-valuemax="100" aria-valuenow="80" aria-disabled="false" style="bottom: 80%; transform: translateY(50%);"></div></div></div></div></div></div><div class="sc-hLBbgP fCCdgh"><div class="react-player-pc-fullscreen"><span role="img" class="svgicon icon"><svg width="1em" height="1em" viewBox="0 0 32 32" fill="currentColor" aria-hidden="true" focusable="false" class=""><path fill-rule="evenodd" clip-rule="evenodd" d="M9 7a1 1 0 0 0-1 1v5a1 1 0 1 0 2 0v-2.586l3.414 3.414a1 1 0 1 0 1.414-1.414L11.414 9H14a1 1 0 1 0 0-2H9Zm14 16a1 1 0 0 0 1-1v-5a1 1 0 1 0-2 0v2.586l-3.465-3.465a1 1 0 0 0-1.414 1.415L20.586 21H18a1 1 0 1 0 0 2h5Z"></path></svg></span><div class="react-player-pc-tips"><span>进入全屏</span></div></div></div><div class="sc-hLBbgP jqIyio"></div></div></div><div class="sc-iBYQkv cJbZP"><div class="sc-eDvSVe ecSGIu"><div class="sc-hLBbgP byAHDX"></div></div></div><div class="react-player-pc-full-play"><span role="img" class="svgicon icon"><svg width="1em" height="1em" viewBox="0 0 70 70" fill="currentColor" aria-hidden="true" focusable="false" class=""><circle cx="35" cy="35" r="35" fill="#000" fill-opacity="0.6"></circle><path fill-rule="evenodd" clip-rule="evenodd" d="M25 26.158c0-3.129 3.431-5.046 6.096-3.406l14.368 8.841c2.538 1.562 2.538 5.252 0 6.814l-14.368 8.841C28.431 48.888 25 46.971 25 43.842V26.158Z" fill="#fff"></path></svg></span></div></div><div class="react-player-pc-loading" style="display: none;"><div class="dot-pulse-pc"></div></div><div class="react-player-poster" style="background-image: url(&quot;https://cstore-public.seewo.com/knowledge-capsule-pub/ojFIQTvV2A9lRV_egxENv.png&quot;);"></div><div class="react-player-pc-modal" style="display: none;"><div class="react-player-refresh-tip-pc"><span role="img" class="svgicon refresh-tip-img"><svg width="1em" height="1em" viewBox="0 0 180 140" fill="currentColor" aria-hidden="true" focusable="false" class=""><g clip-path="url(#refreshTipIconColor_svg__a)"><g opacity="0.6"><path d="m124.449 41.49-1.023-.524a1 1 0 0 0-1.346.435l-15.9 31.007a.999.999 0 0 0 .434 1.345l1.023.524a1 1 0 0 0 1.346-.435l15.9-31.007a.999.999 0 0 0-.434-1.346Z" fill="url(#refreshTipIconColor_svg__b)"></path><path fill-rule="evenodd" clip-rule="evenodd" d="m137.641 22.532 2.484 21.211a4.725 4.725 0 0 1-4.147 5.24 4.733 4.733 0 0 1-2.705-.486l-21.172-10.829a4.719 4.719 0 0 1-.141-8.33l18.688-10.382a4.73 4.73 0 0 1 6.993 3.576Z" fill="url(#refreshTipIconColor_svg__c)"></path><rect x="132.654" y="30.946" width="2" height="10" rx="1" transform="rotate(72.798 132.654 30.946)" fill="#FF7D7D"></rect><rect x="125.803" y="28.933" width="2" height="10" rx="1" transform="rotate(-17.202 125.803 28.933)" fill="#FF7D7D"></rect></g><path fill-rule="evenodd" clip-rule="evenodd" d="M156.635 149.564a22.926 22.926 0 0 1-10.33 2.619C146.207 168.667 132.813 182 116.306 182c-2.691 0-5.299-.354-7.781-1.019a45.785 45.785 0 0 1-6.879 13.966c25.306-4.371 46.088-21.951 54.989-45.383Zm3.519-38.462a22.942 22.942 0 0 0-14.205-4.897c-10.543 0-19.431 7.078-22.159 16.736a30.068 30.068 0 0 0-7.484-.941c-9.095 0-17.244 4.047-22.745 10.438A45.887 45.887 0 0 0 64.347 122a46.02 46.02 0 0 0-15.491 2.668C45.177 113.812 34.904 106 22.806 106c-1.11 0-2.206.066-3.282.194C27.45 75.041 55.687 52 89.306 52c35.361 0 64.769 25.492 70.848 59.102Z" fill="#fff" fill-opacity="0.05"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M155.154 147.809a22.942 22.942 0 0 1-10.849 2.368C144.21 166.664 130.815 180 114.306 180c-1.691 0-3.35-.14-4.965-.409a45.775 45.775 0 0 1-6.127 12.556c24.108-4.808 43.73-21.871 51.94-44.338Zm2.164-40.007a22.935 22.935 0 0 0-12.369-3.597c-10.636 0-19.587 7.203-22.229 16.991a29.996 29.996 0 0 0-8.414-1.196c-8.428 0-16.044 3.475-21.494 9.071A45.884 45.884 0 0 0 65.349 120a46.06 46.06 0 0 0-14.599 2.359C46.983 111.665 36.79 104 24.806 104c-.84 0-1.672.038-2.492.111C31.034 75.687 57.728 55 89.306 55c32.929 0 60.548 22.496 68.012 52.802Z" fill="url(#refreshTipIconColor_svg__d)"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M88.843 116.015c5.507-3.053 8.062-8.972 5.706-13.222-2.355-4.25-8.73-5.22-14.236-2.168-5.507 3.053-8.062 8.973-5.706 13.223 2.355 4.25 8.729 5.22 14.236 2.167Z" fill="url(#refreshTipIconColor_svg__e)" fill-opacity="0.2"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M65.069 86.305c2.583-1.327 3.888-4.105 2.914-6.207-.974-2.101-3.857-2.73-6.44-1.403-2.584 1.327-3.888 4.105-2.915 6.207.974 2.101 3.857 2.73 6.44 1.403Z" fill="url(#refreshTipIconColor_svg__f)" fill-opacity="0.6"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M122.029 102.667c2.186-1.065 3.29-3.295 2.466-4.982-.824-1.687-3.264-2.192-5.45-1.127-2.186 1.065-3.29 3.296-2.466 4.983.824 1.687 3.264 2.191 5.45 1.126Z" fill="url(#refreshTipIconColor_svg__g)" fill-opacity="0.3"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M76.787 79.14c1.15-.485 1.582-1.762.965-2.854-.617-1.091-2.05-1.584-3.2-1.1-1.15.484-1.582 1.761-.965 2.853.617 1.092 2.05 1.584 3.2 1.1Z" fill="url(#refreshTipIconColor_svg__h)" fill-opacity="0.6"></path></g><defs><linearGradient id="refreshTipIconColor_svg__b" x1="114.9" y1="55.403" x2="117.702" y2="56.84" gradientUnits="userSpaceOnUse"><stop stop-color="#EEE"></stop><stop offset="0.693" stop-color="#B5B3B3"></stop><stop offset="1" stop-color="#D8D8D8"></stop></linearGradient><linearGradient id="refreshTipIconColor_svg__c" x1="135.102" y1="18.879" x2="122.715" y2="43.097" gradientUnits="userSpaceOnUse"><stop stop-color="#FCDDD8"></stop><stop offset="1" stop-color="#F29D90"></stop></linearGradient><linearGradient id="refreshTipIconColor_svg__d" x1="73.817" y1="43.999" x2="132.783" y2="130.88" gradientUnits="userSpaceOnUse"><stop stop-color="#282828"></stop><stop offset="1" stop-color="#404040"></stop></linearGradient><linearGradient id="refreshTipIconColor_svg__e" x1="81.475" y1="102.247" x2="92.444" y2="110.574" gradientUnits="userSpaceOnUse"><stop stop-color="#474545"></stop><stop offset="1" stop-color="#222"></stop></linearGradient><linearGradient id="refreshTipIconColor_svg__f" x1="63.306" y1="79.5" x2="66.681" y2="87.335" gradientUnits="userSpaceOnUse"><stop stop-color="#323232"></stop><stop offset="1" stop-color="#242424"></stop></linearGradient><linearGradient id="refreshTipIconColor_svg__g" x1="120.667" y1="96.816" x2="123.011" y2="101.859" gradientUnits="userSpaceOnUse"><stop stop-color="#585656"></stop><stop offset="1" stop-color="#222"></stop></linearGradient><linearGradient id="refreshTipIconColor_svg__h" x1="75.306" y1="74.5" x2="76.486" y2="78.105" gradientUnits="userSpaceOnUse"><stop stop-color="#474545"></stop><stop offset="1" stop-color="#222"></stop></linearGradient><clipPath id="refreshTipIconColor_svg__a"><path fill="#fff" d="M0 0h180v140H0z"></path></clipPath></defs></svg></span><div class="refresh-tip-note">视频加载异常,请刷新重试(0)</div><div class="refresh-button">刷新</div></div></div><div><div class="rc-notification react-player-pc-message"><div></div></div></div></div></div><div></div><div class="container___2HQug" style="width: 100%; height: 100%; position: absolute; top: 0px; z-index: 21; pointer-events: none;"><div class="transition___2k-D0"><div class="left___3astV" style="transition: transform 0.75s ease 0s; transform: translateX(-100%);"></div><div class="right___2vZSo" style="transition: transform 0.75s ease 0s; transform: translateX(100%);"></div></div></div><div id="16823191398450.230-1-startTime-293.455" style="top: 0px; position: absolute; width: 100%; height: 100%; z-index: 20;"><div class="previewer-select-container"><div class="previewer-select-content-scroll"><div class="previewer-select-skip">跳过</div><div class="previewer-select-content"><div class="previewer-select-background-image" style="background-image: url(&quot;https://cstore-public.seewo.com/knowledge-capsule-pub/h0l2_v_agtf166tdDMxhm.png&quot;); background-color: rgb(0, 0, 0);"></div><div class="previewer-question-select-answer-container" style="justify-content: center;"><div class="previewer-select-answer-area"><div class="previewer-select-title"><span class="previewer-select-type">多选题</span></div><div class="previewer-question-select-answer-options"><div class="answer-item is-active" data-value="A">A</div><div class="answer-item " data-value="B">B</div><div class="answer-item " data-value="C">C</div><div class="answer-item " data-value="D">D</div></div></div></div></div></div><div class="previewer-select-footer"><div class="previewer-select-submit-btn">提交</div></div></div></div></div></div></div></div>

你用setTimeout或setInterval执行得不到结果吗?

【以下回答由 GPT 生成】

这里是一个可以在油猴脚本中自动点击“跳过”按钮的示例代码:

// ==UserScript==
// @name         自动点击“跳过”按钮
// @namespace    your-namespace
// @version      1.0
// @description  在油猴脚本中自动点击“跳过”按钮的代码
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function() {
        // 获取“跳过”按钮元素
        var skipButton = document.querySelector('.react-player-controls-pc .sc-eDvSVe.ilXlJq');

        if (skipButton) {
            // 在元素上触发鼠标点击事件
            skipButton.dispatchEvent(new MouseEvent('click'));
        }
    });
})();

这段代码使用了 querySelector 方法来获取“跳过”按钮元素,然后使用 dispatchEvent 方法触发了一个鼠标点击事件。这样,当页面加载完毕时,会自动点击该按钮。你可以将这段代码复制并粘贴到油猴脚本编辑器中,然后保存并安装脚本。

请注意,由于我无法直接测试该网站的情况,所以无法确保代码能够完全适用,可能需要根据实际情况进行适当修改。


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^