2020-01-19 15:16:46 +02:00
|
|
|
optStrings = {
|
|
|
|
selectors: {
|
2020-08-16 01:30:48 +03:00
|
|
|
feedLoading: '.tiktok-ui-loading-container',
|
|
|
|
modalArrowRight: 'div > div.video-card-container > img.arrow-right',
|
|
|
|
modalClose: 'div > div.video-card-container > img.control-icon.close',
|
|
|
|
modalPlayer: 'div.video-card-container > div.video-card-browse > video',
|
|
|
|
modalCaption: 'div.content-container > div.video-infos-container > h1',
|
|
|
|
modalSoundLink: 'div.content-container > div.video-infos-container > h2.music-info > a',
|
2020-01-26 19:44:25 +02:00
|
|
|
modalUploader: '.user-username',
|
2020-08-16 01:30:48 +03:00
|
|
|
videoPlayer: 'div.video-card-container > div > video',
|
|
|
|
videoCaption: 'div.content-container > div.video-infos-container > h1',
|
|
|
|
videoSoundLink: 'div.content-container > div.video-infos-container > h2 > a',
|
2020-01-26 19:44:25 +02:00
|
|
|
videoUploader: '.user-username',
|
2020-01-19 15:16:46 +02:00
|
|
|
},
|
|
|
|
classes: {
|
2020-01-19 21:15:42 +02:00
|
|
|
feedVideoItem: 'video-feed-item-wrapper',
|
2020-01-19 15:16:46 +02:00
|
|
|
modalCloseDisabled: 'disabled',
|
2020-02-25 20:12:01 +02:00
|
|
|
titleMessage: 'title',
|
2020-01-19 15:16:46 +02:00
|
|
|
},
|
|
|
|
tags: {
|
|
|
|
resultTag: 'video_urls',
|
|
|
|
resultParentTag: 'body',
|
|
|
|
},
|
|
|
|
attributes: {
|
|
|
|
src: "src",
|
|
|
|
},
|
2020-02-25 20:12:01 +02:00
|
|
|
tiktokMessages: [
|
|
|
|
"Couldn't find this account",
|
|
|
|
"No videos yet",
|
|
|
|
"Video currently unavailable",
|
|
|
|
],
|
2020-01-19 15:16:46 +02:00
|
|
|
};
|
2020-01-19 04:11:53 +02:00
|
|
|
|
2020-02-08 01:51:17 +02:00
|
|
|
currentState = {
|
|
|
|
preloadCount: 0,
|
|
|
|
finished: false,
|
2020-02-25 20:55:56 +02:00
|
|
|
limit: 0
|
2020-02-08 01:51:17 +02:00
|
|
|
};
|
|
|
|
|
2020-08-16 01:30:48 +03:00
|
|
|
checkForErrors = function () {
|
2020-02-25 20:12:01 +02:00
|
|
|
var titles = document.getElementsByClassName(optStrings.classes.titleMessage);
|
2020-08-16 01:30:48 +03:00
|
|
|
//debugger;
|
2020-02-25 20:12:01 +02:00
|
|
|
if (titles && titles.length) {
|
|
|
|
var error = Array.from(titles).find(x => optStrings.tiktokMessages.includes(x.textContent)).textContent;
|
|
|
|
if (error) {
|
|
|
|
createVidUrlElement("ERR: " + error);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2020-08-16 01:30:48 +03:00
|
|
|
createVidUrlElement = function (outputObj) {
|
2020-01-19 15:16:46 +02:00
|
|
|
var urlSetElement = document.createElement(optStrings.tags.resultTag);
|
2020-01-19 17:54:16 +02:00
|
|
|
urlSetElement.innerText = JSON.stringify(outputObj);
|
2020-01-19 15:16:46 +02:00
|
|
|
document.getElementsByTagName(optStrings.tags.resultParentTag)[0].appendChild(urlSetElement);
|
2020-02-08 01:51:17 +02:00
|
|
|
currentState.finished = true;
|
2020-02-25 00:56:19 +02:00
|
|
|
};
|
2020-01-19 04:11:53 +02:00
|
|
|
|
2020-08-16 01:30:48 +03:00
|
|
|
buldVidUrlArray = function (finishCallback) {
|
2020-01-19 21:15:42 +02:00
|
|
|
var feedItem = document.getElementsByClassName(optStrings.classes.feedVideoItem)[0];
|
2020-01-19 04:11:53 +02:00
|
|
|
feedItem.click();
|
|
|
|
|
2020-01-19 15:16:46 +02:00
|
|
|
var videoArray = [];
|
2020-01-19 04:11:53 +02:00
|
|
|
var intervalID = window.setInterval(x => {
|
2020-01-19 15:16:46 +02:00
|
|
|
videoArray.push(getCurrentModalVideo());
|
2020-08-16 01:30:48 +03:00
|
|
|
if (currentState.limit > 0) {
|
2020-02-25 00:56:19 +02:00
|
|
|
if (videoArray.length >= currentState.limit) {
|
|
|
|
window.clearInterval(intervalID);
|
|
|
|
document.querySelector(optStrings.selectors.modalClose).click();
|
|
|
|
finishCallback(videoArray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var arrowRight = document.querySelectorAll(optStrings.selectors.modalArrowRight)[0];
|
2020-08-16 01:30:48 +03:00
|
|
|
if (!arrowRight || arrowRight.classList.contains(optStrings.classes.modalCloseDisabled)) {
|
2020-01-19 04:11:53 +02:00
|
|
|
window.clearInterval(intervalID);
|
2020-01-19 15:16:46 +02:00
|
|
|
document.querySelector(optStrings.selectors.modalClose).click();
|
|
|
|
finishCallback(videoArray);
|
2020-01-19 04:11:53 +02:00
|
|
|
} else {
|
|
|
|
arrowRight.click();
|
|
|
|
}
|
2020-01-19 21:15:42 +02:00
|
|
|
}, 20);
|
2020-01-19 04:11:53 +02:00
|
|
|
};
|
|
|
|
|
2020-08-16 01:30:48 +03:00
|
|
|
getCurrentModalVideo = function () {
|
2020-01-19 15:16:46 +02:00
|
|
|
var modalPlayer = document.querySelector(optStrings.selectors.modalPlayer);
|
|
|
|
var vidUrl = modalPlayer.getAttribute(optStrings.attributes.src);
|
2020-08-16 01:30:48 +03:00
|
|
|
var shareLink = window.location.href;
|
2020-01-20 19:42:34 +02:00
|
|
|
var caption = document.querySelector(optStrings.selectors.modalCaption).textContent;
|
|
|
|
var soundLink = document.querySelector(optStrings.selectors.modalSoundLink);
|
2020-01-26 19:44:25 +02:00
|
|
|
var uploader = document.querySelector(optStrings.selectors.modalUploader).textContent;
|
2020-08-16 01:30:48 +03:00
|
|
|
var soundHref = soundLink ? soundLink.getAttribute("href") : '';
|
|
|
|
var soundText = soundLink ? soundLink.text : '';
|
2020-01-19 15:16:46 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
url: vidUrl,
|
2020-01-20 19:42:34 +02:00
|
|
|
shareLink: shareLink,
|
|
|
|
caption: caption,
|
2020-01-26 19:44:25 +02:00
|
|
|
uploader: uploader,
|
2020-01-20 19:42:34 +02:00
|
|
|
sound: {
|
|
|
|
title: soundText,
|
|
|
|
link: soundHref,
|
|
|
|
},
|
2020-01-19 15:16:46 +02:00
|
|
|
};
|
2020-02-25 00:56:19 +02:00
|
|
|
};
|
2020-01-19 15:16:46 +02:00
|
|
|
|
2020-08-16 01:30:48 +03:00
|
|
|
getCurrentVideo = function () {
|
|
|
|
//debugger;
|
|
|
|
if (checkForErrors()) return;
|
2020-01-19 17:54:16 +02:00
|
|
|
var player = document.querySelector(optStrings.selectors.videoPlayer);
|
|
|
|
var vidUrl = player.getAttribute(optStrings.attributes.src);
|
2020-08-16 01:30:48 +03:00
|
|
|
var shareLink = window.location.href;
|
2020-01-20 19:42:34 +02:00
|
|
|
var caption = document.querySelector(optStrings.selectors.videoCaption).textContent;
|
|
|
|
var soundLink = document.querySelector(optStrings.selectors.videoSoundLink);
|
2020-01-26 19:44:25 +02:00
|
|
|
var uploader = document.querySelector(optStrings.selectors.videoUploader).textContent;
|
2020-08-16 01:30:48 +03:00
|
|
|
var soundHref = soundLink ? soundLink.getAttribute("href") : '';
|
|
|
|
var soundText = soundLink ? soundLink.text : '';
|
2020-01-19 17:54:16 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
url: vidUrl,
|
2020-01-20 19:42:34 +02:00
|
|
|
shareLink: shareLink,
|
|
|
|
caption: caption,
|
2020-01-26 19:44:25 +02:00
|
|
|
uploader: uploader,
|
2020-01-20 19:42:34 +02:00
|
|
|
sound: {
|
|
|
|
title: soundText,
|
|
|
|
link: soundHref,
|
|
|
|
},
|
2020-01-19 17:54:16 +02:00
|
|
|
};
|
2020-02-25 00:56:19 +02:00
|
|
|
};
|
2020-01-19 17:54:16 +02:00
|
|
|
|
2020-04-08 23:26:50 +03:00
|
|
|
scrollBottom = () => window.scrollTo(0, document.body.scrollHeight);
|
|
|
|
|
2020-08-16 01:30:48 +03:00
|
|
|
scrollWhileNew = function (finishCallback) {
|
|
|
|
var state = {
|
|
|
|
count: 0
|
|
|
|
};
|
2020-01-19 04:11:53 +02:00
|
|
|
var intervalID = window.setInterval(x => {
|
2020-04-08 23:26:50 +03:00
|
|
|
scrollBottom();
|
2020-01-19 04:11:53 +02:00
|
|
|
var oldCount = state.count;
|
2020-01-19 21:15:42 +02:00
|
|
|
state.count = document.getElementsByClassName(optStrings.classes.feedVideoItem).length;
|
2020-08-16 01:30:48 +03:00
|
|
|
if (currentState.limit > 0) {
|
2020-02-25 00:56:19 +02:00
|
|
|
if (currentState.preloadCount >= currentState.limit || state.count >= currentState.limit) {
|
|
|
|
finishCallback(createVidUrlElement);
|
|
|
|
window.clearInterval(intervalID);
|
|
|
|
}
|
|
|
|
}
|
2020-08-16 01:30:48 +03:00
|
|
|
if (checkForErrors()) {
|
2020-02-25 20:12:01 +02:00
|
|
|
window.clearInterval(intervalID);
|
|
|
|
return;
|
2020-04-08 23:26:50 +03:00
|
|
|
} else if (state.count == 0) {
|
|
|
|
return;
|
2020-02-25 20:12:01 +02:00
|
|
|
}
|
2020-01-19 04:11:53 +02:00
|
|
|
if (oldCount !== state.count) {
|
2020-02-08 01:51:17 +02:00
|
|
|
currentState.preloadCount = state.count;
|
2020-01-19 04:11:53 +02:00
|
|
|
} else {
|
2020-08-16 01:30:48 +03:00
|
|
|
if (isLoading()) {
|
2020-01-19 21:15:42 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-01-19 04:11:53 +02:00
|
|
|
window.clearInterval(intervalID);
|
2020-01-19 21:15:42 +02:00
|
|
|
finishCallback(createVidUrlElement);
|
2020-01-19 04:11:53 +02:00
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
};
|
|
|
|
|
2020-08-16 01:30:48 +03:00
|
|
|
isLoading = function () {
|
|
|
|
var loadingElement = document.querySelector(optStrings.selectors.feedLoading);
|
|
|
|
return loadingElement && loadingElement.getClientRects().length != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bootstrapIteratingVideos = function (limit) {
|
2020-02-25 00:56:19 +02:00
|
|
|
currentState.limit = limit;
|
2020-01-19 21:15:42 +02:00
|
|
|
scrollWhileNew(buldVidUrlArray);
|
2020-01-19 17:54:16 +02:00
|
|
|
return 'bootstrapIteratingVideos';
|
2020-01-19 15:16:46 +02:00
|
|
|
};
|
|
|
|
|
2020-08-16 01:30:48 +03:00
|
|
|
bootstrapGetCurrentVideo = function () {
|
2020-01-19 17:54:16 +02:00
|
|
|
var video = getCurrentVideo();
|
|
|
|
createVidUrlElement(video);
|
|
|
|
return 'bootstrapGetCurrentVideo';
|
2020-02-25 00:56:19 +02:00
|
|
|
};
|
2020-01-19 17:54:16 +02:00
|
|
|
|
2020-01-19 04:11:53 +02:00
|
|
|
init = () => {
|
|
|
|
const newProto = navigator.__proto__;
|
|
|
|
delete newProto.webdriver;
|
|
|
|
navigator.__proto__ = newProto;
|
2020-01-19 21:15:42 +02:00
|
|
|
return 'script initialized';
|
2020-01-19 04:11:53 +02:00
|
|
|
};
|
|
|
|
|
2020-01-19 21:15:42 +02:00
|
|
|
init();
|