YouTube Embedded Popupper

You can pop up embedded videos by right click. (It may require permission for pop up blocker at the first pop)

Tính đến 19-07-2017. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        YouTube Embedded Popupper
// @namespace   knoa.jp
// @description You can pop up embedded videos by right click. (It may require permission for pop up blocker at the first pop)
// @description:ja YouTubeの埋め込み動画を、右クリックからポップアップで開けるようにします。(初回のみポップアップブロックの許可が必要かもしれません)
// @include     https://www.youtube.com/embed/*
// @version     1.2
// @grant       none
// ==/UserScript==

(function (){
  const SCRIPTNAME = 'YouTubeEmbeddedPopupper';
  const DEBUG = false;
  console.time(SCRIPTNAME);
  const POPUPWIDTH = 960;/*width of popup window*/
  const POPUPTITLE = 'Right Click to Popup';/*shown on mouse hover*/
  let params = [/* Overwrite parameters */
    'autoplay=1',/*autoplay*/
    'controls=2',/*show controls*/
    'disablekb=0',/*enable keyboard control*/
    'fs=1',/*enable fullscreen*/
    'rel=0',/*not to show relative videos*/
    'popped=1',/*(original)prevent grandchild popup*/
  ];
  let core = {
    initialize: function(){
      /* Prevent grandchild popup and enables shortcut keys on popupped window */
      if(location.href.includes('popped=1')) return setTimeout(function(){document.querySelector('video').focus();}, 100);
      /* Right Click to Popup */
      document.body.title = POPUPTITLE;
      document.body.addEventListener('contextmenu', function(e){
        /* Define elements */
        let player = document.querySelector('.html5-video-player');
        let time = document.querySelector('span.ytp-time-current');
        /* Stop playing */
        if(player.classList.contains('playing-mode')) player.click();
        /* Get current time */
        let t = time.textContent.split(':').map(t => parseInt(t)).reverse();
        let start = 0;
        switch(t.length){
          case(3):
            start += t[2]*60*60;
          case(2):
            start += t[1]*60;
          case(1):
            start += t[0];
        }
        params.push('start=' + start);
        /* Build URL */
        /* (Duplicated params are overwritten by former) */
        let l = location.href.split('?');
        let url = l[0] + '?' + params.join('&');
        if(l.length === 2) url += ('&' + l[1]);
        /* Open popup window */
        /* (Use URL for window name to prevent popupping the same videos) */
        window.open(url, location.href, [
          'width=' + POPUPWIDTH,
          'height=' + (POPUPWIDTH / document.body.offsetWidth) * document.body.offsetHeight,
        ].join(','));
        e.preventDefault();
        e.stopPropagation();
      }, {capture: true});
    },
  };
  let log = (DEBUG) ? console.log.bind(null, SCRIPTNAME + ':') : function(){};
  core.initialize();
  console.timeEnd(SCRIPTNAME);
})();