Skip to content

Instantly share code, notes, and snippets.

@henrik
Last active September 29, 2016 17:26
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 henrik/c7ad3b90379a19f2c0164b3243c6b378 to your computer and use it in GitHub Desktop.
Save henrik/c7ad3b90379a19f2c0164b3243c6b378 to your computer and use it in GitHub Desktop.
Tampermonkey (https://tampermonkey.net/) script to indicate on BBC iPlayer browser tabs when the episode becomes unavailable.
// ==UserScript==
// @name iPlayer better tabs
// @namespace http://henrik.nyh.se/
// @version 0.2
// @description Indicates on browser tabs when the episode becomes unavailable. Counts down if the tab is left open. Also strips title prefixes like "BBC iPlayer" so tabs show actual titles.
// @author Henrik Nyh
// @match http://www.bbc.co.uk/iplayer/*
// @match http://www.bbc.co.uk/programmes/*
// @grant none
// @updateURL https://gist.githubusercontent.com/henrik/c7ad3b90379a19f2c0164b3243c6b378/raw
// ==/UserScript==
(function() {
"use strict";
var updateEverySeconds = 60;
// Strip prefixes from title.
var niceTitle = document.title.replace(/^BBC (iPlayer|One|Two|Three|Four) - /, "");
document.title = niceTitle;
// Show countdown, if available.
var match = document.body.innerHTML.match(/"availabilityEnd":"(.+?)"/);
if (!match) return;
var endDate = new Date(match[1]);
function updateTitle() {
var now = new Date();
var msLeft = endDate - now;
var daysLeft = msLeft / 1000 / 60 / 60 / 24;
var prefix;
if (daysLeft < 0) { prefix = "gone :("; }
else if (daysLeft < 1) { prefix = "<1d!"; }
else if (daysLeft > 31) { prefix = "1m+"; }
else {
var fullDays = Math.round(daysLeft);
prefix = fullDays + "d";
}
document.title = "[" + prefix + "] " + niceTitle;
}
updateTitle();
setInterval(updateTitle, 1000 * updateEverySeconds);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment