Greasy Fork

Greasy Fork is available in English.

Twitter Video Download

Adds a button to download video from a tweet

当前为 2022-07-15 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Twitter Video Download
// @namespace    http://tampermonkey.net/
// @version      1.0.5
// @description  Adds a button to download video from a tweet
// @run-at       document-idle
// @author       naileD
// @include      https://twitter.com/*
// @include      https://mobile.twitter.com/*
// @icon         https://www.google.com/s2/favicons?domain=twitter.com
// @grant        none
// @license      Unlicense
// ==/UserScript==

'use strict';
setInterval(() => {
  var main = document.querySelector("main[role='main'] section[role='region']");
  if (!main) return;
  var react = Object.entries(main.parentElement).find(el => el[0].startsWith("__reactFiber"))[1];
  if (!react.memoizedProps.children.length) return;
  var tweet = react.memoizedProps.children.filter(el => (el || {})._owner).map(el => el._owner.memoizedProps.focalTweet).filter(el => el)[0];
  if (!tweet || !tweet.extended_entities || !tweet.extended_entities.media || !tweet.extended_entities.media[0].video_info) return;
  var el = document.querySelector(`a[href*="${tweet.id_str}"]`);
  if (!el) return;
  while (el.tagName !== "ARTICLE") { el = el.parentElement; }
  el = el.querySelector(`[id^="id"][role="group"]`);
  if (!el) return;
  if (el.lastElementChild.tagName === "A") return;
  var video = tweet.extended_entities.media[0].video_info.variants.filter(v => v.content_type == "video/mp4").sort((a,b) => b.bitrate - a.bitrate)[0].url.replace(new RegExp("\\?tag=.*"), "");
  var color = el.firstElementChild.style.color || "#536471";
  var svg = `<svg width="1.5em" height="1.5em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="square" stroke-linejoin="arcs">
          <g><path d="M18 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8c0-1.1.9-2 2-2h5M15 3h6v6M10 14L20.2 3.8"/></g></svg>`;
  el.insertAdjacentHTML("beforeend", `<a href="${video}" target="_blank" style="display: flex; place-self: center;  color: ${color};" title="Download Video">${svg}</a>`);
}, 1000);