Greasy Fork

Greasy Fork is available in English.

跳过抖音广告

关闭抖音弹窗登录,跳过抖音广告和直播,观看直播默认原画

目前为 2023-03-07 提交的版本,查看 最新版本

// ==UserScript==
// @name         跳过抖音广告
// @namespace    http://greasyfork.icu/zh-CN/users/1034730-%E9%9A%8F%E7%BC%98%E7%8E%A9%E5%AE%B6?locale_override=1
// @version      0.12
// @description  关闭抖音弹窗登录,跳过抖音广告和直播,观看直播默认原画
// @author       随缘玩家
// @license      随缘玩家
// @match        https://www.douyin.com/*
// @match        https://live.douyin.com/*
// @grant        none
// ==/UserScript==

(function () {
  'use strict';
  let url = window.location.host;
  if (url == "www.douyin.com") {
    let next = document.querySelectorAll(".xgplayer-playswitch-next")[0]
    let configxgIcon = {
      tupian: true,
      qingping: true,
      comment: true
    }
    if (!localStorage.getItem("xg-icon")) {
      localStorage.setItem("xg-icon", JSON.stringify(configxgIcon))

    } else {
      configxgIcon = JSON.parse(localStorage.getItem("xg-icon"))

    }
    let observer = new MutationObserver((e) => {
      e.forEach((i) => {
        if (i.addedNodes.length > 0 && i.addedNodes[0].className) {
          let getClass = i.addedNodes[0].classList[0]
          if (getClass != undefined) {
            // console.log(i.addedNodes[0]);
            if (getClass == "OFZHdvpl" && document.querySelector('[data-e2e="feed-active-video"] .aDQw7OWI._628BWQES') != null && configxgIcon.comment) {
              if (document.querySelector('[data-e2e="feed-active-video"] .aDQw7OWI._628BWQES.JFWzESlW.LookModalFrameFast') != null) {
                setTimeout(() => {
                  i.addedNodes[0].querySelector(".pBxTZJeH.Qz1xVpFH.aLzJ7lUV").click()
                }, 180);
              }

            }
            if (getClass == "gear") {
              let clear = i.addedNodes[0].querySelectorAll(".virtual .item")
              if (clear[0] != null && clear[0].classList.length <= 1 && clear[0].querySelectorAll("span")[1] == undefined) {
                clear[0].click()
              }
              if (clear[0].querySelectorAll("span")[1] != undefined && clear[2].classList.length <= 1) {
                clear[2].click()
              }
              if (!document.querySelector("[data-e2e='feed-active-video'] [data-peizhi]")) {
                let config = document.querySelector("[data-e2e='feed-active-video'] .xg-right-grid")
                let xgIcon = document.createElement("xg-icon")
                xgIcon.className = "xgplayer-autoplay-setting automatic-continuous"
                xgIcon.innerHTML = `<div class="xgplayer-icon" data-e2e="video-player-auto-play" data-e2e-state="video-player-auto-playing"><div class="xgplayer-setting-label"><span class="xg-switch-inner"></span></button><span class="xgplayer-setting-title" data-peizhi>配置</span></div></div><div class="xgTips">
    <div class="xgplayer-icon" data-e2e="video-player-auto-play" data-e2e-state="video-player-auto-playing"><div class="xgplayer-setting-label"><button data-type="tupian" aria-checked="${configxgIcon.tupian}" class="${configxgIcon.tupian ? "xg-switch-checked" : ""} xg-switch " aria-labelledby="xg-switch-pip" type="button"><span class="xg-switch-inner"></span></button><span class="xgplayer-setting-title">图片</span></div></div>
    <div class="xgplayer-icon" data-e2e="video-player-auto-play" data-e2e-state="video-player-auto-playing"><div class="xgplayer-setting-label"><button data-type="qingping" aria-checked="${configxgIcon.qingping}" class="${configxgIcon.qingping ? "xg-switch-checked" : ""}  xg-switch" aria-labelledby="xg-switch-pip" type="button"><span class="xg-switch-inner"></span></button><span class="xgplayer-setting-title">清屏</span></div></div>
    <div class="xgplayer-icon" data-e2e="video-player-auto-play" data-e2e-state="video-player-auto-playing"><div class="xgplayer-setting-label"><button data-type="comment" aria-checked="${configxgIcon.comment}" class="${configxgIcon.comment ? "xg-switch-checked" : ""} xg-switch" aria-labelledby="xg-switch-pip" type="button"><span class="xg-switch-inner"></span></button><span class="xgplayer-setting-title">评论区</span></div></div>
   </div>`
                config.appendChild(xgIcon)
                let xgIconClick = xgIcon.querySelectorAll("button")
                xgIconClick.forEach((i, k) => {
                  i.onclick = () => {
                    let state = i.getAttribute("aria-checked")
                    if (state == "true") {
                      i.classList.remove("xg-switch-checked")
                      i.setAttribute("aria-checked", "false")
                      let type = i.getAttribute("data-type")
                      configxgIcon[type] = false
                      localStorage.setItem("xg-icon", JSON.stringify(configxgIcon))
                    } else {
                      i.classList.add("xg-switch-checked")
                      i.setAttribute("aria-checked", "true")
                      let type = i.getAttribute("data-type")
                      configxgIcon[type] = true
                      localStorage.setItem("xg-icon", JSON.stringify(configxgIcon))
                    }
                  }
                })
              }

            }
            if (getClass == "xgplayer-video-info-wrap") {
              let nowplay = i.addedNodes[0].parentNode.parentNode.parentNode.parentNode.parentNode
              if (nowplay.dataset.e2e == "feed-active-video") {
                if (i.addedNodes[0].querySelector(".video-info-detail .ysRqqDJY")) {
                  setTimeout(() => {
                    next.click()
                  }, 800);
                }

              }
            }
            if (getClass == "mPWahmAI") {
              let loginOff = i.addedNodes[0].querySelector(".box-align-center .dy-account-close")
              if (loginOff != null) {
                loginOff.click()
              }
            }

          }
        }
      })
    })
    observer.observe(document, { childList: true, subtree: true })
    //广告
    let body = document.querySelector(".u0N5WOYm.Srjrb_Q0") || document.querySelector(".swiper-wrapper")
    let time;
    function skip() {
      clearInterval(time)
      let videos = document.querySelector("[data-e2e='feed-active-video'] .slider-video")
      if (videos != null) {
        videos.style.display = "none"
        if (videos.querySelector("video") != null) videos.querySelector("video").pause()
      }
      let zhibonode = document.querySelector("[data-e2e='feed-live'] video")
      if (zhibonode != null && zhibonode.style.display == "") {

        zhibonode.style.display = "none"
        zhibonode.pause()
      }
      time = setInterval(() => {
        next.click()
      }, 2);
    }
    let observers = new MutationObserver((e) => {
      e.forEach((i) => {
        if (i.target.attributes[0].nodeValue == 'feed-active-video') {
          clearInterval(time)
          let guanggao = i.target.querySelector(".video-info-detail .SlSbcMqT.FxjGh3L8.alznRtIZ")
          let tupian = i.target.querySelector(".video-info-detail .ysRqqDJY")
          if (tupian != null && configxgIcon.tupian) {

            skip()
          }
          if (guanggao != null) {

            skip()
          }
          if (i.target.querySelector(".video-info-detail") != null && configxgIcon.qingping) {
            i.target.querySelector(".video-info-detail").style.display = "none"
          }
        }
        //直播
        if (document.querySelector("[data-e2e='feed-active-video']") == null) {
          skip()
        }
      })
    })
    observers.observe(body, { attributeOldValue: true, attributes: true, subtree: true, attributeFilter: ['data-e2e'] })
  }
  if (url == "live.douyin.com") {
    window.onload = function () {
      setTimeout(() => {
        let liwu = document.querySelector('.ruqvqPsH')
        if (liwu) {
          liwu.style.display = 'none'
        }
        let inall = document.querySelectorAll('.fHknbHHl').length ? document.querySelectorAll('.fHknbHHl') : document.querySelectorAll('.tY7dfAwO')
        let quanping = inall[1].querySelectorAll('div')[1]
        let pbliwu = inall[2].querySelectorAll('div')[1]
        quanping.click()
        pbliwu.click()
        let size = document.querySelector('.FKQqfehj')
        size.style.height = '100%'
        let danmus = document.querySelector('.basicPlayer.xgplayer .xgplayer-danmu')
        danmus.style.top = '0px'
        let mx = document.querySelectorAll('.tGBLU2eM')[2]
        let vid = document.querySelector('.O6bv6zn7')
        let time;
        vid.onmousemove = function () {
          clearInterval(time)
          vid.style.cursor = 'auto'
          time = setInterval(function () {
            vid.style.cursor = 'none'
          }, 2000)
        }
        let huazhi = document.querySelectorAll('.J1hZCcks .LH4RopWg')[0]
        huazhi.click()
      }, 3000);
    }
  }
})();