MediaWiki:Common.js: Difference between revisions

From Weegeepie Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 21: Line 21:
var toc, toggleLink;
var toc, toggleLink;
try {
try {
setTimeout(1000);
   toc = document.getElementById('toc').getElementsByTagName('ul')[0];
   toc = document.getElementById('toc').getElementsByTagName('ul')[0];
   toggleLink = document.getElementById('toctogglecheckbox');
   toggleLink = document.getElementById('toctogglecheckbox');

Revision as of 19:21, 3 January 2024

/* Any JavaScript here will be loaded for all users on every page load. */

function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}

if (!isMobile()) {

/* Taken from MD wiki lol */
$('#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', 'https://www.youtube.com/watch?v=MFxGcb_XuT0')
);

}

var toc, toggleLink;
try {
setTimeout(1000);
  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";
});