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-17 提交的版本,查看 最新版本

  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
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function (){
  12. const SCRIPTNAME = 'YouTubeEmbededPopupper';
  13. const DEBUG = false;
  14. console.time(SCRIPTNAME);
  15. const POPUPSIZE = 2;/*Multiplies by embeded size*/
  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. 'popped=1',/*(original)prevent grandchild popup*/
  23. ];
  24. let core = {
  25. initialize: function(){
  26. /* Prevent grandchild popup and enables shortcut keys on popupped window */
  27. if(location.href.includes('popped=1')) return setTimeout(function(){document.querySelector('video').focus();}, 100);
  28. /* Right Click to Popup */
  29. document.body.title = POPUPTITLE;
  30. document.body.addEventListener('contextmenu', function(e){
  31. /* Define elements */
  32. let player = document.querySelector('.html5-video-player');
  33. let time = document.querySelector('span.ytp-time-current');
  34. /* Stop playing */
  35. if(player.classList.contains('playing-mode')) player.click();
  36. /* Get current time */
  37. let t = time.textContent.split(':').map(t => parseInt(t)).reverse();
  38. let start = 0;
  39. switch(t.length){
  40. case(3):
  41. start += t[2]*60*60;
  42. case(2):
  43. start += t[1]*60;
  44. case(1):
  45. start += t[0];
  46. }
  47. params.push('start=' + start);
  48. /* Build URL */
  49. /* (Duplicated params are overwritten by former) */
  50. let l = location.href.split('?');
  51. let url = l[0] + '?' + params.join('&');
  52. if(l.length === 2) url += ('&' + l[1]);
  53. /* Open popup window */
  54. /* (Use URL for window name to prevent popupping the same videos) */
  55. window.open(url, location.href, [
  56. 'width=' + document.body.offsetWidth * POPUPSIZE,
  57. 'height=' + document.body.offsetHeight * POPUPSIZE,
  58. ].join(','));
  59. e.preventDefault();
  60. e.stopPropagation();
  61. }, {capture: true});
  62. },
  63. };
  64. let log = (DEBUG) ? console.log.bind(null, SCRIPTNAME + ':') : function(){};
  65. core.initialize();
  66. console.timeEnd(SCRIPTNAME);
  67. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址