Skip to content

Instantly share code, notes, and snippets.

@jdrew1303
Forked from addyosmani/mobileURLs.js
Last active August 29, 2015 14:22
Embed
What would you like to do?
// matchMedia is supported and the device has a small screen
if ( "matchMedia" in window
&& window.matchMedia( "(max-device-width: 800px)" )
) {
Array.prototype.forEach.call(
// for each element matching the selector...
document.querySelectorAll(
"a[href*='youtube.com/watch'], a[href*='flickr.com']"
),
// ...replace the href with their mobile equivalent
function( elem ) {
if ( /flickr\.com\/?(.*)$/.test( elem.href ) ) {
elem.href = "http://m.flickr.com/" + RegExp.$1;
} else {
elem.href =
"http://m.youtube.com/watch?v=" +
elem.href.replace( /.*?[?&]v=(.*?)(?:&|$)/, "$1" );
}
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment