YouTube Embeded Popupper

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

目前为 2017-07-18 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Embeded Popupper
  3. // @namespace knoa.jp
  4. // @description You can pop up embeded videos by right click. (It may require permission for pop up blocker at the first pop)
  5. // @description:ja YouTubeの埋め込み動画を、右クリックからポップアップで開けるようにします。(初回のみポップアップブロックの許可が必要かもしれません)
  6. // @include https://www.youtube.com/embed/*
  7. // @version 1.2
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function (){
  12. const SCRIPTNAME = 'YouTubeEmbededPopupper';
  13. const DEBUG = false;
  14. console.time(SCRIPTNAME);
  15. const POPUPWIDTH = 960;/*width of popup window*/
  16. const POPUPTITLE = 'Right Click to Popup';/*shown on mouse hover*/
  17. let params = [/* Overwrite parameters */
  18. 'autoplay=1',/*autoplay*/
  19. 'controls=2',/*show controls*/
  20. 'disablekb=0',/*enable keyboard control*/
  21. 'fs=1',/*enable fullscreen*/
  22. 'rel=0',/*not to show relative videos*/
  23. 'popped=1',/*(original)prevent grandchild popup*/
  24. ];
  25. let core = {
  26. initialize: function(){
  27. /* Prevent grandchild popup and enables shortcut keys on popupped window */
  28. if(location.href.includes('popped=1')) return setTimeout(function(){document.querySelector('video').focus();}, 100);
  29. /* Right Click to Popup */
  30. document.body.title = POPUPTITLE;
  31. document.body.addEventListener('contextmenu', function(e){
  32. /* Define elements */
  33. let player = document.querySelector('.html5-video-player');
  34. let time = document.querySelector('span.ytp-time-current');
  35. /* Stop playing */
  36. if(player.classList.contains('playing-mode')) player.click();
  37. /* Get current time */
  38. let t = time.textContent.split(':').map(t => parseInt(t)).reverse();
  39. let start = 0;
  40. switch(t.length){
  41. case(3):
  42. start += t[2]*60*60;
  43. case(2):
  44. start += t[1]*60;
  45. case(1):
  46. start += t[0];
  47. }
  48. params.push('start=' + start);
  49. /* Build URL */
  50. /* (Duplicated params are overwritten by former) */
  51. let l = location.href.split('?');
  52. let url = l[0] + '?' + params.join('&');
  53. if(l.length === 2) url += ('&' + l[1]);
  54. /* Open popup window */
  55. /* (Use URL for window name to prevent popupping the same videos) */
  56. window.open(url, location.href, [
  57. 'width=' + POPUPWIDTH,
  58. 'height=' + (POPUPWIDTH / document.body.offsetWidth) * document.body.offsetHeight,
  59. ].join(','));
  60. e.preventDefault();
  61. e.stopPropagation();
  62. }, {capture: true});
  63. },
  64. };
  65. let log = (DEBUG) ? console.log.bind(null, SCRIPTNAME + ':') : function(){};
  66. core.initialize();
  67. console.timeEnd(SCRIPTNAME);
  68. })();