Skip to content

Instantly share code, notes, and snippets.

@lovmoon3k
Forked from monokaijs/Download Tiktok Videos.md
Created January 2, 2024 14:24
Show Gist options
  • Select an option

  • Save lovmoon3k/2d8b2777dd04f4362d721cf4a053a7eb to your computer and use it in GitHub Desktop.

Select an option

Save lovmoon3k/2d8b2777dd04f4362d721cf4a053a7eb to your computer and use it in GitHub Desktop.

Revisions

  1. @monokaijs monokaijs created this gist Jan 2, 2024.
    47 changes: 47 additions & 0 deletions Download Tiktok Videos.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    ### 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.

    ```js
    (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);
    URL.revokeObjectURL(blobUrl);
    }).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*:
    ```js
    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),URL.revokeObjectURL(blobUrl)}).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ẻ :")