// ==UserScript== // @name 抖音视频下载插件 // @namespace https://space.bilibili.com/1552375363 // @version 1.75 // @description 修改网页以使其出现一个按钮供用户点击下载抖音视频 // @author Xbodw // @match https://www.douyin.com/* // @match https://*.douyin.com // @match http://* // @match ftp://* // @match *://*/* // @icon https://tse3-mm.cn.bing.net/th/id/OIP-C.nncnWjuyFBadY1Nl0PqDDwAAAA?pid=ImgDet&rs=1 // @grant unsafeWindow // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; var sleep = function(time) { var timeOut = new Date().getTime() + parseInt(time, 10); while(new Date().getTime() <= timeOut) {} }; function Viewer(TabType,ViewString,HasString) { return document.querySelector('' + TabType + '[' + ViewString + '*="' + HasString + '"]').getAttribute(ViewString); } // 按钮input元素部分 if(window.location.host == "www.douyin.com") { var button = document.createElement("input"); button.setAttribute("type", "button"); button.setAttribute("value", "下载"); button.style.width = "40px"; button.style.height = "30px"; button.style.align = "center"; button.style.background = "#000000"; button.style.color = "white"; button.style.visibility = 'visible'; button.style.border="1px solid red"; //视频解析部分 button.onclick = function() { if(window.location.host == "www.douyin.com") {} else { alert("网站可能不是抖音!"); return; } var link = document.querySelector('source[src*="&aid="]').getAttribute('src'); var part = document.querySelector('source[src*="&aid="]').parentElement.getAttribute('mediatype'); if(part == "video") { //var link=document.querySelector('source[src*="id="][src*="v3-web"]').getAttribute('src'); var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var hour = date.getHours(); var minute = date.getMinutes(); var second = date.getSeconds(); var filename="视频_" + year + month + day + hour + minute + second + ".mp4"; console.log("视频正在合成,完成后将自动保存.");fetch(link).then(res => res.blob()).then(blob => { const a = document.createElement('a'); document.body.appendChild(a) a.style.display = 'none' const url = window.URL.createObjectURL(blob); a.href = url; a.download = filename; a.click(); document.body.removeChild(a) window.URL.revokeObjectURL(url); }); } else { alert("获取视频下载链接失败,可能是接口在维护或脚本版本过低!"); } } //抖音下载按钮判断部分,请勿删除 if(window.location.href == "https://www.douyin.com/") { //var getdiv = document.querySelector('div[class="iViO9oMI"]'); //getdiv.remove(); //getdiv = document.querySelector('div[class="HQwsRJFy"]'); //getdiv.appendChild(button); var getdiv9 = document.querySelector('div[class="l9GtwryL"]'); var getdiv10 = getdiv9.parentNode; var getdiv11 = getdiv10.parentNode; getdiv10.remove(); getdiv11.appendChild(button); } if(window.location.href.indexOf("https://www.douyin.com/video/") !== -1) { //var dylogo = document.querySelector('a[href="//www.douyin.com/"]'); //dylogo.remove(); //var getdiv7 = document.querySelector('div[class="iViO9oMI"]'); //getdiv7.remove(); //var getdiv8 = document.querySelector('div[class="HQwsRJFy"]'); //getdiv8.appendChild(button); var getdiv7 = document.querySelector('div[class="l9GtwryL"]'); var getdiv8 = getdiv7.parentNode; var getdiv2 = getdiv8.parentNode; getdiv8.remove(); getdiv2.appendChild(button); } if(window.location.href.indexOf("https://www.douyin.com/search/") !== -1) { var dylogo = document.querySelector('a[href="//www.douyin.com/"]'); dylogo.remove(); var getdiv1 = document.querySelector('div[class="iViO9oMI"]'); getdiv1.remove(); var getdiv6 = document.querySelector('div[class="HQwsRJFy Bo1o4KGi"]'); getdiv6.appendChild(button); } if(window.location.href.indexOf("modal_id=") !== -1) { var getdiv3 = document.querySelector('div[class="btn"]'); var getdiv4 = getdiv3.parentNode; getdiv3.remove(); getdiv4.appendChild(button); } } })();