版本迭代
This commit is contained in:
		
							
								
								
									
										61
									
								
								src/entry/background.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								src/entry/background.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | ||||
|  | ||||
| /** | ||||
| 	利用chrome的fetch来避免跨域 | ||||
| **/ | ||||
| chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { | ||||
|   if (request.type == 'api') { | ||||
|     new Promise((resolve, reject) => { | ||||
|       let headers = {}; | ||||
|    | ||||
|       if (request.needMallId) { | ||||
|         headers.Mallid = request.mallId; | ||||
|       } | ||||
|       headers['Content-Type'] = 'application/json'; | ||||
|    | ||||
|       headers.cookie = getCookie(); | ||||
|        | ||||
|       fetch(request.url, { | ||||
|         'headers': headers, | ||||
|         'method': 'POST', | ||||
|         'referrerPolicy': 'no-referrer', | ||||
|         'credentials': 'include', | ||||
|         'body': JSON.stringify(request.data), | ||||
|         'mode': 'cors' | ||||
|       }).then((res) => { | ||||
|         resolve(res.json()); | ||||
|       }); | ||||
|     }).then((res) => { | ||||
|       sendResponse(res); | ||||
|     }); | ||||
|   } else if (request.type == 'notify') { | ||||
|     chrome.notifications.create( | ||||
|       "" + Math.random(), { | ||||
|         type: "basic", | ||||
|         title: "TEMU助手", | ||||
|         message: "您的商品【" + request.productName + "】成功加入发货台,请尽快处理", | ||||
|         iconUrl: "./icons/48.png" | ||||
|       }, null | ||||
|     ) | ||||
|   } | ||||
|    | ||||
|   return true; | ||||
| }); | ||||
|  | ||||
| chrome.action.onClicked.addListener(function () { | ||||
|   chrome.tabs.create({ | ||||
|       url: "./popup.html" | ||||
|   }, function (tab) { | ||||
|       console.log('tab is:' + tab); | ||||
|   }); | ||||
| }); | ||||
|  | ||||
| function getCookie() { | ||||
|   const url = new URL("https://kuajing.pinduoduo.com/"); | ||||
|   let cStr = ''; | ||||
|   chrome.cookies.getAll({domain: url.host}, (cookie) => { | ||||
|     cookie.map((c) => { | ||||
|       cStr += c.name + '=' + c.value + ';'; | ||||
|     }); | ||||
|   }); | ||||
|   return cStr; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user