project Websites / videos.bentasker.co.uk avatar

Websites / videos.bentasker.co.uk: e97ad986




Split embedBensPlayer() so that all it does directly is use document.write(). This is a precursor to adding a new entrypoint for websites/videos.bentasker.co.uk#3

Split embedBensPlayer() so that all it does directly is use document.write(). This is a precursor to adding a new entrypoint for websites/videos.bentasker.co.uk#3

Commit e97ad986.

Authored 2022-03-11T16:03:27.000+00:00 by B Tasker in project Websites / videos.bentasker.co.uk

+28 lines -11 lines

Commit Signature

Changes

diff --git a/resources/embed/embed.js b/resources/embed/embed.js
--- a/resources/embed/embed.js
+++ b/resources/embed/embed.js
# @@ -110,7 +110,8 @@ function guessMimeFromUrl(vidurl){
# }
#
#
# -function embedBensPlayer(vidurl,vidtype){
# +/* Calculate variables to set on the video */
# +function prepareVars(vidurl){
#
# // What's the TLD we're embedded into?
# if (window.location.hostname.split('.').pop().toLowerCase() == "onion"){
# @@ -120,12 +121,11 @@ function embedBensPlayer(vidurl,vidtype){
# window.BensPlayerDomain = window.BensPlayerDomainTor;
# }
#
# - //if (vidtype == undefined){
# - vidtype=guessMimeFromUrl(vidurl);
# - //}
# -
# + // Get the mime-type
# + vidtype = guessMimeFromUrl(vidurl);
# +
# + // Calculate the ID for this player instance
# var vidid = 0;
# -
# while (true){
# if (window.BensPlayerInstances.includes(vidid)){
# vidid++;
# @@ -133,8 +133,10 @@ function embedBensPlayer(vidurl,vidtype){
# window.BensPlayerInstances.push(vidid);
# break;
# }
# - }
# + }
#
# + // Prepend the playback domain
# + //
# // We do this for 2 reasons
# //
# // * 1 saves pasting the full URL into the function call
# @@ -144,20 +146,35 @@ function embedBensPlayer(vidurl,vidtype){
# vidurl = window.BensPD + vidurl;
# }
#
# + // Return the vars
# + return [vidtype, vidid, vidurl];
# +}
# +
# +/* Legacy embed */
# +function embedBensPlayer(vidurl,vidtype){
# +
# + ret = prepareVars(vidurl);
# + vidtype = ret[0]
# + vidid = ret[1]
# + vidurl = ret[2]
# +
# document.write("<div id='BensplayerWrapper" + vidid + "' class='BensVideoCont'></div>");
# - var c = document.getElementById('BensplayerWrapper'+vidid);
# + setupPlayer(vidtype, vidurl, vidid);
# +}
# +
# +/* Add stylesheet before triggering the embed flow */
# +function setupPlayer(vidtype, vidurl, vidid){
#
# - // First thing we need to do is get the player files loaded
# + var c = document.getElementById('BensplayerWrapper'+vidid);
#
# + // First thing we need to do is get the player files loaded
# var e = cE('link');
# e.setAttribute('rel','stylesheet');
# e.setAttribute('href',window.BensPD + 'resources/js/videojs/video-js.min.css');
# c.appendChild(e);
#
# -
# playerSettings = { 'vidtype': vidtype, 'vidurl': vidurl, 'vidid': vidid}
#
# -
# // We then trigger the next steps in stages to make sure everything that needs to be loaded, is
# getBensToken(vidid,playerSettings);
# }
#