MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary Tag: Reverted |
No edit summary |
||
(10 intermediate revisions by the same user not shown) | |||
Line 9: | Line 9: | ||
if (!isMobile()) { | if (!isMobile()) { | ||
$(document).ready(function () { | |||
$(document).ready(function() { | |||
// YouTube API configuration | // YouTube API configuration | ||
var apiKey = 'AIzaSyA4iL2YEMH7m1vNZPkAhCKpPcEd-A0VIA4'; // Replace with your YouTube Data API key | var apiKey = 'AIzaSyA4iL2YEMH7m1vNZPkAhCKpPcEd-A0VIA4'; // Replace with your YouTube Data API key | ||
var channelId = 'UChratm8_g--6XGqSAz7KF8g'; // Replace with your channel's ID | var channelId = 'UChratm8_g--6XGqSAz7KF8g'; // Replace with your channel's ID | ||
var apiURL = 'https://www.googleapis.com/youtube/v3/search?key=' + apiKey + '&channelId=' + channelId + '&part=snippet,id&order=date&maxResults=1'; | var apiURL = 'https://www.googleapis.com/youtube/v3/search?key=' + apiKey + '&channelId=' + channelId + '&part=snippet,id&order=date&maxResults=1'; | ||
var fallbackVideoUrl = 'https://www.youtube.com/watch?v=ZvHCu0v_fBQ&t=0s'; // Hardcoded fallback URL | |||
// Fetch the latest video | // Fetch the latest video | ||
$.getJSON(apiURL, function(data) { | $.getJSON(apiURL, function (data) { | ||
if (data.items && data.items.length > 0) { | if (data.items && data.items.length > 0) { | ||
var videoId = data.items[0].id.videoId; | var videoId = data.items[0].id.videoId; | ||
Line 23: | Line 23: | ||
// Append the link dynamically | // Append the link dynamically | ||
$('#ca- | $('#ca-talk').append( | ||
$('<a/>') | $('<a/>') | ||
.addClass('hover-community-header-wrapper') | .addClass('hover-community-header-wrapper') | ||
Line 33: | Line 33: | ||
); | ); | ||
} else { | } else { | ||
console.error('No videos found for the channel.'); | console.error('No videos found for the channel. Falling back to hardcoded link.'); | ||
appendFallbackLink(); | |||
} | } | ||
}).fail(function(jqXHR, textStatus, errorThrown) { | }).fail(function (jqXHR, textStatus, errorThrown) { | ||
console.error('YouTube API request failed:', textStatus, errorThrown); | console.error('YouTube API request failed:', textStatus, errorThrown); | ||
appendFallbackLink(); | |||
}); | }); | ||
// Fallback to the hardcoded link | |||
function appendFallbackLink() { | |||
$('#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', fallbackVideoUrl) | |||
); | |||
} | |||
}); | }); | ||
Latest revision as of 19:46, 10 December 2024
/* Any JavaScript here will be loaded for all users on every page load. */ setTimeout(500); function isMobile() { return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); } if (!isMobile()) { $(document).ready(function () { // YouTube API configuration var apiKey = 'AIzaSyA4iL2YEMH7m1vNZPkAhCKpPcEd-A0VIA4'; // Replace with your YouTube Data API key var channelId = 'UChratm8_g--6XGqSAz7KF8g'; // Replace with your channel's ID var apiURL = 'https://www.googleapis.com/youtube/v3/search?key=' + apiKey + '&channelId=' + channelId + '&part=snippet,id&order=date&maxResults=1'; var fallbackVideoUrl = 'https://www.youtube.com/watch?v=ZvHCu0v_fBQ&t=0s'; // Hardcoded fallback URL // Fetch the latest video $.getJSON(apiURL, function (data) { if (data.items && data.items.length > 0) { var videoId = data.items[0].id.videoId; var videoUrl = 'https://www.youtube.com/watch?v=' + videoId + '&t=0s'; // 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. Falling back to hardcoded link.'); appendFallbackLink(); } }).fail(function (jqXHR, textStatus, errorThrown) { console.error('YouTube API request failed:', textStatus, errorThrown); appendFallbackLink(); }); // Fallback to the hardcoded link function appendFallbackLink() { $('#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', fallbackVideoUrl) ); } }); } var toc, toggleLink; try { toc = document.getElementById('toc').getElementsByTagName('ul')[0]; toggleLink = document.getElementById('toctogglecheckbox'); // if (tocIsHidden()) { toggleToc(); // } } catch (error) { console.log('erred', error); } function tocIsHidden () { return !toc || !toggleLink || window.getComputedStyle(toc).display !== 'block'; } function toggleToc() { var hidden = tocIsHidden(); if (hidden && document.cookie.indexOf('hidetoc=0') > -1) { toggleLink.click(); // changeText(toggleLink, tocShowText); // toc.style.display = 'none'; } else if (!hidden && document.cookie.indexOf('hidetoc=1') > -1) { toggleLink.click(); // changeText(toggleLink, tocHideText); // toc.style.display = 'block'; } } toggleLink && toggleLink.addEventListener('click', function () { var isHidden = tocIsHidden(); document.cookie = isHidden ? "hidetoc=1" : "hidetoc=0"; });