Last active
September 29, 2016 17:26
-
-
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.
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
// ==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