Jump to content

User:HectorMoffet/ShowOnlyToLoggedInUsers.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//------------------------------------------------------------------------
// To install this script, 
//
// 1)  Edit your common.js file by going to Special:MyPage/common.js
// 2)  Add the following line to that file: 
//         importScript('User:HectorMoffet/ShowOnlyToLoggedInUsers.js');
//------------------------------------------------------------------------
//
//
// ShowOnlyToLoggedInUsers.js
//
// This script will first check to see if the user is logged in.   
// If the user is logged in, 
//   the script will then show any HTML elements of the class "ShowOnlyToLoggedInUsers"
//
// Template:ShowOnlyToLoggedInUsers can be used to create such text.  

if ( mw.config.get( 'wgUserId' ) != null)  // If user is logged in
{
   // get all elements in the class 'ShowOnlyToLoggedInUsers'
   var ElementsToShow=document.getElementsByClassName('ShowOnlyToLoggedInUsers'); 
   
   // show those elements
   for(var i=0;i<ElementsToShow.length;i++) ElementsToShow[i].style.visibility="visible"; 
}