User:機智的小魚君/moeskin.js

萌娘百科,萬物皆可萌的百科全書!轉載請標註來源頁面的網頁連結,並聲明引自萌娘百科。內容不可商用。
貢獻者:

注意:在您儲存之後您必須清除瀏覽器快取才可看到最新的變動。

  • Firefox / Safari:按住「Shift」時點選「重新整理」,或按「Ctrl-F5」或「Ctrl-R」 (Mac則為「⌘-R」)
  • Google Chrome:按「Ctrl-Shift-R」 (Mac 則為「⌘-Shift-R」)
  • Internet Explorer:按住「Ctrl」時點選「重新整理」,或按「Ctrl-F5」
  • Opera:進入「工具→偏好設定」中清除快取。
  • 如果您已登入但該頁面出現未登入狀態,請嘗試在網址列的URL最後新增代碼?_=1來訪問最新頁面。
/**
 * 添加背景視頻
 * just for fun
 */
;(function () {
  const windowWidth = document.documentElement.clientWidth
  if (windowWidth < 768) {
    return // EARLY RETURNING
  }

  var VIDEO_LIST = [
    'https://r2.epb.wiki/videos/steam_ad5fa9597db193112408fe0e058c3ce8b07bd7e2.mp4',
    'https://r2.epb.wiki/videos/steam_b3d43fe9bba52b7fb930dd8c306230e35870602e.mp4',
    'https://r2.epb.wiki/videos/steam_1e12a183139d56d904ec334bd8e8c07b386d6a48.mp4',
    'https://r2.epb.wiki/videos/wallpaper_2265394105.mp4',
    'https://r2.epb.wiki/videos/wallpaper_2653049950.mp4',
  ]

  // 創建畫布
  var bg = document.createElement('div')
  bg.id = 'custom-video-background'
  bg.style.position = 'fixed'
  bg.style.top = '0'
  bg.style.left = '0'
  bg.style.width = '100%'
  bg.style.height = '100%'
  bg.style.zIndex = '0'
  bg.style.userSelect = 'none'
  bg.style.display = 'none'

  // 讀取視頻
  var video = document.createElement('video')
  video.src = randomPick(VIDEO_LIST)
  video.autoplay = true
  video.loop = true
  video.muted = true
  video.style.width = '100%'
  video.style.height = '100%'
  video.style.objectFit = 'cover'
  video.disablePictureInPicture = true
  video.disableRemotePlayback = true
  bg.appendChild(video)

  bg.addEventListener('click', function () {
    video.src = randomPick(VIDEO_LIST, video.src)
    video.play()
  })

  /**
   * @param {Event} ev
   */
  function firstInit(ev) {
    var oldBackground = document.querySelector('#moe-global-background')
    if (oldBackground) {
      oldBackground.after(bg)
      $(oldBackground).fadeOut(450)
    } else {
      document.body.appendChild(bg)
    }
    $(bg).fadeIn(250)
    ev.target.removeEventListener('canplay', firstInit)
  }
  video.play()
  video.addEventListener('canplay', firstInit)
})()

/**
 * @template T
 * @param {T[]} arr
 * @param {T|undefined} current
 * @returns {T}
 */
function randomPick(arr, current) {
  if (!Array.isArray(arr)) {
    throw new TypeError('arr must be an array, but got ' + typeof arr)
  }
  var list = arr.filter(function (v) {
    return v !== current
  })
  return list[Math.floor(Math.random() * list.length)]
}
此頁面最後編輯於 2024年12月5日 (週四) 18:06。
搜尋萌娘百科 (按"/"快速搜尋)
有新的未讀公告