script to full screen YouTube videos

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kmcintyre
Posts: 20
Joined: 29 Mar 2014, 18:35

script to full screen YouTube videos

22 Jul 2017, 16:04

Hello,

I'm visually impaired and use a lot of AHK scripts to aid in my use of my computer. But I have a problem and can use some help...

One thing I would love to automate is finding and clicking the button at the far right of the YouTube video player's control bar. I'm pretty sure there is no Windows handle or id for this control. And I'm pretty sure that I'd need to do an http Send with some command string to ask YouTube to go full screen. But those are just educated guesses,..

If any of you young, super studs can help an old blind guy out with a script to automate taking YouTube videos full screen, I'd be greatly appreciative...

(I have the same issue with Vimeo. I'm guessing if I can see how to do it with YouTube I'll be able to figure out Vimeo...)

Thanks in advance!

Keith
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: script to full screen YouTube videos

22 Jul 2017, 17:28

This is the most annoying problem ever. Pressing f works to get fullscreen in Mozilla Firefox and Google Chrome, but not in Internet Explorer.

This works for YouTube in Internet Explorer, but if anyone has any other ideas or knowledge on the subject, I would like to know anything I can about this problem, thanks.

Code: Select all

#IfWinActive, ahk_class IEFrame
;[WBGet function]
;Basic Webpage Controls with JavaScript / COM - Tutorial - Tutorials - AutoHotkey Community
;https://autohotkey.com/board/topic/47052-basic-webpage-controls-with-javascript-com-tutorial/

~f::
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
if InStr(oWB.document.url, "youtube.com/")
|| InStr(oWB.document.url, "youtu.be/")
{
	oWB.document.getElementsByClassName("ytp-fullscreen-button ytp-button").item[0].focus()
	;oWB.document.getElementsByClassName("ytp-fullscreen-button ytp-button").item[0].click() ;didn't work
	ControlSend, Internet Explorer_Server1, {Enter}, % "ahk_id " hWnd
}
oWB := ""
return
#IfWinActive
Re. annoying, in the UK at least, when watching playlists, YouTube kept playing the same 3 mini-Tyler Oakley adverts and 1 Lilly Singh advert constantly. This was really awful and so I set up a script to mute YouTube the second I heard one of those ads come on.

==================================================

I couldn't get Vimeo to work, I tried things like:

Code: Select all

	oWB.document.getElementsByClassName("fullscreen").item[0].focus()
	oWB.document.getElementsByClassName("fullscreen").item[0].click()
	oWB.document.getElementsByClassName("fullscreen-icon").item[0].focus()
	oWB.document.getElementsByClassName("fullscreen-icon").item[0].click()
Like YouTube, f works to set fullscreen on, on Mozilla Firefox and Google Chrome, but doesn't work on Internet Explorer 11.
Last edited by jeeswg on 22 Jul 2017, 18:42, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
kmcintyre
Posts: 20
Joined: 29 Mar 2014, 18:35

Re: script to full screen YouTube videos

22 Jul 2017, 18:20

Well that's totally awesome! I have been using Edge just because I like it and it's the default. But I have chrome and Firefox too.

Hopefully someone will add to the discussion with a workaround for IE 11 and/or Edge...

I used to be a programmer. I could follow your code quite easily. Thanks!

Keith
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: script to full screen YouTube videos

11 Aug 2017, 08:31

It turns out that with YouTube you can double-click on the video to view it in fullscreen, but I am having trouble trying to invoke double-click on a web element, if anyone has any ideas.

E.g. *not* working, it reacts (toggles play/pause) but doesn't invoke fullscreen:

Code: Select all

	oWB.document.getElementById("movie_player").click()
	Sleep 100
	oWB.document.getElementById("movie_player").click()
(dblclick and doubleclick didn't work.)

==================================================

This is a version of the script above for YouTube, but which closes the notification bar via Acc.

Code: Select all

#IfWinActive, ahk_class IEFrame
;[WBGet function]
;Basic Webpage Controls with JavaScript / COM - Tutorial - Tutorials - AutoHotkey Community
;https://autohotkey.com/board/topic/47052-basic-webpage-controls-with-javascript-com-tutorial/
;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

~f::
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
if InStr(oWB.document.url, "youtube.com/")
|| InStr(oWB.document.url, "youtu.be/")
{
	oWB.document.getElementsByClassName("ytp-fullscreen-button ytp-button").item[0].focus()
	;oWB.document.getElementsByClassName("ytp-fullscreen-button ytp-button").item[0].click() ;didn't work
	ControlSend, Internet Explorer_Server1, {Enter}, % "ahk_id " hWnd
}
oWB := ""

;close notification bar
ControlGet, hCtl, Hwnd,, DirectUIHWND1, % "ahk_id " hWnd
oAcc := Acc_Get("Object", "4.4", 0, "ahk_id " hCtl)
if (oAcc.accName(0) = "Close")
	oAcc.accDoDefaultAction(0)
oAcc := ""
return
#IfWinActive
Last edited by jeeswg on 11 Aug 2017, 14:44, edited 2 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: script to full screen YouTube videos

11 Aug 2017, 11:58

Nice jeeswg!

Just 2 tips:
  • You can use oWB.hwnd instead of WinGet, hWnd, ID, ahk_class IEFrame
  • You can use oAcc := oAcc.accChild(4) instead of oAcc := Acc_Get("Object", "4.4", 0, "ahk_id " hCtl)
BTW, the F key works for me in Edge browser.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: script to full screen YouTube videos

11 Aug 2017, 13:32

Wasn't it F11 for all other IEs ??
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: script to full screen YouTube videos

11 Aug 2017, 14:47

@tmplinshi: Thanks. It seems I left some extra lines in, from debugging, it's fixed now.

@BoBo: F11 sets fullscreen for Internet Explorer, f or double-click sets fullscreen for the YouTube video.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: script to full screen YouTube videos

12 Aug 2017, 00:35

This may or may not work..

Code: Select all

oWB.document.dblclk.createEventObject()
oWB.document.dblclk.eventType:="dblclick"
oWB.document.eventName="dblclick"

; call it

; oWB.document.getElementsByClassName("ytp-fullscreen-button ytp-button").item[0].fireEvent("on" . oWB.document.dblclk.eventType, oWB.document.dblclk)
oWB.document.getElementById("movie_player").fireEvent("on" . oWB.document.dblclk.eventType, oWB.document.dblclk)
More likely to work.

Code: Select all

; oWB.navigate("javascript:var dblclk=document.createEventObject();dblclk.eventType='dblclick';document.getElementsByClassName('ytp-fullscreen-button ytp-button').item[0].fireEvent('on'+dblclk.eventType,dblclk);")
oWB.navigate("javascript:var dblclk=document.createEventObject();dblclk.eventType='dblclick';document.getElementById('movie_player').fireEvent('on'+dblclk.eventType,dblclk);")
Anyone know a way to directly execute JS via COM?
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RandomBoy, scriptor2016 and 356 guests