Exit Full View

BBC Weather Fix

The BBC should know better, but their weather pages is bloody annoying.

Firstly, it has an annoying animated news ticker, which never has anything useful, and sucks resources. NO!

Secondly, navigating the tabs doesn't work if you have cookies disabled. Lame!

Thirdly, Its not too easy to navigate between my favourite three forecasts (5 day, 24 hour, and monthly).

This extension turns off the ticker and recreates the tabs in a hacky, but usable fashion (adding the missing monthly outlook tab).

Known Bugs

  • I've hard coded the location to Romford
  • The current tab no longer shown as selected
  • The monthly outlook tab doesn't have an image, so looks out of place (why is the BBC using images anyway?)
  • When navigating to the monthly page, there is no link back again.

Code

// ==UserScript==
// @name           BBC Weather
// @namespace      nickthecoder
// @description    Removes animated headlines
// @include        http://news.bbc.co.uk/weather/forecast/*
// ==/UserScript==

// Turns off the annoying (and CPU sucking) news ticker (which never says anything interesting).

// Please change the version number before each modification.
var version = "1.0";

// Add stubs for logging if firebug isn't enabled on this browser
if ( ! console ) {
  console = new Object();
  var doNothing = function() {};
  console.debug = console.info = console.log = doNothing;
}

console.debug( "begin greasemonkey script bbc_weather" );


// Now lets do the biz...
// It seems that the html that we want to intecept doesn't exist when this greasemonkey script runs,
// So lets set an  arbitary timer, and hopefully it will be long enough pause!
setTimeout( ntc_stopTicker, 2000 );
// It seems that the BBC code changes the onclick of the tab's links (which I don't want),
// so I'll replace the tabs *after* their code has run (and therefore another timeout).
setTimeout( ntc_replaceTabs, 2000 );


function ntc_replaceTabs() {
  var tabA = document.getElementById( "forecasttabA" );
//  if ( tabA == null ) {
//   tabA = document.getElementById( "tabA" );
//  }
  if ( tabA != null ) {

    var ul = tabA.parentNode;
    
    var html = '<li id="forecasttabA"><a href="http://news.bbc.co.uk/weather/forecast/4290?area=Romford"></a></li>';
    html += '<li id="forecasttabB"><a href="http://news.bbc.co.uk/weather/forecast/4290?area=Romford&state=fo:B#fo:B"></a></li>';
    html += '<li id="tabB"><a href="http://news.bbc.co.uk/weather/forecast/10209?state=mp:B#mp:B">Monthly</a></li>';
    html += '<li><a href="http://nickthecoder.co.uk/pinkwino/view/BBC+Weather+Fix">ntc</a></li>';

    ul.innerHTML = html;
  }
}

function ntc_stopTicker() {
  var startStopAnchors = getElementsByClass( "start_stop_anchor", document, "a" );

  for ( var i = 0; i < startStopAnchors.length; i ++ ) {
    var startStopAnchor = startStopAnchors[ i ];
    ntc_fireEvent( startStopAnchor, "click" );
  }
}


function ntc_fireEvent(element,event){
    if (document.createEventObject){
        // dispatch for IE
        var evt = document.createEventObject();
        return element.fireEvent('on'+event,evt)
    }
    else{
        // dispatch for firefox + others
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent(event, true, true ); // event type,bubbling,cancelable
        return !element.dispatchEvent(evt);
    }
}
 

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
    // console.debug( els[i].className );
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

console.debug( "end greasemonkey script bbc_weather" );