-
Notifications
You must be signed in to change notification settings - Fork 19
/
script.min.js
2 lines (2 loc) · 5.86 KB
/
script.min.js
1
2
var scriptOptions={scrolling_min_time:1300,scrolling_max_time:2100,min_views:-1,delete_from_next_txt:!0,output_name_type:2,adapt_text_output:!0,allow_images:!0,export_format:"txt",exclude_from_json:[],advanced:{get_array_after_scroll:!1,get_link_by_filter:!0,check_nullish_link:!0,log_link_error:!0,maximum_downloads:1/0,delete_from_dom:!1,get_video_container_from_e2e:!1},node:{resolve:null,isNode:!1,isResolveTime:!1}};function nodeElaborateCustomArgs(e){""!==(e??"")&&e.forEach(e=>{var t=e[0].split("=>");1===t.length?scriptOptions[e[0]]=e[1]:scriptOptions[t[0]][t[1]]=e[1]})}var height=document.body.scrollHeight,containerMap=new Map([]),skipLinks=[];function loadWebpage(){0===document.querySelectorAll(".tiktok-qmnyxf-SvgContainer").length?(!scriptOptions.advanced.get_array_after_scroll&&scriptOptions.advanced.delete_from_dom&&window.scrollTo({top:document.body.scrollHeight-window.outerHeight*(window.devicePixelRatio||1),behavior:"smooth"}),setTimeout(()=>{window.scrollTo({top:document.body.scrollHeight,behavior:"smooth"}),setTimeout(()=>{height!==document.body.scrollHeight?!scriptOptions.advanced.get_array_after_scroll&&(addArray(),scriptOptions.advanced.maximum_downloads<Array.from(containerMap).length+skipLinks.length)?ytDlpScript():setTimeout(()=>{height=document.body.scrollHeight,loadWebpage()},Math.floor(Math.random()*scriptOptions.scrolling_max_time+scriptOptions.scrolling_min_time)):setTimeout(()=>{0===document.querySelectorAll(".tiktok-qmnyxf-SvgContainer").length&&height==document.body.scrollHeight?(scriptOptions.node.isResolveTime=!0,ytDlpScript(),skipLinks=[]):loadWebpage()},3500)},150)},!scriptOptions.advanced.get_array_after_scroll&&scriptOptions.advanced.delete_from_dom?Math.floor(600*Math.random()+600):1)):setTimeout(function(){loadWebpage()},1e3)}function addArray(){var e,t,o,i,r="[data-e2e=user-liked-item], [data-e2e=music-item], [data-e2e=user-post-item], [data-e2e=favorites-item], [data-e2e=challenge-item], [data-e2e=search_top-item]";let n=document.querySelectorAll(scriptOptions.advanced.get_video_container_from_e2e?r:".tiktok-x6y88p-DivItemContainerV2, .css-x6y88p-DivItemContainerV2, .css-1soki6-DivItemContainerForSearch, .css-ps7kg7-DivThreeColumnItemContainer");for(e of n=scriptOptions.advanced.get_video_container_from_e2e?Array.from(n).map(e=>e.parentElement):n)e&&(t=(scriptOptions.advanced.get_link_by_filter?Array.from(e.querySelectorAll("a")).filter(e=>-1!==e.href.indexOf("/video/")||-1!==e.href.indexOf("/photo/"))[0]:e.querySelector("[data-e2e=user-post-item-desc], "+r)?.querySelector("a"))?.href,!scriptOptions.allow_images&&-1!==t.indexOf("/photo/")||(scriptOptions.advanced.check_nullish_link&&""===(t??"")?scriptOptions.advanced.log_link_error&&console.log("SCRIPT ERROR: Failed to get link!"):-1===skipLinks.indexOf(t)&&(o=e.querySelector(".css-cralc2-SpanPlayCount, [data-e2e=video-views]")?.innerHTML??"0",i=e.querySelector(".css-vi46v1-DivDesContainer a span")?.textContent??e.querySelector(".css-a3te33-AVideoContainer picture img")?.alt??"",containerMap.set(t,{views:""+o.replace(".","").replace("K","00").replace("M","00000")+(-1===o.indexOf("K")&&-1===o.indexOf("M")||-1!==o.indexOf(".")?"":"0"),caption:i}))));if(!scriptOptions.advanced.get_array_after_scroll&&scriptOptions.advanced.delete_from_dom)for(var a of Array.from(n).slice(0,n.length-20))a.remove()}function sanitizeName(e){return e.replaceAll("<","‹").replaceAll(">","›").replaceAll(":","∶").replaceAll('"',"″").replaceAll("/","∕").replaceAll("\\","∖").replaceAll("|","¦").replaceAll("?","¿").replaceAll("*","")}function deleteUnrequestedContent(e){for(var t in e)-1!==scriptOptions.exclude_from_json.indexOf(t)&&delete e[t];return 1===Object.keys(e).length?e[Object.keys(e)[0]]:e}function ytDlpScript(){addArray();let e="json"===scriptOptions.export_format?[]:"";for(var[t,o]of Array.from(containerMap))+o.views<scriptOptions.min_views||("json"===scriptOptions.export_format?e.push(deleteUnrequestedContent({...o,url:t})):e+=t+`
`);if(scriptOptions.node.isNode&&!scriptOptions.node.isResolveTime)return getWhatToReturn(e);downloadScript("object"==typeof e?JSON.stringify(e):e)}function getWhatToReturn(e){return"object"==typeof e?e:e.split("\n")}function downloadScript(e,t){if(scriptOptions.node.isNode&&!t)return scriptOptions.node.isResolveTime?(scriptOptions.node.resolve(getWhatToReturn(e)),scriptOptions.node.resolve=null,void(scriptOptions.node.isResolveTime=!1)):getWhatToReturn(e);t=new Blob([e],{type:"text/plain"}),e=document.createElement("a");let o="TikTokLinks."+scriptOptions.export_format;switch(scriptOptions.output_name_type){case 0:o=document.querySelector("[data-e2e=user-title]")?.textContent.trim()??document.querySelector("[data-e2e=browse-username]")?.firstChild?.textContent.trim()??document.querySelector("[data-e2e=browse-username]")?.textContent.trim()??document.querySelector("[data-e2e=challenge-title]")?.textContent.trim()??document.querySelector("[data-e2e=music-title]")?.textContent.trim()??"TikTokLinks."+scriptOptions.export_format;break;case 1:o=document.title.substring(0,document.title.indexOf(" | TikTok"))+"."+scriptOptions.export_format;break;case 2:o=`${document.querySelector("h1")?.textContent.trim()??"TikTokLinks"}.`+scriptOptions.export_format}"string"==typeof scriptOptions.output_name_type&&(o=scriptOptions.output_name_type),scriptOptions.adapt_text_output&&(o=sanitizeName(o)),e.href=URL.createObjectURL(new File([t],o,{type:"json"===scriptOptions.export_format?"application/json":"text/plain"})),e.download=o,e.click(),URL.revokeObjectURL(e.href)}function requestTxtNow(){var e=ytDlpScript();return scriptOptions.delete_from_next_txt&&(skipLinks.push(...Array.from(containerMap).map(e=>e[0])),containerMap=new Map([])),e}function startDownload(e){if(containerMap=new Map([]),skipLinks=[],""!==(e??"")&&(scriptOptions.output_name_type=e),scriptOptions.node.isNode)return new Promise(e=>{scriptOptions.node.resolve=e,loadWebpage()});loadWebpage()}nodeElaborateCustomArgs(),startDownload();