Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($) {
- /* trigger when page is ready */
- $(document).ready(function() {
- var mixerAPI = 'https://mixer.com/api/v1/channels/';
- var streamName = MixerUsername;
- var logo = swLogo;
- var apiCall = mixerAPI + streamName;
- $.ajax({
- url: apiCall,
- type: 'GET',
- headers: {
- 'Client-ID': '3385f3732ff772308b89485d4b3f7c81b0c69d05001af9b4'
- },
- success: function(data) {
- if(data.online) {
- $('body').addClass('online');
- $('.cp-header__indicator').addClass('cp-header__indicator--online');
- $('.cp-header__game-playing .cp-header__middle--line-2').text(data.name);
- $('.cp-nav__game-playing--line-2').text(data.name);
- $('.cp-header__viewers .cp-header__middle--line-2').text(data.viewersCurrent);
- $('.button--watch-now').attr('href', 'https://mixer.com/embed/player/' + streamName);
- console.log('Querying ' + streamName + ' - streamer online...', data.stream);
- } else {
- console.log('Querying ' + streamName + ' - streamer offline...', data);
- }
- },
- error: function(data) {
- console.log('Querying ' + streamName + ' - Mixer API error...', data);
- }
- });
- function getStreamId(streamName){
- $.ajax({
- url: 'https://mixer.com/api/v1/users/'+streamName,
- type: 'GET',
- headers: {
- 'Client-ID': '3385f3732ff772308b89485d4b3f7c81b0c69d05001af9b4'
- },
- success: function(data) {
- ID = data.data[0].id;
- },
- error: function(data) {
- console.log('[Easy Embed Twitch] - Failed to retrieve StreamId')
- },
- complete: function(data) {
- console.log('[Easy Embed Twitch] - Success - retrieved StreamId')
- getVods(ID)
- }
- });
- }
- function getVods(ID) {
- var videoURL = 'https://mixer.com/api/v1/user_id='+ID;
- $.ajax({
- url: videoURL,
- type: 'GET',
- headers: {
- 'Client-ID': '3385f3732ff772308b89485d4b3f7c81b0c69d05001af9b4'
- },
- success: function(data) {
- var vod = data.data;
- var vodThumb, vodURL, vodId, vodTitle, template;
- $('.cp-blog__stream').show();
- $('.cp-blog__posts').removeClass('cp-blog__posts--full-width');
- if (vod !== 0) {
- for (var i = 0; i < 6; i++) {
- preview = data.data[i].thumbnail_url;
- preview = preview.replace("%{height}", "176");
- preview = preview.replace("%{width}", "313");
- vodId = data.data[i].id;
- vodTitle = data.data[i].title;
- template = '<div class="cp-blog__vods-tile"><a class="cp-blog__vods-link button--modal" href="https://player.twitch.tv?video=' + vodId + '" target="_blank"><img class="cp-blog__vods-image" src="' + preview + '" /><h4 class="cp-blog__vods-title">' + vodTitle + '</h4><div class="cp-blog__vods-overlay"><span class="icon-play"></span></div></a></div>';
- $('.cp-blog__vods').append(template);
- }
- } else {
- console.log('no vods found, hiding vod section...');
- $('.cp-blog__stream').hide();
- $('.cp-blog__posts').addClass('cp-blog__posts--full-width');
- }
- },
- error: function(data) {
- console.log('no vods found, hiding vod section...');
- $('.cp-blog__stream').hide();
- $('.cp-blog__posts').addClass('cp-blog__posts--full-width');
- }
- });
- }
- if ($('.cp-blog__vods').length) {
- getStreamId(streamName);
- }
- $(document).on('click', '.cp-modal', function() {
- $('.cp-modal').removeClass('cp-modal--active');
- $('.cp-modal iframe').attr('src', '');
- });
- $(document).on('click', '.button--modal', function(e) {
- e.preventDefault();
- var url = $(this).attr('href');
- $('.cp-modal iframe').attr('src', url);
- $('.cp-modal').addClass('cp-modal--active');
- });
- if (!$('body').hasClass('broadcast-pro')) {
- if ($('.cp-affiliates').hasClass('cp-affiliates--hide')) {
- $('.cp-affiliates').removeClass('cp-affiliates--hide')
- }
- $('.cp-affiliates__wrapper').prepend('<a href="https://www.streamweasels.com/?affiliate=true" target="_blank"><img src="'+logo+'"></a>')
- }
- });
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement