Skip to content

Instantly share code, notes, and snippets.

@olejorgenb
Created Nov 25, 2016
Embed
What would you like to do?
Simple webextension to include the show/movie title in the netflix tab title
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);
{
"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