抖音单页视频下载助手
// ==UserScript==
// @name 抖音单页视频下载助手
// @namespace http://tampermonkey.net/
// @version 0.3
// @description try to take over the world!
// @author You
// @match https://www.douyin.com/video/*
// @match www.douyin.com/user/*
// @grant GM_setClipboard
// @icon https://www.google.com/s2/favicons?domain=douyin.com
// @grant unsafeWindow
// ==/UserScript==
function GetRenderTextVideo(MergeArray,VideoList){
for(let index=0;index<VideoList.length;index++){
let item=VideoList[index].video.playAddr
if(item.length!==0){
MergeArray.push('https://'+item[0].src.replace('//',''))
}else{
alert('8887')}
}
}
if(window.location.href.indexOf('www.douyin.com/user')!==-1){
let videolist=[]
function addXMLRequestCallback(callback){
var oldSend, i;
if( XMLHttpRequest.callbacks ) {
// we've already overridden send() so just add the callback
XMLHttpRequest.callbacks.push( callback );
} else {
// create a callback queue
XMLHttpRequest.callbacks = [callback];
// store the native send()
oldSend = XMLHttpRequest.prototype.send;
// override the native send()
XMLHttpRequest.prototype.send = function(){
// process the callback queue
// the xhr instance is passed into each callback but seems pretty useless
// you can't tell what its destination is or call abort() without an error
// so only really good for logging that a request has happened
// I could be wrong, I hope so...
// EDIT: I suppose you could override the onreadystatechange handler though
for( i = 0; i < XMLHttpRequest.callbacks.length; i++ ) {
XMLHttpRequest.callbacks[i]( this );
}
// call the native send()
oldSend.apply(this, arguments);
}
}
}
// e.g.
addXMLRequestCallback( function( xhr ) {
xhr.addEventListener("load", function(){
if ( xhr.readyState == 4 && xhr.status == 200 ) {
if(xhr.responseURL.indexOf('/web/aweme/post')!==-1){
console.log('触发了加载')
let list=JSON.parse(xhr.response)
if(list.aweme_list!==undefined){
for(let index=0;index<list.aweme_list.length;index++){
let item=list.aweme_list[index].video.play_addr.url_list
if(item.length!==0){
videolist.push('https://'+item[0].replace('https://','').replace('http://','').replace('//',''))
}else{
alert('888')}
}
}
}
}
});
});
let unrender=JSON.parse(decodeURIComponent(document.querySelector('#RENDER_DATA').innerText))
let keys=Object.keys(unrender)
for(let index=0;index<keys.length;index++){
if(unrender[keys[index]].post!==undefined){
GetRenderTextVideo(videolist,unrender[keys[index]].post.data)
}
}
let parenttagert=document.querySelector('.Z0NF3RWY')
let div=document.createElement("div");
div.innerHTML='<button class="q6zgm94p k-vFWw3W FDOWibym BgSUKoKp">获取已加载视频</button>'
div.onclick=function(event){
GM_setClipboard(videolist.join('\n'))
alert('已设置到剪辑版,数量为:'+videolist.length)
};
parenttagert.append(div);
return;
}
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', text);
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
let parenttagert=document.querySelector('._9c2452d0d6d8dbc6de035f37c1b11314-scss')
let div=document.createElement("div");
div.innerHTML='<div class="_07991c9043badbe055fdf2acb3cbad62-scss _1ff76af5eb8264c41dbf36b70319d944-scss"><svg width="32" height="32" fill="#4F5168" xmlns="http://www.w3.org/2000/svg" class="b48f34fd3b3d967911ebb9f5e585d007-scss dc0ebe29d2f027b192f35e304bd51970-scss" viewBox="0 0 36 36" style="display: ;width: 0;"><path fill-rule="evenodd" clip-rule="evenodd" d="M21.884 9.417c-1.209-1.157-3.214-.3-3.214 1.373v2.396c-.132 0-.263.001-.393.004-1.402-.039-6.254.115-9.667 3.775-2.361 2.532-3.423 6.562-3.357 8.64-.062 2.075.905 1.888 1.165 1.41 2.976-5.46 12.252-3.79 12.252-3.79v2.265c0 1.637 1.932 2.508 3.159 1.424l7.989-7.059a1.9 1.9 0 00.055-2.797l-7.99-7.641z" fill="#2F3035" fill-opacity="0.9" style="display: none;"></path></svg><span class="_891e9d38c00e1b78e2eae43ab8b92359-scss" style="cursor: pointer;">下载此视频</span><div class="_421d3aff42f03ac25665dc94de7ceadb-scss _6e84962fcb7da3b1e8100d798c94fd0a-scss" style="display: none;"><div class="a508b8e520c4938b699e76f52758e1b5-scss"><div class="f34e96e88162611d7208f348d4f89234-scss"><img src="//p6.douyinpic.com/img/aweme-qrcode/HfLOWW6996335373702006541~c5_720x720.png?from=1247829622" alt="3.82 wfB:/ 这样子的小风车你们喜欢吗~%%夹子音 %%夹子音挑战 %%夹子音变装 @DOU+小助手 @抖音小助手 https://v.douyin.com/d1FgV77/ 复制此链接,打开Dou音搜索,直接观看视频!" class=""></div></div><div class="c970dfb43b7e68344f353625de339de0-scss"><div class="_6ed090956a2566bf4d47a648b75d87ef-scss">打开抖音扫码或复制口令粘贴给微信/QQ好友</div><div class="_5d025eb178c1c97d99eb9717cb4f0290-scss"><span class="_95cfb8df7d5be42fc93f8f4464a1c648-scss">3.82 wfB:/ 这样子的小风车你们喜欢吗~%%夹子音 %%夹子音挑战 %%夹子音变装 @DOU+小助手 @抖音小助手 https://v.douyin.com/d1FgV77/ 复制此链接,打开Dou音搜索,直接观看视频!</span><button class="abace09bde29f9d2077ba2a9e9e2b67d-scss _3c25ad295260cb707e35da1ec8d93a51-scss _14339689bca6b9eda19c146a14df625e-scss _047cfcad258573fad8a7513577bb9f75-scss"><span>复制</span></button></div></div></div></div>';
div.onclick=function(event){
let url=document.querySelector('video').currentSrc
GM_setClipboard(url)
alert('已设置到剪辑版')
};
parenttagert.append(div);