From 110d41e393110cec1721e03858a19f38bdeba4af Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Tue, 17 Oct 2017 13:16:19 +0200
Subject: [PATCH] Add function to trigger video playback for plugins

---
 Resources/Scripts/code.js            | 8 ++++----
 Resources/Scripts/plugins.browser.js | 9 +++++++--
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/Resources/Scripts/code.js b/Resources/Scripts/code.js
index 80d38719..d3a19753 100644
--- a/Resources/Scripts/code.js
+++ b/Resources/Scripts/code.js
@@ -928,9 +928,9 @@
   // Block: Setup video player hooks.
   //
   (function(){
-    var playVideo = function(url){
+    window.TDGF_playVideo = function(url){
       $('<div id="td-video-player-overlay" class="ovl" style="display:block"></div>').on("click contextmenu", function(){
-        $TD.playVideo(null);
+        $TD.playVideo(null, null);
       }).appendTo(app);
       
       $TD.playVideo(url);
@@ -947,7 +947,7 @@
         let src = !e.ctrlKey && $(this).closest(".js-media-gif-container").find("video").attr("src");
         
         if (src){
-          playVideo(src);
+          window.TDGF_playVideo(src);
         }
         else{
           $TD.openBrowser(getVideoTweetLink($(this)));
@@ -983,7 +983,7 @@
       let media = this.chirp.getMedia().find(media => media.mediaId === this.clickedMediaEntityId);
 
       if (media && media.isVideo && media.service === "twitter"){
-        playVideo(media.chooseVideoVariant().url);
+        window.TDGF_playVideo(media.chooseVideoVariant().url);
         cancelModal = true;
       }
     });
diff --git a/Resources/Scripts/plugins.browser.js b/Resources/Scripts/plugins.browser.js
index 05cce5d7..704ccf86 100644
--- a/Resources/Scripts/plugins.browser.js
+++ b/Resources/Scripts/plugins.browser.js
@@ -87,14 +87,14 @@
   };
   
   //
-  // Block: Setup global function to change plugin state.
+  // Block: Setup a function to change plugin state.
   //
   window.TDPF_setPluginState = function(identifier, enable){
     window.TD_PLUGINS.setState(window.TD_PLUGINS.findObject(identifier), enable);
   };
   
   //
-  // Block: Setup global function to reload the page.
+  // Block: Setup a function to reload the page.
   //
   window.TDPF_requestReload = function(){
     if (!isReloading){
@@ -102,4 +102,9 @@
       isReloading = true;
     }
   };
+  
+  //
+  // Block: Setup a function to allow plugins to play video.
+  //
+  window.TDPF_playVideo = window.TDGF_playVideo;
 })();