Youtube shuffle bitbucket.io helper

Adds a few features from youtube playlists to youtube-playlist-randomizer

目前為 2022-02-05 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Youtube shuffle bitbucket.io helper
// @namespace    https://youtube-playlist-randomizer.bitbucket.io/
// @version      1.1
// @description  Adds a few features from youtube playlists to youtube-playlist-randomizer
// @author       lopt24d
// @match        https://youtube-playlist-randomizer.bitbucket.io/*
// @grant        none
// ==/UserScript==


(function() {
      
  // Autostart bookmarked playlist
  var pid = new URL(window.location).searchParams.get("pid");
  if (pid != null) {
    document.getElementById("pid").value = pid;
    getVids();
  }
  
  var playerFound = false;
  
  var seekPlayer = setInterval(function () {
    if (player) {
      playerFound = true;
      clearInterval(seekPlayer);
    }
  }, 1000);
  
  var focus;
    
  window.addEventListener('keydown', function(event) {
    focus = document.activeElement.tagName;
    if (!(focus == "INPUT" || focus == "TEXTAREA") && playerFound) {
      switch (event.keyCode) {
        case ('n'.charCodeAt() - 32):   // Next video
          playNext();
          break;
        case ('p'.charCodeAt() - 32):   // Previous video
          playPrev();
          break;
        case ('r'.charCodeAt() - 32):    // Reshuffle
          getVids();
          break;
        case ('l'.charCodeAt() - 32):    // seek forward 10 seconds
          player.seekTo(player.getCurrentTime() + 10);
          break;
        case ('j'.charCodeAt() - 32):    // seek backwards 10 seconds
          player.seekTo(player.getCurrentTime() - 10);
          break;
        case ('k'.charCodeAt() - 32):    // pause/unpause video
          if (player.getPlayerState() == 1)
            player.pauseVideo();
          else
            player.playVideo();
          break;
        case ('m'.charCodeAt() - 32):    // mute/unmute video
          if (player.isMuted())
            player.unMute();
          else
            player.mute();
          break;
      }
    }
  });
  
})();