在比较早的时候,淘宝手机站在电脑上打开是没有链接跳转到PC站的,而手机站显示的内容又有限。看个商品大图很是蛋疼,于是这个手机站助手就出来了。
功能很简单,就是当浏览器访问*.m.taobao.com*的任何一个链接时,自动跳转到相应的PC站。

比如说,当你访问http://h5.m.taobao.com/awp/core/detail.htm?id=**********时,自动打开新的标签访问这个链接对应的http://item.taobao.com/item.htm?id=**********

实现方式很简单

先配置好extensions的manifest信息

manifest里面的各个参数可以参照Google给出的文档,还提供了各种示例  查看示例 只要你了解JS的语法。照着这些例子,基本上都能做出来自己想要的extensions

{"name": "taobao helper","manifest_version":2,"icons": { "16": "icon.png",             "48": "icon.png",            "128": "icon.png"},  "version": "1.0","description": "Auto jump m.taobao.com to taobao.com","background": { "scripts": ["background.js"] },"browser_action" :{ "default_icon" : "icon.png","default_title" : "taobao helper"},"permissions" : ["tabs"]
}

再编写background.js的内容

我这里添加了限制,只有在taobao.com下才对插件进行打开关闭操作。当插件关闭时,打开手机站是不会自动跳转到PC站。


var cookieName = "taobaoconvert_chromeplugs";function setIco(tab) {if (tab.url.indexOf("taobao.com") >= 0) {//cheack cookieif (getCookie(cookieName) == null) {chrome.browserAction.setIcon({ path: "icon.png" });} else {chrome.browserAction.setIcon({ path: "icon_2.png" });}} else {chrome.browserAction.disable(tab.id);}
}function jump(tab) {if (getCookie(cookieName) != null) {return;}if (tab.url.indexOf(".m.taobao.com") >= 0) {var id = getQueryStringByName(tab.url, "id");chrome.tabs.create({ url: "http://item.taobao.com/item.htm?id=" + id, selected: true });chrome.tabs.remove(tab.id);} else if (tab.url.indexOf(".m.tmall.com") >= 0) {var id = new RegExp(/i([0-9]+)/g).exec(tab.url)[1];chrome.tabs.create({ url: "http://detail.tmall.com/item.htm?id=" + id, selected: true });chrome.tabs.remove(tab.id);}}chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {if (changeInfo.status == "loading") {jump(tab);setIco(tab);}});chrome.browserAction.onClicked.addListener(function (tab) {if (getCookie(cookieName) == null) {SetCookie(cookieName, cookieName);} else {delCookie(cookieName);}jump(tab);setIco(tab);
});function getQueryStringByName(url, name) {var result = url.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));if (result == null || result.length < 1) {return "";}return result[1];
}function SetCookie(name, value) {var Days = 30;var exp = new Date();exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
function getCookie(name) {var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));if (arr != null)return unescape(arr[2]);return null;}
function delCookie(name) {var exp = new Date();exp.setTime(exp.getTime() - 1);var cval = getCookie(name);if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

然后打包重新安装打包好的文件到你的 extensions

下载请移步  下载