Created
November 25, 2016 07:30
-
-
Save olejorgenb/771f8cf79fdbca2ea22fb5ed5e582e50 to your computer and use it in GitHub Desktop.
Simple webextension to include the show/movie title in the netflix tab title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function expectOne(array) { | |
if(array.length === 1) | |
return array[0]; | |
else | |
throw new Error("Expected one element, got " + array.length); | |
} | |
function findMediaTitle() { | |
var bag = expectOne(document.getElementsByClassName("playback-longpause-container")); | |
bag = expectOne(bag.getElementsByClassName("content")); | |
var mainTitle = expectOne(bag.getElementsByTagName("h2")).innerText; | |
var subTitle = | |
Array.prototype.join.call( | |
Array.prototype.map.call(bag.getElementsByTagName("h3"), | |
function(x) { return x.innerText; }), " "); | |
return mainTitle + " " + subTitle; | |
} | |
// Note: netflix is a single page app, and it doesn't change the title on | |
// navigation. This makes an event based approach a lot more messy. (the video | |
// element has events for playing etc.) | |
function poll() { | |
if(!document.location.href.match("netflix.com/watch")) { | |
document.title = "Netflix"; | |
return; | |
} | |
var video = document.getElementsByTagName("video")[0]; | |
if(!video) { | |
return; | |
} | |
var stateStr = "playing"; | |
if(video.paused) | |
stateStr = "paused"; | |
document.title = "Netflix: " + findMediaTitle() + " " + "[" + stateStr + "]"; | |
} | |
setInterval(poll, 3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Netflix title tweak", | |
"version": "0.1", | |
"description": "", | |
"permissions": [ | |
"*://*.netflix.com/*" | |
], | |
"content_scripts": [ | |
{ | |
"matches": ["*://*.netflix.com/*"], | |
"js": ["main.js"] | |
} | |
], | |
"manifest_version": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment