Skip to content

Instantly share code, notes, and snippets.

@mtandre
Created December 28, 2015 21:37
Show Gist options
  • Save mtandre/0f60e21cfc50b605814c to your computer and use it in GitHub Desktop.
Save mtandre/0f60e21cfc50b605814c to your computer and use it in GitHub Desktop.
Clickability Bookmarklet: Toggle Mobile
javascript:(function(){
var url = window.location.href,
newUrl = "";
if (url.indexOf("jsonline.com") > -1) {
if (url.indexOf("www.jsonline.com") > -1) {
newUrl = url.replace(/www\./i,"m.");
} else {
newUrl = document.querySelector("link[rel='canonical']").href + window.location.search;
}
} else {
if (url.indexOf("?d=mobile") > -1) {
var tempUrl = url.replace(/\?d=mobile&/i,"?");
newUrl = tempUrl.replace(/\?d=mobile/i,"");
} else if (url.indexOf("&d=mobile") > -1) {
newUrl = url.replace(/&d=mobile/i,"");
} else {
if (window.location.search.indexOf("?") > -1) {
newUrl = url + "&d=mobile";
} else {
newUrl = url + "?d=mobile";
}
}
}
window.location.href = newUrl;
})();
// minified
javascript:(function(){var url=window.location.href,newUrl="";if(-1<url.indexOf("jsonline.com"))newUrl=-1<url.indexOf("www.jsonline.com")?url.replace(/www\./i,"m."):document.querySelector("link[rel='canonical']").href+window.location.search;else if(-1<url.indexOf("?d=mobile"))var tempUrl=url.replace(/\?d=mobile&/i,"?"),newUrl=tempUrl.replace(/\?d=mobile/i,"");else newUrl=-1<url.indexOf("&d=mobile")?url.replace(/&d=mobile/i,""):-1<window.location.search.indexOf("?")?url+"&d=mobile":url+"?d=mobile";window.location.href=newUrl;})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment