快手
// ==UserScript==
// @name 快手
// @namespace http://tampermonkey.net/
// @version 0.2
// @description try to take over the world!
// @author You
// @match https://www.kuaishou.com/profile/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=kuaishou.com
// @grant unsafeWindow
// @run-at document-start
// @grant GM_setClipboard
// @grant GM_xmlhttpRequest
// @connect *
// ==/UserScript==
let downloadurl = []
let oldFetch = unsafeWindow.fetch;
function hookFetch(...args) {
return new Promise((resolve, reject) => {
oldFetch.call(this, ...args).then((response) => {
if (
args.length === 2 &&
args[0].indexOf &&
args[0].indexOf("/graphql") !== -1 &&
(args[1].body.indexOf("visionProfilePhotoList") !== -1 )
) {
console.log(args)
console.log(response)
console.log("劫持了json函数");
const oldText = response.text;
const hookText = function () {
console.log("text is run");
return new Promise((resolve, reject) => {
oldText.apply(this, arguments).then((result) => {
console.log("参数:", arguments)
console.log("劫持到了文本", result);
let resJson = unsafeWindow.JSON.parse(result)
resJson.data.visionProfilePhotoList.feeds.forEach((item) => {
downloadurl.push(item.photo.photoUrl)
})
resolve(result);
});
});
};
const oldClone = response.clone;
const hookClone = function () {
let result = oldClone.apply(this, arguments);
result.clone = hookClone;
result.text = hookText;
return result;
};
response.clone = hookClone;
}
resolve(response);
});
});
}
unsafeWindow.fetch = hookFetch;
let getVedioBtn = document.createElement("button")
getVedioBtn.innerText = "复制视频"
getVedioBtn.className = "getVedio"
getVedioBtn.style.background = "#757575";
getVedioBtn.style.color = "#fff";
let timer = setInterval(() => {
if (document.querySelector(".follow-button.user-info-follow") !== null) {
let target = document.querySelector(".follow-button.user-info-follow");
//找到了定时器
target.insertAdjacentElement("afterend", getVedioBtn)
clearInterval(timer);
}
}, 1000);
getVedioBtn.addEventListener("click", StatToGetVideo)
async function StatToGetVideo() {
GM_setClipboard(downloadurl.join("\n"));
alert("共成功:"+downloadurl.length+'个');
}