mirror of https://github.com/pikami/tiktok-dl.git
Clean up JS code
This commit is contained in:
parent
69574dcb7e
commit
2b56584b1b
|
@ -1,48 +1,64 @@
|
|||
createVidUrlElement = function(videoSet) {
|
||||
var videoArray = Object.entries(videoSet).map(x => {
|
||||
return {
|
||||
shareLink: x[1].shareLink,
|
||||
url: x[0],
|
||||
};
|
||||
});
|
||||
optStrings = {
|
||||
selectors: {
|
||||
feedVideoItem: 'video-feed-item-wrapper',
|
||||
modalArrowLeft: 'div.video-card-modal > div > img.arrow-right',
|
||||
modalClose: '.video-card-modal > div > div.close',
|
||||
modalPlayer: 'div > div > main > div.video-card-modal > div > div.video-card-big > div.video-card-container > div > div > video',
|
||||
modalShareInput: '.copy-link-container > input',
|
||||
},
|
||||
classes: {
|
||||
modalCloseDisabled: 'disabled',
|
||||
},
|
||||
tags: {
|
||||
resultTag: 'video_urls',
|
||||
resultParentTag: 'body',
|
||||
},
|
||||
attributes: {
|
||||
src: "src",
|
||||
},
|
||||
};
|
||||
|
||||
var urlSetElement = document.createElement("video_urls");
|
||||
createVidUrlElement = function(videoArray) {
|
||||
var urlSetElement = document.createElement(optStrings.tags.resultTag);
|
||||
urlSetElement.innerText = JSON.stringify(videoArray);
|
||||
document.getElementsByTagName("body")[0].appendChild(urlSetElement);
|
||||
document.getElementsByTagName(optStrings.tags.resultParentTag)[0].appendChild(urlSetElement);
|
||||
}
|
||||
|
||||
buldVidUrlSet = function(finishCallback) {
|
||||
var feedItem = document.getElementsByClassName("video-feed-item-wrapper")[0];
|
||||
buldVidUrlArray = function(finishCallback) {
|
||||
var feedItem = document.getElementsByClassName(optStrings.selectors.feedVideoItem)[0];
|
||||
feedItem.click();
|
||||
|
||||
var videoSet = {};
|
||||
var videoArray = [];
|
||||
var intervalID = window.setInterval(x => {
|
||||
var players = document.getElementsByClassName("video-player");
|
||||
for (var i = 0; i < players.length; i++) {
|
||||
var vidUrl = players[i].getAttribute("src");
|
||||
if(!videoSet[vidUrl]) {
|
||||
var shareLink = document.querySelector(".copy-link-container > input").value;
|
||||
videoSet[vidUrl] = {
|
||||
shareLink: shareLink
|
||||
};
|
||||
}
|
||||
}
|
||||
var arrowRight = document.querySelectorAll("div.video-card-modal > div > img.arrow-right")[0];
|
||||
if (arrowRight.classList.contains("disabled")) {
|
||||
videoArray.push(getCurrentModalVideo());
|
||||
|
||||
var arrowRight = document.querySelectorAll(optStrings.selectors.modalArrowLeft)[0];
|
||||
if (arrowRight.classList.contains(optStrings.classes.modalCloseDisabled)) {
|
||||
window.clearInterval(intervalID);
|
||||
document.querySelector(".video-card-modal > div > div.close").click();
|
||||
finishCallback(videoSet);
|
||||
document.querySelector(optStrings.selectors.modalClose).click();
|
||||
finishCallback(videoArray);
|
||||
} else {
|
||||
arrowRight.click();
|
||||
}
|
||||
}, 500);
|
||||
};
|
||||
|
||||
getCurrentModalVideo = function() {
|
||||
var modalPlayer = document.querySelector(optStrings.selectors.modalPlayer);
|
||||
var vidUrl = modalPlayer.getAttribute(optStrings.attributes.src);
|
||||
var shareLink = document.querySelector(optStrings.selectors.modalShareInput).value;
|
||||
|
||||
return {
|
||||
url: vidUrl,
|
||||
shareLink: shareLink
|
||||
};
|
||||
}
|
||||
|
||||
scrollWhileNew = function(finishCallback) {
|
||||
var state = { count: 0 };
|
||||
var intervalID = window.setInterval(x => {
|
||||
var oldCount = state.count;
|
||||
state.count = document.getElementsByClassName("video-feed-item").length;
|
||||
state.count = document.getElementsByClassName(optStrings.selectors.feedVideoItem).length;
|
||||
if (oldCount !== state.count) {
|
||||
window.scrollTo(0, document.body.scrollHeight);
|
||||
} else {
|
||||
|
@ -52,15 +68,21 @@ scrollWhileNew = function(finishCallback) {
|
|||
}, 1000);
|
||||
};
|
||||
|
||||
bootstrapIteratingVideos = function() {
|
||||
var intervalID = window.setInterval(() => {
|
||||
window.scrollTo(0, document.body.scrollHeight);
|
||||
if (document.getElementsByClassName(optStrings.selectors.feedVideoItem).length > 0) {
|
||||
window.setTimeout(() => buldVidUrlArray(createVidUrlElement), 100);
|
||||
window.clearInterval(intervalID);
|
||||
}
|
||||
}, 500);
|
||||
};
|
||||
|
||||
init = () => {
|
||||
const newProto = navigator.__proto__;
|
||||
delete newProto.webdriver;
|
||||
navigator.__proto__ = newProto;
|
||||
|
||||
window.setTimeout(x => {
|
||||
window.scrollTo(0, document.body.scrollHeight);
|
||||
window.setTimeout(x => buldVidUrlSet(createVidUrlElement), 2000);
|
||||
}, 1000)
|
||||
bootstrapIteratingVideos();
|
||||
};
|
||||
|
||||
init();
|
||||
|
|
Loading…
Reference in New Issue