Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DevMensIT/521d1e71e72bb2508e0eaca3f3275d7c to your computer and use it in GitHub Desktop.
Save DevMensIT/521d1e71e72bb2508e0eaca3f3275d7c to your computer and use it in GitHub Desktop.
Userscript to download tiktok videos shown in the browser, for ultimate memeing purposes. :)
// ==UserScript==
// @name Download Tiktok Videos
// @namespace https://tiktok.com/
// @version 0.1
// @description Adds download links for videos, even on private accounts.
// @author Evan Straw
// @include http://*.tiktok.com/*
// @include https://*.tiktok.com/*
// @grant none
// ==/UserScript==
(function() {
setTimeout(addDownloadLinks,100);
})();
function getVideoElements(){
return document.getElementsByTagName("video");
}
function getNumVideos(){
return getVideoElements().length;
}
function isPostPage(){
return window.location.pathname.startsWith("/p/");
}
function makeDLLink(url){
let linkElement = document.createElement("A");
linkElement.href = url;
linkElement.innerText = "Download Video";
linkElement.target = "_blank";
linkElement.style = "padding: 10px;font-size:2em;font-weight:bold;color:red;";
return linkElement;
}
function addDownloadLinks(){
if(getNumVideos() > 0){
let videoElements = getVideoElements();
let video = videoElements[0];
let videoURL = video.src;
let link = makeDLLink(videoURL);
let mainBody = document.getElementById("mainBody");
mainBody.appendChild(link);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment