MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary Tag: Reverted |
||
Line 1: | Line 1: | ||
/ | $(document).ready(function() { | ||
// YouTube API configuration | |||
const apiKey = 'AIzaSyA4iL2YEMH7m1vNZPkAhCKpPcEd-A0VIA4'; // Replace with your YouTube Data API key | |||
const channelId = 'UChratm8_g--6XGqSAz7KF8g'; // Replace with your channel's ID | |||
const apiURL = `https://www.googleapis.com/youtube/v3/search?key=${apiKey}&channelId=${channelId}&part=snippet,id&order=date&maxResults=1`; | |||
// Fetch the latest video | |||
$.getJSON(apiURL, function(data) { | |||
if (data.items && data.items.length > 0) { | |||
const videoId = data.items[0].id.videoId; | |||
const videoUrl = `https://www.youtube.com/watch?v=${videoId}`; | |||
// Append the link dynamically | |||
$('#ca-talk').append( | |||
$('<a/>') | |||
.addClass('hover-community-header-wrapper') | |||
.append($('<div/>') | |||
.addClass('wgp-ep-msg') | |||
.text('Click here to view the latest episode!') | |||
$('#ca-talk').append( | ) | ||
.attr('href', videoUrl) | |||
); | |||
} else { | |||
console.error('No videos found for the channel.'); | |||
} | |||
}).fail(function(jqXHR, textStatus, errorThrown) { | |||
); | console.error('YouTube API request failed:', textStatus, errorThrown); | ||
}); | |||
} | |||
} | |||
function | |||
}); | }); |
Revision as of 18:09, 10 December 2024
$(document).ready(function() { // YouTube API configuration const apiKey = 'AIzaSyA4iL2YEMH7m1vNZPkAhCKpPcEd-A0VIA4'; // Replace with your YouTube Data API key const channelId = 'UChratm8_g--6XGqSAz7KF8g'; // Replace with your channel's ID const apiURL = `https://www.googleapis.com/youtube/v3/search?key=${apiKey}&channelId=${channelId}&part=snippet,id&order=date&maxResults=1`; // Fetch the latest video $.getJSON(apiURL, function(data) { if (data.items && data.items.length > 0) { const videoId = data.items[0].id.videoId; const videoUrl = `https://www.youtube.com/watch?v=${videoId}`; // Append the link dynamically $('#ca-talk').append( $('<a/>') .addClass('hover-community-header-wrapper') .append($('<div/>') .addClass('wgp-ep-msg') .text('Click here to view the latest episode!') ) .attr('href', videoUrl) ); } else { console.error('No videos found for the channel.'); } }).fail(function(jqXHR, textStatus, errorThrown) { console.error('YouTube API request failed:', textStatus, errorThrown); }); });