// ==UserScript== // @name 【蛮吉】售后退款 // @namespace https://bbs.tampermonkey.net.cn/ // @version 0.1.0 // @description try to take over the world! // @match http*://refund2.tmall.com/dispute/prepareDownload.htm* // @author You // @grant GM_xmlhttpRequest // @connect https://bx1r8xwh6pn51.cfc-execute.bj.baidubce.com* // @connect https://bx1r8xwh6pn51.cfc-execute.bj.baidubce.com/test2 // @connect bx1r8xwh6pn51.cfc-execute.bj.baidubce.com // @connect bx1r8xwh6pn51.cfc-execute.bj.baidubce.com // @connect *127.0.0.1:7890* // @connect http://127.0.0.1:7890/cooike // @connect http://127.0.0.1:7890/cookie // @grant GM_cookie // @connect tmall.com // @run-at document-start // ==/UserScript== (function() { 'use strict'; // 获取网址中的参数 function getUrlParams(url) { // let url = window.location.href // 通过 ? 分割获取后面的参数字符串 let urlStr = url.split('?')[1] // 创建空对象存储参数 let obj = {}; // 再通过 & 将每一个参数单独分割出来 let paramsArr = urlStr.split('&') for(let i = 0,len = paramsArr.length;i < len;i++){ // 再通过 = 将每一个参数分割为 key:value 的形式 let arr = paramsArr[i].split('=') obj[arr[0]] = arr[1]; } return obj }; function addXMLRequestCallback(callback){ // 是一个捕获函数 var oldSend, i; if( XMLHttpRequest.callbacks ) { // 判断XMLHttpRequest对象下是否存在回调列表,存在就push一个回调的函数 XMLHttpRequest.callbacks.push( callback ); } else { // create a callback queue XMLHttpRequest.callbacks = [callback]; // 如果不存在则在xmlhttprequest函数下创建一个回调列表 oldSend = XMLHttpRequest.prototype.send; // 获取旧xml的send函数,并对其进行劫持 XMLHttpRequest.prototype.send = function(){ for( i = 0; i < XMLHttpRequest.callbacks.length; i++ ) { XMLHttpRequest.callbacks[i]( this ); } // 循环回调xml内的回调函数 // call the native send() oldSend.apply(this, arguments); // 由于我们获取了send函数的引用,并且复写了send函数,这样我们在调用原send的函数的时候,需要对其传入引用,而arguments是传入的参数 } } }; addXMLRequestCallback( function( xhr ) { // 调用劫持函数,填入一个function的回调函数 // 回调函数监听了对xhr调用了监听load状态,并且在触发的时候再次调用一个function,进行一些数据的劫持以及修改 xhr.addEventListener("load", function(){ if ( xhr.readyState == 4 && xhr.status == 200 ) { if(xhr.responseURL.indexOf("refund2.tmall.com/dispute/download/download") != -1){ // if (xhr.responseText == 'success'){ // console.log('捕获目标成功:'); const dataKey = getUrlParams(xhr.responseURL).dataKey; const downloagURL = 'https://refund2.tmall.com/dispute/download/downloadDisputeList.json?dataKey='+dataKey console.log('合成的下载地址为:',downloagURL); // 将下载地址 和 cookie 发送到服务器处理 // const cookies = getCookieTM(); const severURL = 'https://19z42m7544.goho.co/tmallAfterSales'; getCookieTM(severURL,dataKey,downloagURL,sendData); }; // alert(xhr.responseURL); }else{ console.log('未捕获到目标网址,提供以下网址供参考:') console.log(xhr.responseURL) }; }; }); }); // 获取cookie字典 function getCookieTM(severURL,dataKey,downloagURL,callback){ const cookieDic = {}; var tmCookie = ''; GM_cookie('list',{ domain:'tmall.com' },(r)=>{ for(var i=0;i