Greasy Fork is available in English.

PureFetch 抖音网页版一键无水印下载

内嵌下载按钮,轻松下载无水印视频。

// ==UserScript==
// @name         PureFetch 抖音网页版一键无水印下载
// @namespace    https://j8.gs/
// @version      1.0.0
// @description  内嵌下载按钮,轻松下载无水印视频。
// @author       Go3p
// @license      MIT
// @match        *://www.douyin.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
	'use strict';

	// 创建按钮元素
	var floatingButton = document.createElement('button');
	floatingButton.innerHTML = '无水印下载当前视频';

	// 设置按钮样式
	floatingButton.style.position = 'fixed';
	floatingButton.style.top = '1rem';
	floatingButton.style.left = '8rem';
	floatingButton.style.padding = '10px';
	floatingButton.style.backgroundColor = '#fe2c55';
	floatingButton.style.color = 'white';
	floatingButton.style.border = 'none';
	floatingButton.style.borderRadius = '5px';
	floatingButton.style.cursor = 'pointer';
	floatingButton.style.zIndex = '9999';
	floatingButton.addEventListener('click', function() {
		floatingButton.innerHTML = '解析中...';
		floatingButton.disabled = true;

		var vid = null;
		var video = document.querySelector('div[data-e2e="feed-active-video"]') ||
			document.querySelector('video[mediatype="video"]');
		if (video) {
			vid = video.getAttribute('data-e2e-vid');
			if (vid) {
				pure(vid, null);
				return;
			}
		}

		var documentString = new XMLSerializer().serializeToString(video);
		var matchResult = documentString.match(/video_id=([^&]*)&/);
		var uri = matchResult ? matchResult[1] : null;
		if (uri) {
			pure(null, uri);
			return;
		}
	});
	document.body.appendChild(floatingButton);

	function pure(vid, uri) {
		var url = 'https://ci.ak47.ink/Shorts/'
		if (vid) {
			url = url + 'pure?url=https://www.douyin.com/video/' + vid;
		} else if (uri) {
			url = url + 'getDyNWVUrlWithUri/' + uri;
		}
		fetch(url)
			.then(response => {
				if (!response.ok) {
					throw new Error('Network response was not ok');
				}
				return response.json();
			})
			.then(data => {
				floatingButton.innerHTML = '无水印下载当前视频';
				floatingButton.disabled = false;
				if (data.code == 200) {
					window.open(data.url);
				}
			})
			.catch(error => {
				floatingButton.innerHTML = '解析中...';
				floatingButton.disabled = false;
				alert('获取无水印地址失败了=-=');
			});
	}
})();