Direct Links to Twitter Media Embeds

Generates a small link directly to the source of Twitter media embeds (Youtube, Twitch clips, etc.)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Direct Links to Twitter Media Embeds
// @namespace    http://bifrost.me
// @version      1.0
// @description  Generates a small link directly to the source of Twitter media embeds (Youtube, Twitch clips, etc.)
// @match        https://twitter.com/*
// @grant        none
// @require		 https://code.jquery.com/jquery-1.12.4.min.js
// ==/UserScript==

var documentHeight = '';

// Monitor the height of the window to detect when new tweets have been dynamically loaded
function heightWatcher() {
    if (documentHeight != document.body.scrollHeight) {
        addLinks();
    }
    documentHeight = document.body.scrollHeight;
    setTimeout(function(){heightWatcher();}, 3000);
};

function addLinks() {
    $('div.card-type-player').each(function() {
        if ($(this).attr('link-added')) {
            return;
        }
        const src = $(this).attr('data-card-url');
        $(this).before('<a href=\"' + src + '\">→</a>');
        $(this).attr('link-added', true)
    });
};

(function() {
    'use strict';

    heightWatcher();
})();