本文来自网易云社区
作者:吴琪惠
{
"manifest_version": 2,
"name": "严选测试插件",
"description": "严选的测试辅助插件",
"version": "0.0.1",
"background": { "scripts": ["js/jquery-2.0.0.min.js", "js/background.js"] },
"page_action": {
"default_icon": {
"19": "19.png",
"38": "38.png" // 插件图标
},
"default_title": "严选测试插件" // shown in tooltip
},
"permissions" : ["tabs","http://test.yx.mail.netease.com/toolbox/"],
"content_scripts":[{
"matches":["http://you.yxp.163.com/*","http://you.163.com/*"],
"js":["js/jquery-2.0.0.min.js", "js/content_script.js"],
"run_at":"document_start"
}]
}
function getDomainFromUrl(url){
var host = "null";
if(typeof url == "undefined" || null == url)
url = window.location.href;
var regex = /.*\:\/\/([^\/]*).*/;
var match = url.match(regex);
if(typeof match != "undefined" && null != match)
host = match[1];
return host;
}
function checkForValidUrl(tabId, changeInfo, tab) {
console.log(getDomainFromUrl(tab.url));
if(getDomainFromUrl(tab.url).toLowerCase()=="you.yxp.163.com"){
chrome.pageAction.show(tabId);
}
};
chrome.tabs.onUpdated.addListener(checkForValidUrl);
//添加监听
window.addEventListener("dblclick", (e) => {
if (checkUrl("/order/myList")) {//订单列表页的处理
addbutton();
$('body').on('click', '.toolboxtest', function() {
console.log($(this).attr('id'));
$.ajax({
type:"post",
url:"http://xxxx/toolbox/aftersale/packageDeliver",
data:{orderId:$(this).attr('id'), packageId:""},
error:function(xhr,err){
alert('请求失败,errorcode=' + xhr.status + ', errormsg=' + err + '!')
},
success:function(data){
alert(JSON.stringify(data));
window.location.reload();
}
});
});
}else if(checkUrl("/item/detail")){//商品详情页的处理
console.log("go to page /item/detail");
var itemid = GetQueryString("id");
$.ajax({
type:"get",
url:"http://xxxx/toolbox/itemsku/getsku/"+itemid,
error:function(xhr, err){
chrome.runtime.sendMessage({type:"yx_pc_detail", error:xhr.status + ', errormsg='+xhr.result});
},
success:function(data) {
var skustr = "xxx";
$('.m-info').append(skustr); //详细处理不加赘述
}
});
}
}, false);
网易云免费体验馆,0成本体验20+款云产品!
更多网易研发、产品、运营经验分享请访问网易云社区。