MediaWiki:Mobile.js

/** Mobile browser helper link ************************************************ * * Adds a link to the mobile-optimized gateway at en.m.wikimedia.org * for viewers on iPhone, iPod Touch, and Android devices. * This is semi-experimental to drive more test traffic there for now; * it's still in development but very usable for reading! * * Currently set to always show the link on main page and search results, * and w/ 25% probability on other page views.

if (/(Android|iPhone|iPod)/.test(navigator.userAgent)) { addOnloadHook(function {   var prob = 1.0;    if (wgCanonicalNamespace == 'Special' && wgCanonicalSpecialPageName == 'Search') {       var pageLink = '?search=' + encodeURIComponent(document.getElementById('searchText').value);    } else if (wgPageName == 'Main_Page') {       var pageLink = '::Home'; // Special case    } else {       var pageLink = encodeURIComponent(wgPageName).replace('%2F','/').replace('%3A',':');    }    if (prob < Math.random) return;    var div = document.createElement('div');    div.setAttribute( "id", "mobileDeviceNotice" );    div.style.fontSize = '30pt';    div.style.lineHeight = '40pt';    div.style.textAlign = 'center';    div.style.marginTop = '20px';    div.style.marginBottom = '20px';    div.style.padding = '20px';    div.style.border = '2px solid gray';    div.appendChild(document.createTextNode("View this page on "));    var link = document.createElement('a'); link.href = 'http://en.m.wikipedia.org/wiki/' + pageLink; link.appendChild(document.createTextNode("Wikipedia's mobile site")); div.appendChild(link); var content=document.getElementById('content'); content.insertBefore(div,content.firstChild); }); }