![]() ![]() |
I'm hoping something like this already exists, but I can't find anything. I have a userscript 'Disable Youtube Autoplay' (http://userscripts.org/scripts/show/100858) Unfortunately there is no way to get an indication of the length of the current video unless you press play. I'm hoping there is a userscript that can give an indication of the video length without clicking play. |
![]() ![]() |
I see the length beside the play and volume buttons. Installing that script doesn't stop it being shown in either the flash or HTML5 player (although it does fail to prevent HTML5 auto-play). Maybe another script/plugin is causing you problems? In any case, the page code contains references to |
![]() ![]() |
http://s11.postimage.org/z2r0uypjn/Youtube_No_A... I don't see the length anywhere, pic related. In order to see it I have to press play, which plays the video and defeats the whole purpose of having a script to disable autoplay. See, I don't want to load the video unless I know how long it is first. This in particular is very important. |
![]() ![]() |
What is the player you have in that image? I've never seen it before. |
![]() ![]() |
Yep that's no official youtube player, they'd never include a download link :-) |
![]() ![]() |
It's a different userscript that provides the download link. I don't actually use it, but it's there if I need it. The 'player'? That is Opera's standard flash blocking policy that very neatly integrates into youtube, meaning you have to press play to enable the video. I wish other browsers would have that feature implemented by default. |
![]() ![]() |
Are you being deliberately confusing? |
![]() ![]() |
Reread the thread title: I need a userscript that will "Show youtube video length" without clicking play on the video. I don't care where the length is shown, though I figured a good spot would be just below the video on the right. A simple 1:36 for a one minute thirty six second video. How is that confusing? |
![]() ![]() |
First of all you can go to Opera preferences -> Advanced -> Content and uncheck 'Enable plug-ins only on demand' if you don't like the idea of press to play. Second - you can get the length in seconds from:
|
![]() ![]() |
I know about that first point, and who in their right mind would uncheck that? It's one of the few things that Opera has built-in that makes youtube autoplay/autobuffer blocking scripts unnecessary, which is fantastic. How would I go about utilizing the 'window.yt.playerConfig.args.length_seconds' code? I'm not a script writer. |
![]() ![]() |
In Opera, can you still run JavaScript from the address bar? If so, try this on a sample page to see whether the variable is set:
Or perhaps there is a script console that you would use instead, omitting the protocol:
If the value is defined and non-zero, then you can access it in your script. |
![]() ![]() |
I just pasted the first script into the address bar on a youtube page and pressed enter. It correctly returned the video length in the alert. The second link returned an invalid URL, but maybe that's just because I tried running it directly from the address bar. |
![]() ![]() |
Cool, so now how you do want the information displayed in the page by your userscript? Perhaps: // ==UserScript==
// @name Video Length After Title
// @namespace YourNameHere
// @include http*://www.youtube.tld/watch*
// @version 1
// ==/UserScript==
function ShowRunningTime(e){
if (window.self != window.top) return;
var emb = document.querySelector('#movie_player');
if (!emb){
window.setTimeout(ShowRunningTime, 250); // doesn't work??
return;
}
var fvars = emb.getAttribute("flashvars");
fvars = fvars.substr(fvars.indexOf("length_seconds=") + "length_seconds=".length);
var trt = fvars.split("&")[0];
var vidtitle = document.getElementById("watch-headline-title");
if (trt > 0 && vidtitle){
var min = Math.floor(parseInt(trt)/60);
var sec = parseInt(trt) - (min * 60);
vidtitle.appendChild(document.createTextNode(" (trt: " + min + ":" + sec + ")"));
}
}
ShowRunningTime();
I only tested that on Firefox in Greasemonkey and I'm not blocking Flash. YMMV. |
![]() ![]() |
Had to change the include line to * (not all youtube links have .tld in them), but it works brilliantly in both Opera and Firefox, though for some odd reason not in Chrome (Tampermonkey extension). |
![]() ![]() |
.tld is a magic wildcard for known TLDs, but perhaps only Greasemonkey itself supports it. (I don't test in Opera or Chrome.) |
![]() ![]() |
I wonder what could be causing Chrome to fail. Oh well, it works in Opera and that was the main goal, as Opera has the best flash blocking abilities. Do you mind if I publish it as a userscript (with you in the credits of course) or would you prefer to publish it yourself? |
![]() ![]() |
Go for it. Then you get the pleasure of responding to requests for fixes and enhancements. ;-) |
![]() ![]() |
Fine, I'll forward the requests to you. Nahh. Though it probably won't need fixing. I don't really expect it to break. |



