User:Stuem007/SuggestBotOverlay.js

/* User:Stuem007/sboverlay.js */ //importScript( 'User:Stuem007/sboverlay.js' );// Backlink: User:Stuem007/sboverlay.js

// sboverlay // Make sure the utilities module is loaded (will only load if not already) mw.loader.using( 'mediawiki.util', function {

// Wait for the page to be parsed $(document).ready( function {    	// Only run in the User talk namespace    	if (wgNamespaceNumber === 3) {	    	//alert('just loaded in');	    	var idStr = "SuggestBotRecLink"	    	var recLinks = document.getElementsByClassName('plainlinks');	        //alert(reclinks.length + " links fetched");	        for (var i = 0; i < recLinks.length; i++) {	            //alert("in for loop " + reclinks[i].id);	            if (recLinks[i].id.indexOf(idStr) > -1) {	                //alert("listener added");	                recLinks[i].addEventListener('click', function { event.preventDefault; //alert(this.noteType); var recIndex = this.id.substr(idStr.length); //alert('clicked element ' + recIndex); var articleNameID = "SuggestBotName" + recIndex; //alert(articleNameID); var articleNameText = document.getElementById(articleNameID).innerHTML; articleNameText = articleNameText.substring(0, articleNameText.indexOf(" ") - 1); alert(articleNameText); var recList = ["Stuem007", "Gilliam", "82redleg", "AGK", "Aldaron", "AshLin", "Carptrash", "Dormskirk", "Foxsch", "John"]; var tableBody = ""; for (var j = 0; j < recList.length; j ++) { tableBody += '' + '' + recList[j] + ' ' + ' ' + recList[j] + '\'s user page ' + ' ' + recList[j] + '\'s talk page ' + ' ' + recList[j] + '\'s contributions ' + ' ';		       		}						var imageClose = "https://upload.wikimedia.org/wikipedia/commons/e/e7/Closewindow.svg"; // Load prerequisites importStylesheet('User:Stuem007/SuggestBotCollaboratorOverlay.css'); loadJQViewport; // Predict a static sboverlay height var sboverlay = 31; // Create/insert empty sboverlay div $('#mw-head').prepend('. '); // Grab the div sboverlay = $('.sboverlay'); // Add close button var closeButton = 'Close' + ''; // Fill the sboverlay div sboverlay.html(							// Right section Close button							' ' + 								'' +									closeButton +								'' +							' ' + 							// Center section header							' ' + 								'<ul class="sboverlayPagelinks" style="margin-center:10px;list-style-type:none;list-style-image:none;display:inline;">' +									'Suggested Collaborators' +								'</ul>' +							' ' + 							// Table							' ' +							' ' +							' '); // Wait half a sec for images to load etc. b4 un-hiding sboverlay setTimeout(function{sboverlay.prop('hidden', false)},500); // Listen for TOC or other internal anchor clicks and adjust page scrolling to un-obscure the associated header $(window).on('hashchange', function{							adjustForHash;						}); // Run the scroll function once on load after additional half-second delay to display sboverlay in case we come in mid-page setTimeout(function{							scroll;							adjustForHash;						},500); function adjustForHash{ // If we're coming in mid-page due to an anchor link, make sure the anchored header isn't obscured by sboverlay if (window.location.hash) { // Get DOM version of the anchored header using [0], then use DOM method to get its viewport coordinates var anchorCoords = $('[id="' + window.location.hash.replace('#','') + '"]:last')[0].getBoundingClientRect; // If the pagetop links aren't in view and the anchored header is likely obscured by sboverlay, scroll up to reveal it								if (($('#p-namespaces ul li:above-the-top').length > 0) && (anchorCoords.bottom < 25)){ window.scrollBy(0, -sboverlayHeight - 5); }							}						}						// Set the function for scrolling $(window).scroll(function{							scroll;						}); // Use :above-the-top (from plugin below) to check for pagetop stuff outside window. If they're there, start the music. function scroll{ if ($('#p-namespaces ul li:above-the-top').length > 0){ sboverlay.css('top','0'); } else { sboverlay.css('top','-' + sboverlayHeight + 'px'); }						}						// Add the :above-the-top jQuery selector, which we use to check if user has scrolled past a certain point. function loadJQViewport{ /* Excerpt from http://www.appelsiini.net/projects/viewport, Copyright (c) 2008-2009 Mika Tuupola, MIT license: http://www.opensource.org/licenses/mit-license.php $(":above-the-top") */ (function($) {								$.abovethetop = function(element, settings){									var top = $(window).scrollTop;									return top >= $(element).offset.top + $(element).height - settings.threshold;								};								$.extend($.expr[':'], { "above-the-top": function(a, i, m) { return $.abovethetop(a, {threshold : 0}); }								});							})(jQuery); }	   	        }, true);	            }	            else {	                //alert("invalid id");	            }    	        }    	}    } ); } );