User:Josve05a/furmeScroller.js

// Copied from https://en.wikipedia.org/w/index.php?title=User:AWeenieMan/furmeScroller.js&oldid=188317338 - CC By SA 3.0 // If FurMeConfig does not exist. if( typeof( FurMeConfig ) == 'undefined' ) { FurMeConfig = {}; }

if (FurMeConfig.scrollerMax == 'undefined' || null == FurMeConfig.scrollerMax) FurMeConfig.scrollerMax = 10; if (FurMeConfig.scrollerSkipDone == 'undefined' || null == FurMeConfig.scrollerSkipDone) FurMeConfig.scrollerSkipDone = true;

function furmeScroller { try {		var scrollerStarted = decodeURIComponent(/[&?]furme-scroller=([^&]*)/.exec(window.location.search)[1]); }	catch ( err ) {} if ( mw.config.get('wgNamespaceNumber') == 2 ) {		var scrollerSpan = document.getElementById('furme-scroller'); if (null != scrollerSpan) scrollerSpan.innerHTML = 'Run FurMe Scroller'; }	else if ( mw.config.get('wgNamespaceNumber') == 6 && mw.config.get('wgAction') == 'view') {				if ( scrollerStarted == 'true' ) {						if (document.getElementById('delete') || !FurMeConfig.scrollerSkipDone) furme.seedValues; else furme.callback.next; }		else if ( parseInt(readCookie('FurMeScroller-Counter')) + 1 < FurMeConfig.scrollerMax ) {			var currentImage = parseInt(readCookie('FurMeScroller-Counter')) + 1; var scrollerImages = readCookie('FurMeScroller-Images').split(','); document.cookie = 'FurMeScroller-Counter=' + currentImage + ';path=/'; window.location = mw.config.get('wgArticlePath').replace(/\$1/, scrollerImages[currentImage]) + '?furme-scroller=true'; }		else if ( parseInt(readCookie('FurMeScroller-Counter')) + 1 == FurMeConfig.scrollerMax ) {			var currentImage = parseInt(readCookie('FurMeScroller-Counter')) + 1; document.cookie = 'FurMeScroller-Counter=' + currentImage + ';path=/'; alert ( 'FurMe scroller complete' ); }	} }

$(furmeScroller); furmeScroller.start = function furmeScrollerStart { var scrollerImages = new Array; var scrollerNums = new Array; var scrollerCount = 0; var articleText = document.getElementById('bodyContent'); var imagesList = articleText.getElementsByTagName('li'); var numImages = imagesList.length; // Get an array of random images to review while ( scrollerCount < FurMeConfig.scrollerMax ) {		var randNumberUsed = false; var randNumber = Math.floor(Math.random*(numImages + 1)); for ( i = 0; i < scrollerNums.length; i++ ) {			if ( scrollerNums[i] == randNumber ) randNumberUsed = true; }		if (randNumberUsed == false) {			scrollerImages[scrollerCount] = imagesList[randNumber].getElementsByTagName('a')[0].title; scrollerCount++; }	}	// Set cookie with image names document.cookie = 'FurMeScroller-Images=' + scrollerImages + ';path=/'; document.cookie = 'FurMeScroller-Counter=0;path=/'; window.location = mw.config.get('wgArticlePath').replace(/\$1/, scrollerImages[0]) + '?furme-scroller=true'; //alert(scrollerImages); }

function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); }	return null; }