Last active
October 5, 2018 10:44
-
-
Save DaggieBlanqx/895358ecc394cc3fb8611ceb25032ced to your computer and use it in GitHub Desktop.
http://www.christianworldmedia.com don`t have an api that shows when there is a video , so I created this javascript function that does that .Checks if there is a video . Email me at info@blanqx.com for queries /concerns .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use strict" | |
| var isLive = (parentURL)=>{ | |
| return new Promise((resolve,reject)=>{ | |
| /* Fetch webpage */ | |
| fetch(parentURL) | |
| .then((response)=>{ | |
| return response.text(); | |
| }) | |
| .then((data)=>{ | |
| /*convert webpage string to DOMNodes*/ | |
| let webPage = document.createRange().createContextualFragment(data); | |
| /*Find the video tag*/ | |
| let videoTag = webPage.querySelector('video'); | |
| if (videoTag != null) { | |
| /*video tag found , find video url*/ | |
| resolve({ | |
| status : true, | |
| url : videoTag.src | |
| }); | |
| }else{ | |
| /*No video tag found*/ | |
| resolve({ | |
| status : false | |
| }); | |
| } | |
| }) | |
| .catch((err)=>{ | |
| reject(err); | |
| }) | |
| }); | |
| }; | |
| /** | |
| USAGE : THIS IS HOW TO USE THIS FUNCTION | |
| **/ | |
| var testUrl = 'https://www.christianworldmedia.com/1224-1175-/embed-html5/f7/livestream.html'; | |
| isLive(testUrl) | |
| .then((info)=>{ | |
| if(info.status){ | |
| /*Do an action that shows that there is a video*/ | |
| console.log('there is a video'); | |
| }else{ | |
| /* Do an action that shows that there is no video*/ | |
| console.log('No video available') | |
| } | |
| }) | |
| .catch((err)=>{ | |
| console.error(`Sorry seems an error occured \n ${err}`); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment