Skip to content

Instantly share code, notes, and snippets.

@monokaijs
Last active January 6, 2024 04:29
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save monokaijs/b57845c22667a6594707f10a753d4bce to your computer and use it in GitHub Desktop.
Save monokaijs/b57845c22667a6594707f10a753d4bce to your computer and use it in GitHub Desktop.
Download Video Tiktok

Hướng dẫn

Vào một trang video Tiktok bất kỳ, copy đoạn code phía dưới, quay lại trang xem video Tiktok rồi nhấn Ctrl + Shift + I (hoặc Command + Shift + I trên Macbook). Sau đó qua tab console, paste đoạn code vào rồi nhấn Enter, chờ tí tẹo Video sẽ bắt đầu tải.

(function () {
  const videoEl = document.querySelector('video');
  function downloadVideo(url) {
    fetch(url).then(response => {
      if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
      return response.blob();
    }).then(blob => {
      const link = document.createElement("a");
      link.href = URL.createObjectURL(blob);
      link.download = "video.mp4";
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    }).catch(error => {
      alert("Có lỗi trong quá trình tải video.");
    });
  }
  if (!videoEl) {
    alert("Không tìm thấy video, bạn đã mở trang video chưa?");
  } else {
    const videoSrc = videoEl.src;
    if (videoSrc || videoSrc.includes('.tiktok.com/video/tos/alisg/')) {
      downloadVideo(videoSrc);
    } else alert("Video không hợp lệ");
  }
})();

Nếu bạn dùng thường xuyên, có thể dùng cách này

Đây là cách tạo bookmark, trước tiên nhấn Ctrl + Shift + B hoặc Command + Shift + B. Thanh bookmark sẽ hiện ra. Tiếp theo bạn chuột phải vào thanh Bookmark và nhấn chọn Tạo bookmark mới (Add Page / Thêm Trang).

Sau đó dán đoạn code bên dưới vào ô URL:

javascript:!function(){let e=document.querySelector("video");if(e){let t=e.src;t||t.includes(".tiktok.com/video/tos/alisg/")?function e(t){fetch(t).then(e=>{if(!e.ok)throw Error(`HTTP error! Status: ${e.status}`);return e.blob()}).then(e=>{let t=document.createElement("a");t.href=URL.createObjectURL(e),t.download="video.mp4",document.body.appendChild(t),t.click(),document.body.removeChild(t)}).catch(e=>{alert("C\xf3 lỗi trong qu\xe1 tr\xecnh tải video.")})}(t):alert("Video kh\xf4ng hợp lệ")}else alert("Kh\xf4ng t\xecm thấy video, bạn đ\xe3 mở trang video chưa?")}();

Đặt tên tuỳ ý rồi lưu lại. Từ giờ mỗi khi lướt Tiktok trên PC, chỉ cần nhấn vào cái bookmark mới tạo ra, video sẽ được tải về.

Chúc các bạn vui vẻ :")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment