Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Notifies a user if they arrive at an outdated documentation page for jQuery Mobile.
// ==UserScript==
// @match*
// ==/UserScript==
// notifies user of newer version of jQuery Mobile documentation
(function versionNotifier() {
var path = window.location.pathname,
// regex for version number in url
re = /[0-9ab.]+\//,
// extract version being viewed from path
// this is the only way I could reliably find to get this
// data-url on page element is inconsistent across doc versions
docsVer = path.match(re).toString().split('/')[0],
// cache body element
body = document.getElementsByTagName('body')[0],
// create iframe to be appended to body
iframe = document.createElement('iframe');
// set the src and style attributes
// append the iframe
// when the iframe loads
iframe.onload = function() {
// get the current version off the first jqm page's data-url attr
var currentVer = iframe.contentDocument.getElementsByClassName('ui-page')[0].getAttribute('data-url').split('/')[2];
// if we're not already viewing the current version
if (currentVer !== docsVer) {
// cache the content div (where we're going to insert the message
var contentDiv = body.getElementsByClassName('ui-content')[0],
// create a div to hold our message
messageDiv = document.createElement('div'),
// create the message
message = document.createTextNode('Looks like this is an old version of the documentation. '),
// create a link
link = document.createElement('a'),
// and the link text
linkText = document.createTextNode('Go to the latest version');
// set classes to gives us a yellow notification bar
messageDiv.setAttribute('class','ui-bar ui-bar-e');
// prevent jqm from using ajax to load page
// this prevents ajax request on older versions of jqm
// set href to latest docs
// append link text to the link
// append the message and link to the message container
// insert it at the top of the content div
// and remove the iframe
else {
// if we're already on latest version of docs, just remove the iframe

jasonlcrane commented Dec 14, 2011

This is a userscript (only tested in Chrome) that adds a notification to older jQuery Mobile docs pages that you're not viewing the latest version of the docs. It's pretty hacky, but it's the only way I could figure out to do it.

The problem this hopes to solve: Do a Google search for pagecreate (for example) on You'll get results for several different versions of the jQuery Mobile docs, but frequently not the docs for the current release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment