Created
March 25, 2020 13:08
-
-
Save surajsau/c8f39d66aefd7b45cb5a81c749e4bb97 to your computer and use it in GitHub Desktop.
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
/* | |
ptrack-content div contains an attribute 'data-ui-tracking-context' | |
which contains the information regarding video_id of the element. | |
It's a url-encoded JSON string. | |
*/ | |
function getVideoId(element) { | |
let ptrack_content = $(element).find('.ptrack-content'); | |
if(ptrack_content && ptrack_content.length > 0) { | |
let tracking_data = ptrack_content.attr('data-ui-tracking-context'); | |
let decoded_tracking_data = decodeURIComponent(tracking_data); | |
let decoded_tracking_json = JSON.parse(decoded_tracking_data); | |
// some attribute values have 'videoId' and some have 'video_id' | |
return decoded_tracking_json.videoId || decoded_tracking_json.video_id; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment