Tumblr get video source

Gets the video source url for the first video on a tumblr post and puts it in the clipboard for easy downloading.

当前为 2018-02-01 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Tumblr get video source
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Gets the video source url for the first video on a tumblr post and puts it in the clipboard for easy downloading.
// @author       You
// @match        https://*.tumblr.com/post/*
// @match        https://www.tumblr.com/video/*
// @grant        GM_setClipboard
// @grant        GM_registerMenuCommand
// @run-at       document-idle
// ==/UserScript==

if(window.top !== window.self) {
  const videoSourceElem = document.querySelector('video source');
  if(!videoSourceElem){
    return;
  }
  window.top.postMessage({
    iframeVideoUrl: window.location.href,
    iframeVideoSrc: videoSourceElem.src
  }, "*")
  return
}


const parentPostID = window.location.href.split('/')[4]
let iframeVideoSrc = ''

window.addEventListener('message', function(event) {
  if(!event.data.iframeVideoUrl || !event.data.iframeVideoSrc) {
    return
  }
  const iframeVideoID = event.data.iframeVideoUrl.split('/')[5]

 if(parentPostID === iframeVideoID){
    iframeVideoSrc = event.data.iframeVideoSrc
    if(iframeVideoSrc.endsWith('/480')){
      iframeVideoSrc = iframeVideoSrc.slice(0, -3)
    }
    console.log(iframeVideoSrc)
  }
}, false)

function getVideoUrl(){
  GM_setClipboard(iframeVideoSrc)
}

GM_registerMenuCommand('Get Video Url (clipboard)', getVideoUrl)