Difference between revisions of "MediaWiki:Common.js"
Line 176: | Line 176: | ||
var body = document.getElementsByTagName('body')[0]; | var body = document.getElementsByTagName('body')[0]; | ||
body.classList.remove('page-Leaderboards') | body.classList.remove('page-Leaderboards') | ||
+ | } | ||
+ | |||
+ | //modal | ||
+ | |||
+ | if (window.location.href == 'https://dkcspeedruns.com/Leaderboards') { | ||
+ | var links = document.getElementsByTagName('a'); | ||
+ | for (var j = 0; j < links.length; j++) { | ||
+ | if (links[j].innerHTML == 'Video') { | ||
+ | var link = links[j].href; | ||
+ | console.log(link); | ||
+ | links[j].setAttribute('data-embed', link); | ||
+ | links[j].removeAttribute('href'); | ||
+ | links[j].onclick = function() { | ||
+ | var link = this.getAttribute('data-embed'); | ||
+ | document.getElementsByTagName('html')[0].className += ' ve-loading'; | ||
+ | var modal = document.createElement('div'); | ||
+ | var close = document.createElement('div'); | ||
+ | close.id = "close"; | ||
+ | close.onclick = function() { | ||
+ | document.getElementsByTagName('html')[0].className = document.getElementsByTagName('html')[0].className.substr(0, document.getElementsByTagName('html')[0].className.length - 11); | ||
+ | document.getElementById('modal').outerHTML = ''; | ||
+ | } | ||
+ | modal.id = "modal"; | ||
+ | if (link.indexOf('twitch') > -1) { | ||
+ | modal.innerHTML = '<iframe src="https://player.twitch.tv/?video=' + link.substr(link.length - 9) + '" height="100%" width="100%"></iframe>'; | ||
+ | body.appendChild(modal); | ||
+ | modal.appendChild(close); | ||
+ | } else if (link.indexOf('youtube') > -1) { | ||
+ | modal.innerHTML = '<iframe src="https://www.youtube.com/embed/' + link.substr(link.length - 11) + '?autoplay=1" height="100%" width="100%"></iframe>'; | ||
+ | body.appendChild(modal); | ||
+ | modal.appendChild(close); | ||
+ | } else { | ||
+ | modal.innerHTML = '<video controls><source src="' + link + '"></video>'; | ||
+ | body.appendChild(modal); | ||
+ | modal.appendChild(close); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
} | } |
Revision as of 20:37, 3 April 2018
/* Any JavaScript here will be loaded for all users on every page load. */ if (window.location.href == 'https://dkcspeedruns.com/Main_Page') { var body, donkey, clickbait, krool; body = document.getElementsByTagName('body')[0]; donkey = document.createElement('span'); donkey.className = 'donkey-vine'; body.appendChild(donkey); donkeyImg = document.createElement('img'); donkeyImg.src = 'https://lh3.googleusercontent.com/HgzIYLiblc5D-1AwQjN4IFgCudFVbzJc5MoOdzOt69ftO0s4VJ245vfYNvGFufBh3aP4W0slle1bwWNGrg4Vu1RWd9hj1T_fMsdMjjn5DQ=s0'; donkey.appendChild(donkeyImg); clickbait = document.createElement('img'); clickbait.src = 'https://lh3.googleusercontent.com/eOOIdVO2nbcWBDrOhq_iv-GkaZP5pXlvv84yqaPLwWRsNKZwseqw2XF65v-zu8n7oJfeZBLAyb0aU0hVekSHbfZ8j11XtYFVk4jumnC00w=s0'; clickbait.id = "clickbait"; document.getElementById('bodyContent').insertBefore(clickbait, document.getElementById('bodyContent').firstChild); krool = document.createElement('div'); krool.id = 'krool'; krool.className = 'pop-out'; krool.className += ' paused'; body.appendChild(krool); clickbait.onclick = function() { krool.classList.remove('paused'); } } if (window.location.href.indexOf('https://dkcspeedruns.com/Krowb0t') > -1) { top.location= 'https://www.lukelogiudice.com/krowb0t'; } if (window.location.href == 'https://dkcspeedruns.com/Leaderboards') { document.getElementById('firstHeading').style.border = 'none'; var editLinks = document.getElementsByClassName('mw-editsection-visualeditor'); for (var i = 0; i < editLinks.length; i++) { editLinks[i].style.display = 'none'; var newLink = document.createElement('a'); newLink.href = 'https://dkcspeedruns.com/' + editLinks[i].href.substr(51).split('&')[0] + '?veaction=edit'; newLink.innerHTML = 'edit', editLinks[i].parentNode.insertBefore(newLink, editLinks[i]); } var body, toc, container, gameTabs, gameTabsContainer, catTabs, games, gamesContainer, cats, catsContainer, currentGame; toc = document.getElementById('toc'); container = document.getElementById('mw-content-text'); toc.style.display = 'none'; body = document.getElementsByTagName('body')[0]; gameTabs = document.getElementById('mw-content-text').getElementsByTagName('h1'); catTabs = document.getElementById('mw-content-text').getElementsByTagName('h2'); currentGame = 0; $(gameTabs).each(function(i) { if (i == 0) { $(this).addClass('game-tab selected'); } else { $(this).addClass('game-tab'); } $(this).nextUntil('h1').wrapAll('<div class="game"></div>'); }); $(catTabs).each(function(i) { if (i == 0) { //skip <h2>Contents</h2> random shit } else if (i == 1) { $(this).addClass('cat-tab selected'); } else { $(this).addClass('cat-tab'); } $(this).nextUntil('h2').wrapAll('<div class="cat"></div>'); }); games = document.getElementsByClassName('game'); cats = document.getElementsByClassName('cat'); gameTabsContainer = document.createElement('div'); gameTabsContainer.id = 'game-tabs'; body.appendChild(gameTabsContainer); // add h1 elements to game tabs container while (gameTabs.length > 0) { //appened each game tab to container //gameTabs[0].innerText = gameTabs[0].innerText.substr(0, gameTabs[0].innerText.length - 20); gameTabsContainer.appendChild(gameTabs[0]); } //move game tabs to top of page container.insertBefore(gameTabsContainer, container.firstChild); // add h2 elements to cat tabs container for (var i = 0; i < games.length; i++) { var catTabsContainer = document.createElement('div'); catTabsContainer.className = 'cat-tabs'; var tabs = games[i].getElementsByClassName('cat-tab'); while (tabs.length > 0) { //tabs[0].innerText = tabs[0].innerText.substr(0, tabs[0].innerText.length - 20); catTabsContainer.appendChild(tabs[0]); } games[i].insertBefore(catTabsContainer, games[i].firstChild); }; // show first game for (var i = 0; i < games.length; i++) { if (i == 0) { games[i].className += ' dkc-show'; }; } // show first cat for (var i = 0; i < cats.length; i++) { if (i == 0) { cats[i].className += ' dkc-show'; }; } //show game for (var i = 0; i < gameTabs.length; i++) { (function(index) { gameTabs[i].onclick = function() { // alert(index) ; showCurrentGame(index); } })(i); } var showCurrentGame = function(index) { if (currentGame != index) { currentGame = index; // ALL TABS for (var k = 0; k < games.length; k++) { games[k].classList.remove('dkc-show'); // hide all games gameTabs[k].className = 'game-tab'; // remove selected from any game tabs // reset cat tabs var resetCatTabs = games[k].getElementsByClassName('cat-tab'); for (var p = 0; p < resetCatTabs.length; p++) { if (resetCatTabs[p].classList.contains('selected')) { resetCatTabs[p].classList.remove('selected'); } } // reset cats var resetCats = games[k].getElementsByClassName('cat'); for (var p = 0; p < resetCats.length; p++) { if (resetCats[p].classList.contains('dkc-show')) { resetCats[p].classList.remove('dkc-show'); } } } // CURRENT TAB gameTabs[index].className += ' selected'; // add selected to current game tab games[index].className += ' dkc-show'; // show current game games[index].getElementsByClassName('cat')[0].className += ' dkc-show'; // show first cat games[index].getElementsByClassName('cat-tab')[0].className = 'cat-tab selected'; // select first cat tab } else { for (var k = 0; k < games.length; k++) { games[k].classList.remove('dkc-show'); // hide all games } // show games games[index].className += ' dkc-show'; } } //show cat for (var i = 0; i < catTabs.length; i++) { (function(index) { catTabs[i].onclick = function() { // alert(index) ; showCurrentCat(index - 1); } })(i); } var showCurrentCat = function(cat) { // hide cats for (var k = 0; k < cats.length; k++) { cats[k].classList.remove('dkc-show'); catTabs[k].className = 'cat-tab'; } // show cats catTabs[cat + 1].className = 'cat-tab selected'; cats[cat].className += ' dkc-show'; } container.style.marginBottom = '-10px'; container.style.display = 'block'; } if (window.location.href.indexOf('Leaderboards') > -1) { var body = document.getElementsByTagName('body')[0]; body.classList.remove('page-Leaderboards') } //modal if (window.location.href == 'https://dkcspeedruns.com/Leaderboards') { var links = document.getElementsByTagName('a'); for (var j = 0; j < links.length; j++) { if (links[j].innerHTML == 'Video') { var link = links[j].href; console.log(link); links[j].setAttribute('data-embed', link); links[j].removeAttribute('href'); links[j].onclick = function() { var link = this.getAttribute('data-embed'); document.getElementsByTagName('html')[0].className += ' ve-loading'; var modal = document.createElement('div'); var close = document.createElement('div'); close.id = "close"; close.onclick = function() { document.getElementsByTagName('html')[0].className = document.getElementsByTagName('html')[0].className.substr(0, document.getElementsByTagName('html')[0].className.length - 11); document.getElementById('modal').outerHTML = ''; } modal.id = "modal"; if (link.indexOf('twitch') > -1) { modal.innerHTML = '<iframe src="https://player.twitch.tv/?video=' + link.substr(link.length - 9) + '" height="100%" width="100%"></iframe>'; body.appendChild(modal); modal.appendChild(close); } else if (link.indexOf('youtube') > -1) { modal.innerHTML = '<iframe src="https://www.youtube.com/embed/' + link.substr(link.length - 11) + '?autoplay=1" height="100%" width="100%"></iframe>'; body.appendChild(modal); modal.appendChild(close); } else { modal.innerHTML = '<video controls><source src="' + link + '"></video>'; body.appendChild(modal); modal.appendChild(close); } } } } }