Skip to content

Instantly share code, notes, and snippets.

@olejorgenb
Created November 25, 2016 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olejorgenb/771f8cf79fdbca2ea22fb5ed5e582e50 to your computer and use it in GitHub Desktop.
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
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