Javascript bookmarks

From Hackerspace ACKspace
Jump to: navigation, search

Some Javascript bookmark oneliners that do stuff with video of all kinds.

Just create a new bookmark, paste the snippet, make sure it starts with

javascript

Open video

Works on html5 video elements (also a lot of the ones that don't have a 'save video' context menu option

javascript:window.location.href=(document.querySelector( "video[src]" ) || document.querySelector( "video>source" )).src

Video to TV

Works on html5 video elements and sends it to Kodi

javascript:var ip="192.168.999.999:8080";window.location.href="http://"+ip+"/jsonrpc?request="+encodeURIComponent("{\"jsonrpc\":\"2.0\",\"method\":\"Player.Open\",\"params\":{\"item\":{\"file\":\""+(document.querySelector( "video[src]" ) || document.querySelector( "video>source" )).src +"\"}}}")

Open Tweakers video

Works on Tweakers.net videos: picks the highest resolution available (subject to change)

javascript:with (new XMLHttpRequest()) { open("GET", "//tweakers.net/video/s1playlist" + document.querySelector("iframe").src.match(/player(\/\d+\/)/)[1] + "0/0/playlist.xspf"), responseType = "json", onload = function(x) { if (status === 200) document.location.href = Array.prototype.map.call(x.target.response.items[0].locations.progressive, function(i) { return { "h": i.height | 0, "u": i.sources[0].src } }).sort(function(a, b) { if (a.h === b.h) return 0; else return a.h > b.h ? -1 : 1 })[0].u; } , send() }

Tweakers to TV

Works on Tweakers.net videos: picks the highest resolution available (subject to change): sends it to Kodi for a quality TV show from your couch

javascript:var ip="192.168.999.999:8080";with (new XMLHttpRequest()) { open("GET", "//tweakers.net/video/s1playlist" + document.querySelector("iframe").src.match(/player(\/\d+\/)/)[1] + "0/0/playlist.xspf"), responseType = "json", onload = function(x) { if (status === 200) document.location.href = "http://"+ip+"/jsonrpc?request=" + encodeURIComponent("{\"jsonrpc\":\"2.0\",\"method\":\"Player.Open\",\"params\":{\"item\":{\"file\":\"" + Array.prototype.map.call(x.target.response.items[0].locations.progressive, function(i) { return { "h": i.height | 0, "u": i.sources[0].src } }).sort(function(a, b) { if (a.h === b.h) return 0; else return a.h > b.h ? -1 : 1 })[0].u + "\"}}}"); } , send() }

html5ify

Tries to change object/embed video elements into html5 video tags

javascript:[].forEach.call(document.querySelectorAll("object>embed"),function(e){var o=e.parentElement,f,m;if(m=e.src.match(/.*\.(mp4|mov)/)){o.parentElement.replaceChild((f=document.createElement("video"),f.width=o.width||e.width,f.height=o.height||e.height,f.setAttribute("controls","true"),f.src=m[0],f),o)}})

flv link

Creates a link containing the flv file (since browsers don't play flv natively

javascript:with(document.body.appendChild(document.createElement("a"))){innerText="LINK";setAttribute("href",decodeURIComponent(document.querySelector("embed").getAttribute("flashvars").match(/flv_url=([^&]*)&/)[1]))}

YT html5ify

Tries to change object/embed youtube video elements into html5 link

javascript:[].forEach.call(document.querySelectorAll("object>embed"),function(e){var o=e.parentElement,s=e.src,f,m;if(m=s.match(/(youtube.com\/)v(\/[^?&\/]*)/)){o.parentElement.replaceChild((f=document.createElement("iframe"),f.width=o.width||e.width,f.height=o.height||e.height,f.setAttribute("frameborder","0"),f.setAttribute("allowfullscreen",true),f.src="//"+m[1]+"embed"+m[2],f),o)}})