/* Copyright (C) 2010 - 2017 Sebastian Luncan Copyright (C) 2017 Arun Isaac This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Website: http://isebaro.com/viewtube Contact: http://isebaro.com/contact */ // ==========Variables========== // (function() { // Userscript var userscript = 'ViewTube'; // Page var page = {win: window, doc: document, body: document.body, url: window.location.href, title: document.title, site: window.location.hostname.match(/([^.]+)\.[^.]+$/)[1]}; // Player var player = {}; var option = {'definition': 'HD', 'container': 'MP4', 'direct': false}; var mimetypes = { 'MPEG': 'video/mpeg', 'MP4': 'video/mp4', 'WebM': 'video/webm', 'FLV': 'video/x-flv', 'MOV': 'video/quicktime', 'M4V': 'video/x-m4v', 'AVI': 'video/x-msvideo', '3GP': 'video/3gpp', }; var sources = {}; // Links var website = 'https://git.systemreboot.net/youtube-noscript-shim/about'; var contact = 'mailto:arunisaac@systemreboot.net'; // ==========Functions========== // function createElement (type, attributes, ...children) { var element = document.createElement(type); for (var key in attributes) { if (key == 'innerHTML') element.innerHTML = attributes[key]; else element.setAttribute(key, attributes[key]); } for (var child in children) element.appendChild(child); return element; } function createVideoElement (attributes, ...children) { return createElement("video", Object.assign({controls: "controls", autoplay: "autoplay", volume: 0.8}, attributes)); } function createMyPlayer() { /* Get My Options */ function onGot(item) { Object.assign(option, item); /* The Panel */ player['playerPanel'] = createElement('div'); player['playerWindow'].appendChild(player['playerPanel']); /* Panel Video Menu */ player["videoMenu"] = createElement("select", {title: "Select the video format for playback"}); player["videoMenu"].addEventListener('change', function() { player['videoPlay'] = this.value; playMyVideo(); }, false); player['playerPanel'].appendChild(player['videoMenu']); for (var videoCode in player['videoList']) { player["videoItem"] = createElement("option", {value: videoCode, innerHTML: videoCode}); if (videoCode.indexOf('Video') != -1 || videoCode.indexOf('Audio') != -1) player["videoItem"].classList.add("audio-video-only"); if (player['videoList'][videoCode] == 'DASH') player["videoItem"].classList.add("dash"); player['videoMenu'].appendChild(player['videoItem']); if (videoCode == 'Direct Video Link') player["videoItem"].classList.add("direct-video-link"); } /* The Content */ player['playerContent'] = createElement('div'); player['playerWindow'].appendChild(player['playerContent']); /* Play My Video */ playMyVideo(); } promise = browser.storage.local.get(Object.keys(option)); promise.then(onGot, onGot); } function playDASHwithHTML5() { if (player['videoPlay'].indexOf('MP4') != -1) { player["contentVideo"] = createVideoElement({src: player["videoList"][player["videoPlay"].replace(/MP4/, "Video MP4")]}); if (player['videoList']['High Bitrate Audio Opus']) player["contentAudio"] = createVideoElement({src: player["videoList"]["High Bitrate Audio Opus"]}); else if (player['videoList']['Medium Bitrate Audio Opus']) player['contentAudio'] = createVideoElement({src: player['videoList']['Medium Bitrate Audio Opus']}); else player['contentAudio'] = createVideoElement({src: player['videoList']['Medium Bitrate Audio MP4']}); } else { player["contentVideo"] = createVideoElement({src: player["videoList"][player["videoPlay"].replace(/WebM/, "Video WebM")]}); if (player['videoList']['High Bitrate Audio Opus']) player["contentAudio"] = createVideoElement({src: player["videoList"]["High Bitrate Audio Opus"]}); else if (player['videoList']['Medium Bitrate Audio Opus']) player["contentAudio"] = createVideoElement({src: player["videoList"]["Medium Bitrate Audio Opus"]}); else player["contentAudio"] = createVideoElement({src: player["videoList"]["Medium Bitrate Audio WebM"]}); } player['contentAudio'].pause(); player['contentVideo'].addEventListener('play', function() { player['contentAudio'].play(); }, false); player['contentVideo'].addEventListener('pause', function() { player['contentAudio'].pause(); }, false); player['contentVideo'].addEventListener('ended', function() { player['contentVideo'].pause(); player['contentAudio'].pause(); }, false); player['contentVideo'].addEventListener('timeupdate', function() { if (player['contentAudio'].paused && !player['contentVideo'].paused) { player['contentAudio'].play(); } if (Math.abs(player['contentVideo'].currentTime - player['contentAudio'].currentTime) >= 0.30) { player['contentAudio'].currentTime = player['contentVideo'].currentTime; } }, false); player["contentAudio"].classList.add("hide"); player['contentVideo'].appendChild(player['contentAudio']); } function playMyVideo() { while (player['playerContent'].hasChildNodes()) player['playerContent'].removeChild(player['playerContent'].firstChild); if (player['videoList'][player['videoPlay']] == 'DASH') playDASHwithHTML5(); else player["contentVideo"] = createVideoElement({src: player["videoList"][player["videoPlay"]], poster: player["videoThumb"]}); player['playerContent'].appendChild(player['contentVideo']); } function cleanMyContent(content, unesc) { var myNewContent = content; if (unesc) myNewContent = unescape(myNewContent); myNewContent = myNewContent.replace(/\\u0025/g,'%'); myNewContent = myNewContent.replace(/\\u0026/g,'&'); myNewContent = myNewContent.replace(/\\/g,''); myNewContent = myNewContent.replace(/\n/g,''); return myNewContent; } function getMyContent(url, pattern, clean) { var myPageContent, myVideosParse, myVideosContent; var getMethod = (url != page.url) ? 'XHR' : 'DOM'; if (!sources[url]) sources[url] = {}; if (getMethod == 'DOM') { if (!sources[url]['DOM']) sources[url]['DOM'] = document.querySelector("html").innerHTML; myPageContent = sources[url]['DOM']; if (clean) myPageContent = cleanMyContent(myPageContent, true); myVideosParse = myPageContent.match(pattern); myVideosContent = (myVideosParse) ? myVideosParse[1] : null; if (myVideosContent) return myVideosContent; else getMethod = 'XHR'; } if (getMethod == 'XHR') { if (!sources[url]['XHR']) sources[url]['XHR'] = {}; if ((pattern == 'XML' && !sources[url]['XHR']['XML']) || (pattern != 'XML' && !sources[url]['XHR']['TEXT'])) { var xmlHTTP = new XMLHttpRequest(); xmlHTTP.open('GET', url, false); xmlHTTP.send(); if (pattern == 'XML') sources[url]['XHR']['XML'] = xmlHTTP.responseXML; else sources[url]['XHR']['TEXT'] = xmlHTTP.responseText; } if (pattern == 'XML') { myVideosContent = sources[url]['XHR']['XML']; } else if (pattern == 'TEXT') { myVideosContent = sources[url]['XHR']['TEXT']; } else { myPageContent = sources[url]['XHR']['TEXT']; if (clean) myPageContent = cleanMyContent(myPageContent, true); myVideosParse = myPageContent.match(pattern); myVideosContent = (myVideosParse) ? myVideosParse[1] : null; } return myVideosContent; } } function setMyOptions(key, value) { var pair = {}; pair[key] = value; browser.storage.local.set(pair); } // =====YouTube===== // // Add stylesheet document.head.appendChild(createElement("link", {rel: "stylesheet", type: "text/css", href: browser.extension.getURL("viewtube.css")})); /* Redirect Categories */ if (page.url.indexOf('gaming.youtube.com') != -1) { page.win.location.href = page.url.replace('gaming', 'www'); } /* Video Availability */ var ytVideoUnavailable = document.querySelector("#player-unavailable"); if (ytVideoUnavailable) { if (ytVideoUnavailable.className.indexOf('hid') == -1) { var ytAgeGateContent = document.querySelector("#watch7-player-age-gate-content"); if (!ytAgeGateContent) return; else { if(ytAgeGateContent.indexOf('feature=private_video') != -1) return; } } } /* Decrypt Signature */ var ytScriptSrc; function ytDecryptSignature(s) {return null;} function ytDecryptFunction() { var ytSignFuncName, ytSignFuncBody, ytSwapFuncName, ytSwapFuncBody, ytFuncMatch; ytScriptSrc = ytScriptSrc.replace(/(\r\n|\n|\r)/gm, ''); ytSignFuncName = ytScriptSrc.match(/"signature"\s*,\s*([^\)]*?)\(/); ytSignFuncName = (ytSignFuncName) ? ytSignFuncName[1] : null; if (ytSignFuncName) { ytFuncMatch = ytSignFuncName.replace(/\$/, '\\$') + '\\s*=\\s*function\\s*' + '\\s*\\(\\w+\\)\\s*\\{(.*?)\\}'; ytSignFuncBody = ytScriptSrc.match(ytFuncMatch); ytSignFuncBody = (ytSignFuncBody) ? ytSignFuncBody[1] : null; if (ytSignFuncBody) { ytSwapFuncName = ytSignFuncBody.match(/((\$|_|\w)+)\.(\$|_|\w)+\(\w,[0-9]+\)/); ytSwapFuncName = (ytSwapFuncName) ? ytSwapFuncName[1] : null; if (ytSwapFuncName) { ytFuncMatch = 'var\\s+' + ytSwapFuncName.replace(/\$/, '\\$') + '=\\s*\\{(.*?)\\};'; ytSwapFuncBody = ytScriptSrc.match(ytFuncMatch); ytSwapFuncBody = (ytSwapFuncBody) ? ytSwapFuncBody[1] : null; } if (ytSwapFuncBody) ytSignFuncBody = 'var ' + ytSwapFuncName + '={' + ytSwapFuncBody + '};' + ytSignFuncBody; ytSignFuncBody = 'try {' + ytSignFuncBody + '} catch(e) {return null}'; ytDecryptSignature = new Function('a', ytSignFuncBody); } } } /* Get Player Window */ var ytPlayerWindow = document.querySelector("#player"); if (!ytPlayerWindow) console.log("Couldn't get the player element."); else { /* Get Video Thumbnail */ var ytVideoThumb = getMyContent(page.url, 'link\\s+itemprop="thumbnailUrl"\\s+href="(.*?)"', false); if (!ytVideoThumb) ytVideoThumb = getMyContent(page.url, 'meta\\s+property="og:image"\\s+content="(.*?)"', false); if (!ytVideoThumb) { var ytVideoID = page.url.match(/(\?|&)v=(.*?)(&|$)/); if (ytVideoID) ytVideoThumb = 'https://img.youtube.com/vi/' + ytVideoID[2] + '/0.jpg'; } /* Get Videos Content */ var ytVideosEncodedFmts, ytVideosAdaptiveFmts, ytVideosContent, ytHLSVideos, ytHLSContent; ytVideosEncodedFmts = getMyContent(page.url, '"url_encoded_fmt_stream_map":\\s*"(.*?)"', false); if (!ytVideosEncodedFmts) ytVideosEncodedFmts = getMyContent(page.url, '\\\\"url_encoded_fmt_stream_map\\\\":\\s*\\\\"(.*?)\\\\"', false); ytVideosAdaptiveFmts = getMyContent(page.url, '"adaptive_fmts":\\s*"(.*?)"', false); if (!ytVideosAdaptiveFmts) ytVideosAdaptiveFmts = getMyContent(page.url, '\\\\"adaptive_fmts\\\\":\\s*\\\\"(.*?)\\\\"', false); if (ytVideosEncodedFmts) { ytVideosContent = ytVideosEncodedFmts; } else { ytHLSVideos = getMyContent(page.url, '"hlsvp":\\s*"(.*?)"', false); if (!ytHLSVideos) ytHLSVideos = getMyContent(page.url, '\\\\"hlsvp\\\\":\\s*\\\\"(.*?)\\\\"', false); if (ytHLSVideos) { ytHLSVideos = cleanMyContent(ytHLSVideos, false); if (ytHLSVideos.indexOf('keepalive/yes/') != -1) ytHLSVideos = ytHLSVideos.replace('keepalive/yes/', ''); } else { var ytVideoID = page.url.match(/(\?|&)v=(.*?)(&|$)/); ytVideoID = (ytVideoID) ? ytVideoID[2] : null; if (ytVideoID) { var ytVideoSts = getMyContent(page.url.replace(/watch.*?v=/, 'embed/').replace(/&.*$/, ''), '"sts"\\s*:\\s*(\\d+)', false); var ytVideosInfoURL = page.win.location.protocol + '//' + page.win.location.hostname + '/get_video_info?video_id=' + ytVideoID + '&eurl=https://youtube.googleapis.com/v/' + ytVideoID + '&sts=' + ytVideoSts; var ytVideosInfo = getMyContent(ytVideosInfoURL, 'TEXT', false); if (ytVideosInfo) { ytVideosEncodedFmts = ytVideosInfo.match(/url_encoded_fmt_stream_map=(.*?)&/); ytVideosEncodedFmts = (ytVideosEncodedFmts) ? ytVideosEncodedFmts[1] : null; if (ytVideosEncodedFmts) { ytVideosEncodedFmts = cleanMyContent(ytVideosEncodedFmts, true); ytVideosContent = ytVideosEncodedFmts; } if (!ytVideosAdaptiveFmts) { ytVideosAdaptiveFmts = ytVideosInfo.match(/adaptive_fmts=(.*?)&/); ytVideosAdaptiveFmts = (ytVideosAdaptiveFmts) ? ytVideosAdaptiveFmts[1] : null; if (ytVideosAdaptiveFmts) ytVideosAdaptiveFmts = cleanMyContent(ytVideosAdaptiveFmts, true); } } } } } if (ytVideosAdaptiveFmts && !ytHLSVideos) { if (ytVideosContent) ytVideosContent += ',' + ytVideosAdaptiveFmts; else ytVideosContent = ytVideosAdaptiveFmts; } function removeElements (selector) { document.querySelectorAll(selector).forEach(function (element) { element.remove(); }); } /* Remove Player Window */ removeElements("#placeholder-player"); /* Remove Sidebar Ads */ removeElements("#watch7-sidebar-ads"); /* Playlist */ var ytPlaylist = document.querySelector("#player-playlist"); if (ytPlaylist) { var ytPlaceholderPlaylist = document.querySelector("#placeholder-playlist"); if (ytPlaceholderPlaylist) ytPlaceholderPlaylist.appendChild(ytPlaylist); } /* My Player Window */ var myPlayerWindow = document.querySelector("#player-api"); /* Create Player */ var ytDefaultVideo = 'Low Definition MP4'; function ytPlayer() { player = { 'playerSocket': ytPlayerWindow, 'playerWindow': myPlayerWindow, 'videoList': ytVideoList, 'videoPlay': ytDefaultVideo, 'videoThumb': ytVideoThumb }; option['definitions'] = ['Ultra High Definition', 'Full High Definition', 'High Definition', 'Standard Definition', 'Low Definition', 'Very Low Definition']; option['containers'] = ['MP4', 'WebM', 'FLV', '3GP', 'Any']; createMyPlayer(); } /* Parse Videos */ function ytVideos() { var ytVideoFormats = { '5': 'Very Low Definition FLV', '17': 'Very Low Definition 3GP', '18': 'Low Definition MP4', '22': 'High Definition MP4', '34': 'Low Definition FLV', '35': 'Standard Definition FLV', '36': 'Low Definition 3GP', '37': 'Full High Definition MP4', '38': 'Ultra High Definition MP4', '43': 'Low Definition WebM', '44': 'Standard Definition WebM', '45': 'High Definition WebM', '46': 'Full High Definition WebM', '82': 'Low Definition 3D MP4', '83': 'Standard Definition 3D MP4', '84': 'High Definition 3D MP4', '85': 'Full High Definition 3D MP4', '100': 'Low Definition 3D WebM', '101': 'Standard Definition 3D WebM', '102': 'High Definition 3D WebM', '135': 'Standard Definition Video MP4', '136': 'High Definition Video MP4', '137': 'Full High Definition Video MP4', '138': 'Ultra High Definition Video MP4', '139': 'Low Bitrate Audio MP4', '140': 'Medium Bitrate Audio MP4', '141': 'High Bitrate Audio MP4', '171': 'Medium Bitrate Audio WebM', '172': 'High Bitrate Audio WebM', '244': 'Standard Definition Video WebM', '247': 'High Definition Video WebM', '248': 'Full High Definition Video WebM', '249': 'Low Bitrate Audio Opus', '250': 'Medium Bitrate Audio Opus', '251': 'High Bitrate Audio Opus', '266': 'Ultra High Definition Video MP4', '272': 'Ultra High Definition Video WebM', '298': 'High Definition Video MP4', '299': 'Full High Definition Video MP4', '302': 'High Definition Video WebM', '303': 'Full High Definition Video WebM', '313': 'Ultra High Definition Video WebM' }; var ytVideoFound = false; var ytVideos = ytVideosContent.split(','); var ytVideoParse, ytVideoCodeParse, ytVideoCode, myVideoCode, ytVideo; for (var i = 0; i < ytVideos.length; i++) { if (!ytVideos[i].match(/^url/)) { ytVideoParse = ytVideos[i].match(/(.*)(url=.*$)/); if (ytVideoParse) ytVideos[i] = ytVideoParse[2] + '&' + ytVideoParse[1]; } ytVideoCodeParse = ytVideos[i].match(/itag=(\d{1,3})/); ytVideoCode = (ytVideoCodeParse) ? ytVideoCodeParse[1] : null; if (ytVideoCode) { myVideoCode = ytVideoFormats[ytVideoCode]; if (myVideoCode) { ytVideo = cleanMyContent(ytVideos[i], true); ytVideo = ytVideo.replace(/url=/, '').replace(/&$/, ''); if (ytVideo.match(/itag=/) && ytVideo.match(/itag=/g).length > 1) { if (ytVideo.match(/itag=\d{1,3}&/)) ytVideo = ytVideo.replace(/itag=\d{1,3}&/, ''); else if (ytVideo.match(/&itag=\d{1,3}/)) ytVideo = ytVideo.replace(/&itag=\d{1,3}/, ''); } if (ytVideo.match(/clen=/) && ytVideo.match(/clen=/g).length > 1) { if (ytVideo.match(/clen=\d+&/)) ytVideo = ytVideo.replace(/clen=\d+&/, ''); else if (ytVideo.match(/&clen=\d+/)) ytVideo = ytVideo.replace(/&clen=\d+/, ''); } if (ytVideo.match(/lmt=/) && ytVideo.match(/lmt=/g).length > 1) { if (ytVideo.match(/lmt=\d+&/)) ytVideo = ytVideo.replace(/lmt=\d+&/, ''); else if (ytVideo.match(/&lmt=\d+/)) ytVideo = ytVideo.replace(/&lmt=\d+/, ''); } if (ytVideo.match(/type=(video|audio).*?&/)) ytVideo = ytVideo.replace(/type=(video|audio).*?&/, ''); else ytVideo = ytVideo.replace(/&type=(video|audio).*$/, ''); if (ytVideo.match(/xtags=[^%=]*&/)) ytVideo = ytVideo.replace(/xtags=[^%=]*?&/, ''); else if (ytVideo.match(/&xtags=[^%=]*$/)) ytVideo = ytVideo.replace(/&xtags=[^%=]*$/, ''); if (ytVideo.match(/&sig=/)) ytVideo = ytVideo.replace(/&sig=/, '&signature='); else if (ytVideo.match(/&s=/)) { var ytSig = ytVideo.match(/&s=(.*?)(&|$)/); if (ytSig) { var s = ytSig[1]; s = ytDecryptSignature(s); if (s) ytVideo = ytVideo.replace(/&s=.*?(&|$)/, '&signature=' + s + '$1'); else ytVideo = ''; } else ytVideo = ''; } ytVideo = cleanMyContent(ytVideo, true); if (ytVideo.indexOf('ratebypass') == -1) ytVideo += '&ratebypass=yes'; if (ytVideo && ytVideo.indexOf('http') == 0) { if (!ytVideoFound) ytVideoFound = true; ytVideoList[myVideoCode] = ytVideo; } } } } if (ytVideoFound) { /* DASH */ if (!ytVideoList['Standard Definition MP4'] && ytVideoList['Standard Definition Video MP4']) ytVideoList['Standard Definition MP4'] = 'DASH'; if (!ytVideoList['High Definition MP4'] && ytVideoList['High Definition Video MP4']) ytVideoList['High Definition MP4'] = 'DASH'; if (!ytVideoList['Full High Definition MP4'] && ytVideoList['Full High Definition Video MP4']) ytVideoList['Full High Definition MP4'] = 'DASH'; if (!ytVideoList['Ultra High Definition MP4'] && ytVideoList['Ultra High Definition Video MP4']) ytVideoList['Ultra High Definition MP4'] = 'DASH'; if (!ytVideoList['Standard Definition WebM'] && ytVideoList['Standard Definition Video WebM']) ytVideoList['Standard Definition WebM'] = 'DASH'; if (!ytVideoList['High Definition WebM'] && ytVideoList['High Definition Video WebM']) ytVideoList['High Definition WebM'] = 'DASH'; if (!ytVideoList['Full High Definition WebM'] && ytVideoList['Full High Definition Video WebM']) ytVideoList['Full High Definition WebM'] = 'DASH'; if (!ytVideoList['Ultra High Definition WebM'] && ytVideoList['Ultra High Definition Video WebM']) ytVideoList['Ultra High Definition WebM'] = 'DASH'; /* DVL */ ytVideoList['Direct Video Link'] = page.url; ytPlayer(); } else { if (ytVideosContent.indexOf("conn=rtmp") != -1) console.log("This video uses the RTMP protocol and is not supported."); else console.log("Couldn't get any video."); } } /* Parse HLS */ function ytHLS() { var ytHLSFormats = { '92': 'Very Low Definition MP4', '93': 'Low Definition MP4', '94': 'Standard Definition MP4', '95': 'High Definition MP4', '96': 'Full High Definition MP4' }; ytVideoList["Any Definition MP4"] = ytHLSVideos; if (ytHLSContent) { var ytHLSVideo, ytVideoCodeParse, ytVideoCode, myVideoCode; var ytHLSMatcher = new RegExp('(http.*?m3u8)', 'g'); ytHLSVideos = ytHLSContent.match(ytHLSMatcher); if (ytHLSVideos) { for (var i = 0; i < ytHLSVideos.length; i++) { ytHLSVideo = ytHLSVideos[i]; ytVideoCodeParse = ytHLSVideo.match(/\/itag\/(\d{1,3})\//); ytVideoCode = (ytVideoCodeParse) ? ytVideoCodeParse[1] : null; if (ytVideoCode) { myVideoCode = ytHLSFormats[ytVideoCode]; if (myVideoCode && ytHLSVideo) { ytVideoList[myVideoCode] = ytHLSVideo; } } } } } /* DVL */ ytVideoList['Direct Video Link'] = page.url; ytDefaultVideo = 'Any Definition MP4'; ytPlayer(); } /* Get Videos */ var ytVideoList = {}; if (ytVideosContent) { if (ytVideosContent.match(/&s=/) || ytVideosContent.match(/,s=/) || ytVideosContent.match(/u0026s=/)) { var ytScriptURL = getMyContent(page.url, '"js":\\s*"(.*?)"', true); if (!ytScriptURL) ytScriptURL = getMyContent(page.url.replace(/watch.*?v=/, 'embed/').replace(/&.*$/, ''), '"js":\\s*"(.*?)"', true); if (ytScriptURL) { ytScriptURL = page.win.location.protocol + ytScriptURL; try { ytScriptSrc = getMyContent(ytScriptURL, 'TEXT', false); if (ytScriptSrc) ytDecryptFunction(); ytVideos(); } catch(e) { try { var oReq = new XMLHttpRequest(); oReq.open("GET", ytScriptURL); oReq.onload = function(response) { if (response.readyState === 4 && response.status === 200 && response.responseText) { ytScriptSrc = response.responseText; ytDecryptFunction(); ytVideos(); } else console.log("Couldn't get the signature content."); }; oReq.onerror = function() { console.log("Couldn't make the request. Make sure your browser user scripts extension supports cross-domain requests."); }; oReq.send(); } catch(e) { console.log("Couldn't make the request. Make sure your browser user scripts extension supports cross-domain requests."); } } } else console.log("Couldn't get the signature link."); } else { ytVideos(); } } else { if (ytHLSVideos) { try { ytHLSContent = getMyContent(ytHLSVideos, 'TEXT', false); ytHLS(); } catch(e) { try { var oReq = new XMLHttpRequest(); oReq.open("GET", ytHLSVideos); oReq.onload = function(response) { if (response.readyState === 4 && response.status === 200 && response.responseText) { ytHLSContent = response.responseText; } ytHLS(); }; oReq.onerror = function() { ytHLS(); }; oReq.send(); } catch(e) { ytHLS(); } } } else console.log("Couldn't get the videos content."); } } })();