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) {
|
optStrings = {
|
||||||
var videoArray = Object.entries(videoSet).map(x => {
|
selectors: {
|
||||||
return {
|
feedVideoItem: 'video-feed-item-wrapper',
|
||||||
shareLink: x[1].shareLink,
|
modalArrowLeft: 'div.video-card-modal > div > img.arrow-right',
|
||||||
url: x[0],
|
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);
|
urlSetElement.innerText = JSON.stringify(videoArray);
|
||||||
document.getElementsByTagName("body")[0].appendChild(urlSetElement);
|
document.getElementsByTagName(optStrings.tags.resultParentTag)[0].appendChild(urlSetElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
buldVidUrlSet = function(finishCallback) {
|
buldVidUrlArray = function(finishCallback) {
|
||||||
var feedItem = document.getElementsByClassName("video-feed-item-wrapper")[0];
|
var feedItem = document.getElementsByClassName(optStrings.selectors.feedVideoItem)[0];
|
||||||
feedItem.click();
|
feedItem.click();
|
||||||
|
|
||||||
var videoSet = {};
|
var videoArray = [];
|
||||||
var intervalID = window.setInterval(x => {
|
var intervalID = window.setInterval(x => {
|
||||||
var players = document.getElementsByClassName("video-player");
|
videoArray.push(getCurrentModalVideo());
|
||||||
for (var i = 0; i < players.length; i++) {
|
|
||||||
var vidUrl = players[i].getAttribute("src");
|
var arrowRight = document.querySelectorAll(optStrings.selectors.modalArrowLeft)[0];
|
||||||
if(!videoSet[vidUrl]) {
|
if (arrowRight.classList.contains(optStrings.classes.modalCloseDisabled)) {
|
||||||
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")) {
|
|
||||||
window.clearInterval(intervalID);
|
window.clearInterval(intervalID);
|
||||||
document.querySelector(".video-card-modal > div > div.close").click();
|
document.querySelector(optStrings.selectors.modalClose).click();
|
||||||
finishCallback(videoSet);
|
finishCallback(videoArray);
|
||||||
} else {
|
} else {
|
||||||
arrowRight.click();
|
arrowRight.click();
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 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) {
|
scrollWhileNew = function(finishCallback) {
|
||||||
var state = { count: 0 };
|
var state = { count: 0 };
|
||||||
var intervalID = window.setInterval(x => {
|
var intervalID = window.setInterval(x => {
|
||||||
var oldCount = state.count;
|
var oldCount = state.count;
|
||||||
state.count = document.getElementsByClassName("video-feed-item").length;
|
state.count = document.getElementsByClassName(optStrings.selectors.feedVideoItem).length;
|
||||||
if (oldCount !== state.count) {
|
if (oldCount !== state.count) {
|
||||||
window.scrollTo(0, document.body.scrollHeight);
|
window.scrollTo(0, document.body.scrollHeight);
|
||||||
} else {
|
} else {
|
||||||
|
@ -52,15 +68,21 @@ scrollWhileNew = function(finishCallback) {
|
||||||
}, 1000);
|
}, 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 = () => {
|
init = () => {
|
||||||
const newProto = navigator.__proto__;
|
const newProto = navigator.__proto__;
|
||||||
delete newProto.webdriver;
|
delete newProto.webdriver;
|
||||||
navigator.__proto__ = newProto;
|
navigator.__proto__ = newProto;
|
||||||
|
bootstrapIteratingVideos();
|
||||||
window.setTimeout(x => {
|
|
||||||
window.scrollTo(0, document.body.scrollHeight);
|
|
||||||
window.setTimeout(x => buldVidUrlSet(createVidUrlElement), 2000);
|
|
||||||
}, 1000)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
Loading…
Reference in New Issue