Greasy Fork

Greasy Fork is available in English.

优学院直播/保利威直播自动签到

顾名思义,fuck ulearning

当前为 2022-09-05 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         优学院直播/保利威直播自动签到
// @namespace    https://github.com/ufec/yxy_live_auto_sign
// @version      0.1.0
// @description  顾名思义,fuck ulearning
// @author       ufec
// @license MIT
// @homepage     https://github.com/ufec/yxy_live_auto_sign
// @supportURL   https://github.com/ufec/yxy_live_auto_sign
// @match        https://live.polyv.cn/watch/*
// @match        https://www.ulearning.cn/ulearning/live.html?channelId=*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=polyv.cn
// @grant        none
// ==/UserScript==

(function() {
  'use strict';
  // 执行签到
  function execSign() {
    // 签到界面弹窗元素
    let signDialog = document.querySelector(
      '.plv-iar-btn-default.pws-btn-bg-color.pws-vclass-btn--primary',
    );
    if (signDialog == null) {
      setTimeout(execSign, 3000);
      return;
    }
    // 定位到具体签到Dialog
    signDialog = signDialog.parentElement.parentElement.parentElement.parentElement.parentElement;
    // 签到按钮
    let signButton = null;
    document
      .querySelectorAll(
        '.plv-iar-btn-default.pws-btn-bg-color.pws-vclass-btn--primary',
      )
      .forEach((btn) => {
        if (btn.innerText == '立即签到') {
          signButton = btn;
        }
      });
    if (signButton == null) {
      return;
    }
    if (!window.hasOwnProperty('polyvLiveAutoSignObserver')) {
      window.polyvLiveAutoSignObserver = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
          console.log('mutation: ', mutation);
          if (
            window.getComputedStyle(mutation.target).getPropertyValue('display') !=
            'none'
          ) {
            signButton.click(); // 点击签到按钮
            alert('签到成功');
          }
        });
      });
    }
    alert('开始监听签到弹窗');
    window.polyvLiveAutoSignObserver.observe(signDialog, {
      attributes: true,
      attributeFilter: ['style'],
    });
  }

  // 检查网页是否加载了签到弹窗
  function check() {
    const liveIframe = document.querySelector('#liveIframe');
    if (liveIframe == null) {
      setTimeout(check, 3000);
      return;
    }
    // 监听iframe加载完成
    liveIframe.onload = () => {
      // 跳转到iframe
      window.location.href = liveIframe.src;
    };
    execSign();
  }
  window.onload = function () {
    if (window.location.href.indexOf('live.polyv.cn') > -1) {
      // 保利威直播
      execSign();
    }else{
      // 优学院直播
      check();
    }
  };
})();