Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Tiktok-Downloader
- // @version 1.0.2
- // @description tiktok.com Video Downloader
- // @match https://www.tiktok.com/*
- // @match https://tiktok.com/*
- // @grant GM_download
- // @grant GM_addStyle
- // @grant GM_xmlhttpRequest
- // @connect tiktok.com
- // @connect api-t2.tiktokv.com
- // @icon https://s16.tiktokcdn.com/musical/resource/wap/static/image/logo_144c91a.png?v=2
- // @original https://greasyfork.org/users/209098
- // @license MIT
- // ==/UserScript==
- (function () {
- 'use strict'
- GM_addStyle(
- "#anastasia-i-love-u { position: absolute; top: 20px; left: 20px; z-index: 9001; width: 48px; height: 48px; opacity: 0.95; font-size: 15px; line-height: 50%; border: none; " +
- "background: #545454; color: #FFF; cursor: pointer; border-radius: 100%; transition: opacity 0.4s; } #anastasia-i-love-u:disabled { opacity: 0.01; background-color: #c0392b; } " +
- ".vid_height_add { top: 78px !important; width: 40px !important; height: 40px !important;}"
- );
- GM_addStyle(".logo { display: none !important; } .mute-icon { opacity: 1 !important; } ");
- /*///////////////////////////////////
- WORKING AS OF 07/02/2021
- /*///////////////////////////////////
- function generateBase62(length) {
- var i = 0, r = "", base62 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- while (i < length) {
- r += base62.charAt(Math.floor(Math.random() * 62));
- i++;
- }
- return r;
- }
- function generateDeviceId() {
- var i = 1, a = new Array(19); //Math.floor(Math.random() * 9) + 11
- a[0] = 54; //Math.floor(Math.random() * 9) + 49
- while (i < a.length) {
- a[i++] = Math.floor(Math.random() * 10) + 48;
- }
- return String.fromCharCode.apply(null, a);
- }
- function getAPIData(ID) {
- const d = new Date();
- const t = d.getTime() - d.getTimezoneOffset() * 60000;
- const deviceVersion = generateBase62(8);
- const deviceId = generateDeviceId();
- const iId = generateDeviceId();
- const url = "https://api-t2.tiktokv.com/aweme/v1/multi/aweme/detail/?aweme_ids="
- + "[" + ID + "]"
- + "®ion=US"
- + "&ts=" + Math.floor(t / 1000)
- + "&timezone_name=Etc%2FGMT"
- + "&device_type=Pixel%20" + deviceVersion
- + "&iid=" + iId
- + "&locale=en"
- + "&app_type=normal"
- + "&resolution=1080*1920"
- + "&aid=1180"
- + "&app_name=musical_ly"
- + "&_rticket=" + t
- + "&device_platform=android"
- + "&version_code=100000"
- + "&dpi=441"
- + "&cpu_support64=false"
- + "&sys_region=US"
- + "&timezone_offset=0"
- + "&device_id=" + deviceId
- + "&pass-route=1"
- + "&device_brand=google"
- + "&os_version=8.0.0"
- + "&op_region=US"
- + "&app_language=en"
- + "&pass-region=1"
- + "&language=en"
- + "&channel=googleplay"
- console.log(url);
- GM_xmlhttpRequest({
- method: "GET",
- url: url,
- headers: {
- "User-Agent": "okhttp"
- },
- onload: downloadLink
- });
- }
- function downloadLink(dat) {
- const downloadBtn = document.getElementById('anastasia-i-love-u');
- if (!downloadBtn) return;
- try {
- dat = JSON.parse(dat.responseText);
- const ID = dat.aweme_details[0].aweme_id
- dat = dat.aweme_details[0].video.play_addr.url_list
- dat = dat[dat.length - 1]
- .replace("improve_bitrate=0", "improve_bitrate=1")
- .replace(/ratio=\d+p/i, "ratio=default");
- const fileName = `${ID}.mp4`;
- GM_download({
- url: dat,
- name: fileName,
- headers: {
- "User-Agent": "okhttp"
- },
- onload: setTimeout(() => { downloadBtn.disabled = !1; }, 2000)
- });
- }
- catch(e) { console.log(e); return; }
- }
- function addDownloadButton(videoCardTag) {
- if (document.getElementById('anastasia-i-love-u')) return;
- const downloadBtn = document.createElement('button');
- downloadBtn.innerHTML = '▼';
- downloadBtn.id = 'anastasia-i-love-u';
- if (document.querySelector(".trending-title")) {
- downloadBtn.classList.add('vid_height_add');
- }
- downloadBtn.onclick = () => {
- downloadBtn.disabled = !0;
- const vidId = document.location.href.match(/video\/(6\d+)/i)[1];
- getAPIData(vidId);
- }
- videoCardTag
- .parentNode
- .appendChild(downloadBtn);
- }
- const bodyObserver = new MutationObserver(() => {
- const card = document.querySelector('.video-card-browse > video');
- card && addDownloadButton(card);
- });
- bodyObserver.observe(document.body, {
- childList: !0,
- subtree: !0,
- attributes: !1
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement