// ==UserScript==
// @name        T-抖音-复制视频引用
// @namespace   Violentmonkey Scripts
// @match       https://www.douyin.com/video/*
// @grant       none
// @version     1.0
// @author      tianyunperfect
// @require     https://cdn.bootcdn.net/ajax/libs/jquery/3.3.1/jquery.min.js
// @require     https://git.tianyunperfect.cn/tianyunperfect/web-base/raw/master/monkey/util.js?a=2
// @description 2021/1/30 下午7:09:51
// ==/UserScript==
(async () => {
    'use strict';

    let h1_s = '.z8_VexPf';
    await getDom('.xg-video-container video source');

    function getTempId() {
        return "myTmp" + Math.floor(Math.random() * 10000);
    }

    function get_video_id() {
        let source_list = document.querySelector('.xg-video-container video').querySelectorAll('source');
        for (let s of source_list) {
            let src = s.getAttribute("src");
            let video_id = getQueryStringByUrl(src, "video_id");
            if (video_id.length > 0) {
                return video_id;
            }
        }
        console.log("获取 video——id异常")
        return '';
    }

    $(h1_s).dblclick(function () {
        let video_id = get_video_id();
        let url = `https://aweme.snssdk.com/aweme/v1/playwm/?video_id=${video_id}`;
        myCopy(url);
        let tmpId = getTempId();
        $(h1_s).eq(0).append(jQuery('<span class="tag" id="' + tmpId + '">：已复制</span>'));
        setTimeout(() => {
            jQuery('#' + tmpId).remove();
        }, 1500)
    })
})();
