PageSourceSearch

https://www.zoloft.com/-/media/Base-Themes/Core-Libraries/scripts/twitch.js

js zoloft.com collected 2026-09-24 20:03:46 UTC 10,343 bytes, 372 lines download raw bytes

1/*!
2 * MediaElement.js
3 * http://www.mediaelementjs.com/
4 *
5 * Wrapper that mimics native HTML5 MediaElement (audio and video)
6 * using a variety of technologies (pure JavaScript, Flash, iframe)
7 *
8 * Copyright 2010-2017, John Dyer (http://j.hn/)
9 * License: MIT
10 *
11 */(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
12'use strict';
13
14var TwitchApi = {
15
16	promise: null,
17
18	load: function load(settings) {
19		if (typeof Twitch !== 'undefined') {
20			TwitchApi._createPlayer(settings);
21		} else if (!TwitchApi.promise) {
22			TwitchApi.promise = TwitchApi.promise || mejs.Utils.loadScript('https://player.twitch.tv/js/embed/v1.js');
23			TwitchApi.promise.then(function () {
24				TwitchApi._createPlayer(settings);
25			});
26		}
27
28		return TwitchApi.promise;
29	},
30
31	_createPlayer: function _createPlayer(settings) {
32		var player = new Twitch.Player(settings.id, settings);
33		window['__ready__' + settings.id](player);
34	},
35
36	getTwitchId: function getTwitchId(url) {
37		var twitchId = '';
38
39		if (url.indexOf('?') > 0) {
40			twitchId = TwitchApi.getTwitchIdFromParam(url);
41			if (twitchId === '') {
42				twitchId = TwitchApi.getTwitchIdFromUrl(url);
43			}
44		} else {
45			twitchId = TwitchApi.getTwitchIdFromUrl(url);
46		}
47
vendor: 4,726 bytes, lines 48-228
48		return twitchId;
49	},
50
51	getTwitchIdFromParam: function getTwitchIdFromParam(url) {
52		if (url === undefined || url === null || !url.trim().length) {
53			return null;
54		}
55
56		var parts = url.split('?'),
57		    parameters = parts[1].split('&');
58
59		var twitchId = '';
60
61		for (var i = 0, total = parameters.length; i < total; i++) {
62			var paramParts = parameters[i].split('=');
63			if (~paramParts[0].indexOf('channel=')) {
64				twitchId = paramParts[1];
65				break;
66			} else if (~paramParts[0].indexOf('video=')) {
67				twitchId = 'v' + paramParts[1];
68				break;
69			}
70		}
71
72		return twitchId;
73	},
74
75	getTwitchIdFromUrl: function getTwitchIdFromUrl(url) {
76		if (url === undefined || url === null || !url.trim().length) {
77			return null;
78		}
79
80		var parts = url.split('?');
81		url = parts[0];
82		var id = url.substring(url.lastIndexOf('/') + 1);
83		return (/^\d+$/i.test(id) !== null ? 'v' + id : id
84		);
85	},
86
87	getTwitchType: function getTwitchType(id) {
88		return (/^v\d+/i.test(id) !== null ? 'video' : 'channel'
89		);
90	}
91};
92
93var TwitchIframeRenderer = {
94	name: 'twitch_iframe',
95	options: {
96		prefix: 'twitch_iframe'
97	},
98
99	canPlayType: function canPlayType(type) {
100		return ~['video/twitch', 'video/x-twitch'].indexOf(type.toLowerCase());
101	},
102
103	create: function create(mediaElement, options, mediaFiles) {
104		var twitch = {},
105		    apiStack = [],
106		    readyState = 4,
107		    twitchId = TwitchApi.getTwitchId(mediaFiles[0].src);
108
109		var twitchPlayer = null,
110		    paused = true,
111		    ended = false,
112		    hasStartedPlaying = false,
113		    volume = 1,
114		    duration = Infinity,
115		    time = 0;
116
117		twitch.options = options;
118		twitch.id = mediaElement.id + '_' + options.prefix;
119		twitch.mediaElement = mediaElement;
120
121		var props = mejs.html5media.properties,
122		    assignGettersSetters = function assignGettersSetters(propName) {
123			var capName = '' + propName.substring(0, 1).toUpperCase() + propName.substring(1);
124
125			twitch['get' + capName] = function () {
126				if (twitchPlayer !== null) {
127					var value = null;
128
129					switch (propName) {
130						case 'currentTime':
131							time = twitchPlayer.getCurrentTime();
132							return time;
133						case 'duration':
134							duration = twitchPlayer.getDuration();
135							return duration;
136						case 'volume':
137							volume = twitchPlayer.getVolume();
138							return volume;
139						case 'paused':
140							paused = twitchPlayer.isPaused();
141							return paused;
142						case 'ended':
143							ended = twitchPlayer.getEnded();
144							return ended;
145						case 'muted':
146							return twitchPlayer.getMuted();
147						case 'buffered':
148							return {
149								start: function start() {
150									return 0;
151								},
152								end: function end() {
153									return 0;
154								},
155								length: 1
156							};
157						case 'src':
158							return TwitchApi.getTwitchType(twitchId) === 'channel' ? twitchPlayer.getChannel() : twitchPlayer.getVideo();
159						case 'readyState':
160							return readyState;
161					}
162
163					return value;
164				} else {
165					return null;
166				}
167			};
168
169			twitch['set' + capName] = function (value) {
170				if (twitchPlayer !== null) {
171					switch (propName) {
172						case 'src':
173							var url = typeof value === 'string' ? value : value[0].src,
174							    videoId = TwitchApi.getTwitchId(url);
175
176							if (TwitchApi.getTwitchType(twitchId) === 'channel') {
177								twitchPlayer.setChannel(videoId);
178							} else {
179								twitchPlayer.setVideo(videoId);
180							}
181							break;
182						case 'currentTime':
183							twitchPlayer.seek(value);
184							setTimeout(function () {
185								var event = mejs.Utils.createEvent('timeupdate', twitch);
186								mediaElement.dispatchEvent(event);
187							}, 50);
188							break;
189						case 'muted':
190							twitchPlayer.setMuted(value);
191							setTimeout(function () {
192								var event = mejs.Utils.createEvent('volumechange', twitch);
193								mediaElement.dispatchEvent(event);
194							}, 50);
195							break;
196						case 'volume':
197							volume = value;
198							twitchPlayer.setVolume(value);
199							setTimeout(function () {
200								var event = mejs.Utils.createEvent('volumechange', twitch);
201								mediaElement.dispatchEvent(event);
202							}, 50);
203							break;
204						case 'readyState':
205							var event = mejs.Utils.createEvent('canplay', twitch);
206							mediaElement.dispatchEvent(event);
207							break;
208						default:
209							
210							break;
211					}
212				} else {
213					apiStack.push({ type: 'set', propName: propName, value: value });
214				}
215			};
216		};
217
218		for (var i = 0, total = props.length; i < total; i++) {
219			assignGettersSetters(props[i]);
220		}
221
222		var methods = mejs.html5media.methods,
223		    assignMethods = function assignMethods(methodName) {
224			twitch[methodName] = function () {
225				if (twitchPlayer !== null) {
226					switch (methodName) {
227						case 'play':
228							paused = false;
229							return twitchPlayer.play();
230						case 'pause':
231							paused = true;
232							return twitchPlayer.pause();
233						case 'load':
234							return null;
235					}
236				} else {
237					apiStack.push({ type: 'call', methodName: methodName });
238				}
239			};
240		};
241
242		for (var _i = 0, _total = methods.length; _i < _total; _i++) {
243			assignMethods(methods[_i]);
244		}
245
246		function sendEvents(events) {
247			for (var _i2 = 0, _total2 = events.length; _i2 < _total2; _i2++) {
248				var event = mejs.Utils.createEvent(events[_i2], twitch);
249				mediaElement.dispatchEvent(event);
250			}
251		}
252
253		window['__ready__' + twitch.id] = function (_twitchPlayer) {
254			mediaElement.twitchPlayer = twitchPlayer = _twitchPlayer;
255
256			if (apiStack.length) {
257				for (var _i3 = 0, _total3 = apiStack.length; _i3 < _total3; _i3++) {
258					var stackItem = apiStack[_i3];
259
260					if (stackItem.type === 'set') {
261						var propName = stackItem.propName,
262						    capName = '' + propName.substring(0, 1).toUpperCase() + propName.substring(1);
263
264						twitch['set' + capName](stackItem.value);
265					} else if (stackItem.type === 'call') {
266						twitch[stackItem.methodName]();
267					}
268				}
269			}
270
271			var twitchIframe = document.getElementById(twitch.id).firstChild;
272			twitchIframe.style.width = '100%';
273			twitchIframe.style.height = '100%';
274
275			var events = ['mouseover', 'mouseout'],
276			    assignEvents = function assignEvents(e) {
277				var event = createEvent(e.type, twitch);
278				mediaElement.dispatchEvent(event);
279			};
280
281			for (var _i4 = 0, _total4 = events.length; _i4 < _total4; _i4++) {
282				twitchIframe.addEventListener(events[_i4], assignEvents, false);
283			}
284
285			var timer = void 0;
286
287			twitchPlayer.addEventListener('ready', function () {
288				paused = false;
289				ended = false;
290				sendEvents(['rendererready', 'loadedmetadata', 'loadeddata', 'canplay']);
291			});
292			twitchPlayer.addEventListener('play', function () {
293				if (!hasStartedPlaying) {
294					hasStartedPlaying = true;
295				}
296				paused = false;
297				ended = false;
298				sendEvents(['play', 'playing', 'progress']);
299
300				timer = setInterval(function () {
301					twitchPlayer.getCurrentTime();
302					sendEvents(['timeupdate']);
303				}, 250);
304			});
305			twitchPlayer.addEventListener('pause', function () {
306				paused = true;
307				ended = false;
308				if (!twitchPlayer.getEnded()) {
309					sendEvents(['pause']);
310				}
311			});
312			twitchPlayer.addEventListener('ended', function () {
313				paused = true;
314				ended = true;
315				sendEvents(['ended']);
316				clearInterval(timer);
317				hasStartedPlaying = false;
318				timer = null;
319			});
320		};
321
322		var height = mediaElement.originalNode.height,
323		    width = mediaElement.originalNode.width,
324		    twitchContainer = document.createElement('div'),
325		    type = TwitchApi.getTwitchType(twitchId),
326		    twitchSettings = {
327			id: twitch.id,
328			width: width,
329			height: height,
330			playsinline: false,
331			autoplay: mediaElement.originalNode.autoplay,
332			muted: mediaElement.originalNode.muted
333		};
334
335		twitchSettings[type] = twitchId;
336		twitchContainer.id = twitch.id;
337		twitchContainer.style.width = '100%';
338		twitchContainer.style.height = '100%';
339
340		mediaElement.originalNode.parentNode.insertBefore(twitchContainer, mediaElement.originalNode);
341		mediaElement.originalNode.style.display = 'none';
342		mediaElement.originalNode.autoplay = false;
343
344		twitch.setSize = function (width, height) {
345			if (TwitchApi !== null && !isNaN(width) && !isNaN(height)) {
346				twitchContainer.setAttribute('width', width);
347				twitchContainer.setAttribute('height', height);
348			}
349		};
350		twitch.hide = function () {
351			twitch.pause();
352			twitchContainer.style.display = 'none';
353		};
354		twitch.show = function () {
355			twitchContainer.style.display = '';
356		};
357		twitch.destroy = function () {};
358
359		mediaElement.promises.push(TwitchApi.load(twitchSettings));
360
361		return twitch;
362	}
363};
364
365mejs.Utils.typeChecks.push(function (url) {
366	return (/\/\/(www|player).twitch.tv/i.test(url) ? 'video/x-twitch' : null
367	);
368});
369
370mejs.Renderers.add(TwitchIframeRenderer);
371
372},{}]},{},[1]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.