grenzionky / Copy video URL to Clipboard (press 'v')

// ==UserScript==
// @name         Copy video URL to Clipboard (press 'v')
// @version      1.2
// @description  Copies the URL any video to the clipboard for use in an external video player or to download.
// @author       Abraham Gross
// @include      http*
// @include      https://cdn.testout.com/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @updateURL    https://openuserjs.org/meta/grenzionky/Copy_video_URL_to_Clipboard_(press_v).meta.js
// @grant        GM_setClipboard
// @license      MIT License Copyright (c) 2017 Abraham Gross
// ==/UserScript==

/*
This script copies the URL of any video to the clipboard for use in an external video player or to download.

To copy the videos URL press 'v'.
Since many websites have multiple videos in each page, press 'v' again to cycle to the next video.

------------------------
Does not work in:
YouTube
------------------------

Hope you enjoy!
*/
(function() {
    var i, videos, video, url;
    i = 0;
    document.addEventListener( "keydown", function(press) {
        if (press.keyCode === 86) // if 'v' is pressed
        {
            videos = document.getElementsByTagName('video'); // puts all videos on the page into an array
            video = videos[i].innerHTML === "" ? videos[i].outerHTML : videos[i].innerHTML; // !NOT AN ERROR! determines where to look for the video URL
            url = video.substring(video.indexOf('http'), video.indexOf('"', video.indexOf('http'))); // seperates HTML from URL

            i = i == videos.length-1 ? 0 : ++i;  // cyles to the next video after successive press, or if out of bounds cycles the back to the beginning of the list of urls

            GM_setClipboard(url); // Copies URL to clipboard
            console.log('copied video ' + i + '/' + videos.length-1 + '. URL is: ' + url);
        }
    });
})();