User:Begoon/myGallery.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.
/*
	myGallery.js
        ------------
	Description: Adds a Tab to the Vector skin providing 1-click access to your own uploaded images, 
        using http://toolserver.org/~daniel/WikiSense/Gallery.php 
        Only written/tested for Vector skin.
*/
 
//function to find first 'ul' node in an element
 
function getFirstULchild(n)
{
x=n.firstChild;
while (x.tagName != 'UL')
  {
  x=x.nextSibling;
  }
return x;
}
 
//attach this whole event to Onload for page
 
addOnloadHook(function () {
 
// Create a <li> element, and an <a> element, and a <span> element, and set some properties
 
var liContainer = document.createElement("li");

// build and assign the url for the link
 
var myLink = document.createElement('a');
myLink.href = 'http://toolserver.org/~daniel/WikiSense/Gallery.php?wikifam=.wikipedia.org';
myLink.href += '&wikilang=en&order=-img_timestamp&img_user_text='
myLink.href += wgUserName; //currently logged in user
myLink.href += '&max=250&ofs=0&max=250';
 
var mySpan = document.createElement('span');
mySpan.innerHTML = 'My Gallery';
 
//nest the <span> in the <a>, then the <a> in the <li>
 
myLink.appendChild(mySpan);
liContainer.appendChild(myLink);
 
//insert the <li>, now containing both nested elements, into the DOM 
//it should be inserted before the watch/unwatch link/icon
 
y = (document.getElementById("ca-unwatch"));
if (!y) 
{
     y = (document.getElementById("ca-watch"));
}


if (y) 
{ 
getFirstULchild(document.getElementById("p-views")).insertBefore(liContainer,y);
}

});
 
/*
	END OF: myGallery.js
        --------------------       
*/