更换获取方式方法
This commit is contained in:
@@ -7,18 +7,27 @@ import store from '@/store'
|
|||||||
export function sendChromeAPIMessage(message) {
|
export function sendChromeAPIMessage(message) {
|
||||||
message.type = 'api'
|
message.type = 'api'
|
||||||
message.url = "https://kuajing.pinduoduo.com/" + message.url;
|
message.url = "https://kuajing.pinduoduo.com/" + message.url;
|
||||||
|
message.anti = false
|
||||||
if (message.needMallId) {
|
if (message.needMallId) {
|
||||||
// 如果参数中没有携带MallId,则从state中获取
|
// 如果参数中没有携带MallId,则从state中获取
|
||||||
if (!message.mallId) {
|
if (!message.mallId) {
|
||||||
message.mallId = store.state.mallId;
|
message.mallId = store.state.mallId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
chrome.runtime.sendMessage(message, resolve)
|
chrome.runtime.sendMessage(message, resolve)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getAntiContent = message => {
|
||||||
|
message.type = "genAnti"
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
chrome.runtime.sendMessage(message, resolve)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 向Chrome发送消息
|
* 向Chrome发送消息
|
||||||
* @param message 消息
|
* @param message 消息
|
||||||
|
|||||||
@@ -413,7 +413,3 @@ const genAnti = function () {
|
|||||||
}()
|
}()
|
||||||
return S()
|
return S()
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.resolve(genAnti()).then(r => {
|
|
||||||
// console.log(r.toString())
|
|
||||||
})
|
|
||||||
@@ -1,21 +1,20 @@
|
|||||||
/**
|
/**
|
||||||
利用chrome的fetch来避免跨域
|
利用chrome的fetch来避免跨域
|
||||||
**/
|
**/
|
||||||
import {genAnti} from "@/entry/genAnti";
|
import {getAntiContent} from "@/api/chromeApi";
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||||
if (request.type == 'api') {
|
if (request.type == 'api') {
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve) => {
|
||||||
let headers = {};
|
let headers = {};
|
||||||
|
|
||||||
if (request.needMallId) {
|
if (request.needMallId) {
|
||||||
headers.Mallid = request.mallId;
|
headers.Mallid = request.mallId;
|
||||||
}
|
}
|
||||||
|
if (request.anti) {
|
||||||
|
headers["Anti-Content"] = getAntiContent()
|
||||||
|
}
|
||||||
headers['Content-Type'] = 'application/json';
|
headers['Content-Type'] = 'application/json';
|
||||||
headers.cookie = getCookie();
|
headers.cookie = getCookie();
|
||||||
// Promise.resolve(genAnti()).then(r => {
|
|
||||||
// headers["Anti-Content"] = r
|
|
||||||
// })
|
|
||||||
Promise.resolve().then(() => fetch(request.url, {
|
Promise.resolve().then(() => fetch(request.url, {
|
||||||
'headers': headers,
|
'headers': headers,
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
@@ -26,11 +25,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||||||
})).then((res) => {
|
})).then((res) => {
|
||||||
resolve(res.json());
|
resolve(res.json());
|
||||||
});
|
});
|
||||||
}).then((res) => {
|
}).then(sendResponse);
|
||||||
sendResponse(res);
|
|
||||||
});
|
|
||||||
} else if (request.type == 'init') {
|
|
||||||
fetch(request.url,{headers:{cookie: getCookie()}}).then(res => sendResponse(res.text()));
|
|
||||||
} else if (request.type == 'notify') {
|
} else if (request.type == 'notify') {
|
||||||
chrome.notifications.create(
|
chrome.notifications.create(
|
||||||
"" + Math.random(), {
|
"" + Math.random(), {
|
||||||
|
|||||||
@@ -1 +1,10 @@
|
|||||||
console.log('hello world content todo something~')
|
console.log('hello world content todo something~')
|
||||||
|
if (window["webpackJsonp"] && location.href.indexOf("kuajing.pinduoduo.com") > -1) {
|
||||||
|
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||||
|
if (request.type == 'genAnti') {
|
||||||
|
// window["webpackJsonp"]
|
||||||
|
sendResponse("kubbo")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import ElementUI from 'element-ui'
|
|||||||
import '../assets/css/element-variables.scss'
|
import '../assets/css/element-variables.scss'
|
||||||
import instance from '../api'
|
import instance from '../api'
|
||||||
import utils from '../utils'
|
import utils from '../utils'
|
||||||
import install from '../utils/install'
|
import '../utils/install'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
Vue.use(ElementUI)
|
Vue.use(ElementUI)
|
||||||
|
|||||||
@@ -18,7 +18,10 @@
|
|||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"cookies",
|
"cookies",
|
||||||
"notifications"
|
"notifications",
|
||||||
|
"tabs",
|
||||||
|
"scripting",
|
||||||
|
"activeTab"
|
||||||
],
|
],
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ export default {
|
|||||||
this.$router.push('/login')
|
this.$router.push('/login')
|
||||||
} else {
|
} else {
|
||||||
this.$store.dispatch('getUserInfo');
|
this.$store.dispatch('getUserInfo');
|
||||||
this.getMainEntry()
|
|
||||||
sendChromeAPIMessage({url: 'bg/quiet/api/mms/userInfo', needMallId: false, data: {}}).then((res) => {
|
sendChromeAPIMessage({url: 'bg/quiet/api/mms/userInfo', needMallId: false, data: {}}).then((res) => {
|
||||||
if (res.errorCode == 1000000) {
|
if (res.errorCode == 1000000) {
|
||||||
if (res.result.companyList[0].malInfoList.length == 1) {
|
if (res.result.companyList[0].malInfoList.length == 1) {
|
||||||
@@ -48,11 +47,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {}
|
||||||
async getMainEntry() {
|
|
||||||
chrome.runtime.sendMessage({type: "init", url: this.$base + "main-entry"})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user