librelist archives

« back to archive

[PATCH 1/2] youtube-player.js: update play/pause and fullscreen

[PATCH 1/2] youtube-player.js: update play/pause and fullscreen

From:
Joren Van Onder
Date:
2013-12-18 @ 20:36
The HTML5 play/pause and fullscreen buttons are no longer button
elements, but div elements with a .ytp-button-* class.
---
 modules/page-modes/youtube-player.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/modules/page-modes/youtube-player.js 
b/modules/page-modes/youtube-player.js
index 5ec130d..10ac68e 100644
--- a/modules/page-modes/youtube-player.js
+++ b/modules/page-modes/youtube-player.js
@@ -22,7 +22,7 @@ function youtube_player_click_command (selector, 
error_message) {
 
 interactive("youtube-player-play-or-pause",
     "Click the Youtube html5 player play/pause button.",
-    youtube_player_click_command("button.html5-pause-button, 
button.html5-play-button",
+    youtube_player_click_command(".ytp-button-pause, .ytp-button-play",
                                  "No play or pause button found"));
 
 interactive("youtube-player-mute",
@@ -32,7 +32,7 @@ interactive("youtube-player-mute",
 
 interactive("youtube-player-fullscreen",
     "Click the Youtube html5 player fullscreen button.",
-    youtube_player_click_command("button.html5-fullscreen-button",
+    youtube_player_click_command(".ytp-button-fullscreen-enter, 
.ytp-button-fullscreen-exit",
                                  "No fullscreen button found"));
 
 define_key(youtube_player_keymap, "C-c return", "youtube-player-play-or-pause");
-- 
1.8.5.2

[PATCH 2/2] youtube-player.js: add support for changing playback speed

From:
Joren Van Onder
Date:
2013-12-18 @ 20:36
Allows users to change playback speed with 'C-c C-[' and 'C-c C-]'.
---
 modules/page-modes/youtube-player.js | 39 ++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/modules/page-modes/youtube-player.js 
b/modules/page-modes/youtube-player.js
index 10ac68e..30308d8 100644
--- a/modules/page-modes/youtube-player.js
+++ b/modules/page-modes/youtube-player.js
@@ -1,5 +1,6 @@
 /**
  * (C) Copyright 2012 Scott Jaderholm
+ * (C) Copyright 2013 Joren Van Onder
  *
  * Use, modification, and distribution are subject to the terms specified in the
  * COPYING file.
@@ -9,6 +10,34 @@ require("content-buffer.js");
 
 define_keymap("youtube_player_keymap", $display_name = "youtube-player");
 
+function youtube_player_change_speed (slower) {
+    return function (I) {
+        var buf = I.buffer;
+
+        // get settings control rows
+        // [0]: annotations, [1]: speed, [2]: quality, [3]: captions
+        var settings_control_rows = 
buf.document.querySelectorAll(".ytp-menu-row");
+
+        // get speed dropdown menu content
+        var speed_buttons = settings_control_rows[1].querySelectorAll(
+	    ".ytp-drop-down-menu-content .ytp-drop-down-menu-button");
+
+        for (var i = 0; i < speed_buttons.length; ++i) {
+            if 
(speed_buttons[i].className.indexOf("ytp-drop-down-menu-button-checked") 
!= -1) {
+                // current speed
+
+                if (slower && i != 0) {
+                    dom_node_click(speed_buttons[i - 1], 1, 1);
+                } else if (! slower && i != speed_buttons.length - 1) {
+                    dom_node_click(speed_buttons[i + 1], 1, 1);
+                }
+
+                break;
+            }
+        }
+    }
+}
+
 function youtube_player_click_command (selector, error_message) {
     return function (I) {
         var buf = I.buffer;
@@ -35,9 +64,19 @@ interactive("youtube-player-fullscreen",
     youtube_player_click_command(".ytp-button-fullscreen-enter, 
.ytp-button-fullscreen-exit",
                                  "No fullscreen button found"));
 
+interactive("youtube-player-speed-down",
+    "Slow down the Youtube html5 player.",
+    youtube_player_change_speed(true));
+
+interactive("youtube-player-speed-up",
+    "Speed up the Youtube html5 player.",
+    youtube_player_change_speed(false));
+
 define_key(youtube_player_keymap, "C-c return", "youtube-player-play-or-pause");
 define_key(youtube_player_keymap, "C-c C-m", "youtube-player-mute");
 define_key(youtube_player_keymap, "C-c C-f", "youtube-player-fullscreen");
+define_key(youtube_player_keymap, "C-c C-[", "youtube-player-speed-down");
+define_key(youtube_player_keymap, "C-c C-]", "youtube-player-speed-up");
 
 define_keymaps_page_mode("youtube-player-mode",
     build_url_regexp($domain = "youtube", $allow_www = true),
-- 
1.8.5.2

Re: [PATCH 2/2] youtube-player.js: add support for changing playback speed

From:
Joren Van Onder
Date:
2013-12-19 @ 17:09
So it turns out there are some differences between the DOM trees of
various YouTube pages embedding HTML5 video. This causes this second
patch to not work on certain videos (the first one should be fine). So I
think the best thing to do is to just ignore this patch for now. I'll
look more into it during the weekend.


       Joren

Re: [conkeror] [PATCH 1/2] youtube-player.js: update play/pause and fullscreen

From:
John J. Foerch
Date:
2013-12-19 @ 17:34
On Wed, Dec 18, 2013 at 09:36:09PM +0100, Joren Van Onder wrote:
> The HTML5 play/pause and fullscreen buttons are no longer button
> elements, but div elements with a .ytp-button-* class.

Thanks, pushed.

-- 
John Foerch