User:Parkerdr/popupBookmarks.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Parkerdr/popupBookmarks. |
//
//Extended bookmarks script, to accept the current page as the bookmarks page.
//
//any tables are hidden, and edit section (<span>s are hidden.
//
var myCookie = getCookie("roadmappage");
if (myCookie == null) {
validatePage();
} else
myBkmPagex = myCookie;
var myBkmURL = wgServer + wgArticlePath.replace('$1','') + myBkmPagex
if (doneOnloadHook) myBookmarksLoad()
else addOnloadHook(myBookmarksLoad)
function myBookmarksLoad() {
var obj_id = window.myBkmPlace || 'p-personal'
var obj = document.getElementById(obj_id)
if (!obj) return
var bkmLink
if (obj.className && obj.className == 'portlet') {
mw.util.addPortletLink(obj_id, myBkmURL, window.myBkmName || 'Bookmarks', 't-bkmmenu')
obj = document.getElementById('t-bkmmenu')
}
if (window.myBkmShowOnHover != 2) addHandler(obj, 'click', myBookmarks)
if (window.myBkmShowOnHover) addHandler(obj, 'mouseover', myBookmarks)
}
function myBookmarks(e){
if (e.preventDefault) e.preventDefault(); else e.returnValue = false //do not follow the link
if (!window.bkmMenu) myBookmarksIni()
bkmMenu.ShowHide(e)
return false
}
function myBookmarksIni(){
var ht = sajax_init_object()
ht.open('GET', myBkmURL + '?action=render', false)
ht.send(null)
bkmMenu = new mnuObj('papka', ht.responseText,
(window.myBkmHideOnHover!=2), window.myBkmHideOnHover)
if (window.myBkmNewWin){
var links = bkmMenu.div.getElementsByTagName('a')
for (var i=0; i<links.length; i++)
links[i].target = '_blank'
}
var tables = bkmMenu.div.getElementsByTagName('table')
for (var i=0; i< tables.length; i++) {
tables[i].style.display='none'
tables[i].width = 10
}
var spans = bkmMenu.div.getElementsByTagName("span");
for (var j = 0; j < spans.length; j++)
{
if (spans[j].className == "editsection")
{
spans[j].style.display='none'
}
}
var links = bkmMenu.div.getElementsByTagName('a');
var home = window.location.pathname.substring(1).replace (/ /, "_");
for (var i=0; i<links.length; i++)
if (links[i].pathname.replace (/ /, "_") == home) {
links[i].style.backgroundColor = 'yellow'
}
//else bkmMenu.div.innerHTML += '<br>' + links[i].pathname + ' ' + window.location.pathname
bkmMenu.div.innerHTML += '<div style="text-align:right">[<a href="' + myBkmURL + '">page</a>]'
+ ' [<a href="' + myBkmURL + '?action=edit">edit</a>] [<a href="' + wgServer + wgArticlePath.replace('$1','') + 'User:Parkerdr/popupBookmarks">help</a>]<br> [<a href="#" onClick="javascript:setRoadMap();return 0;">use current page</a>] [<a href="#" onClick="javascript:resetRoadMap();return 0;">/bookmarks</a>]</div>'
}
/* MENU */
function mnuObj(id, html, isMouseUp, isMouseOut) {
var d = document.createElement('div')
d.id=id
d.className = 'menudiv'
d.innerHTML=html
d.style.display='none'
d.style.position='absolute'
d.style.padding='5px'
d.style.border='3px outset'
d.style.zIndex = '50'
d.style.backgroundColor='#EEEEEE'
document.body.appendChild(d)
this.div = d
this.div.obj = this //backlink
this.Hide = function (){
this.div.style.display = 'none'
}
this.ShowHide = function (e){
if (this.div.style.display == 'block') this.Hide()
else this.Show(e)
}
this.Show = function (e){
this.div.style.display = 'block'
var e = e || window.event
if (!e) return
var coords = getMousePos(e)
var posx = coords[0], posy = coords[1]
this.div.style.top = posy + 5 + 'px'
posx -= elementWidth(this.div)/2
if (posx + elementWidth(this.div) > windowWidth()) posx = windowWidth() - elementWidth(this.div) - 20
else if (posx < 0) posx = 10
this.div.style.left = posx + 'px'
}
this.hideOnMouseUp = function (e){
var e = e || window.event
if ((e.which && e.which == 3) || (e.button && e.button == 2)) return //except right-click
var targ = e.srcElement || e.target
while (targ && (!targ.className || targ.className != 'menudiv')) targ = targ.parentNode
if (!targ) return
targ.style.display = 'none'
}
this.hideOnMouseOut = function(e){
var e = e || window.event
var targ = e.srcElement || e.target
while (targ && (!targ.className || targ.className != 'menudiv')) targ = targ.parentNode
if (!targ) return
var toEl = e.toElement || e.relatedTarget
while (toEl && toEl != targ && toEl.nodeName != 'BODY') toEl = toEl.parentNode
if (toEl == targ) return
targ.style.display = 'none'
}
if (isMouseUp) addHandler(this.div, 'mouseup', this.hideOnMouseUp)
if (isMouseOut) addHandler(this.div, 'mouseout', this.hideOnMouseOut)
}
/*API */
function windowWidth(){
if (self.innerWidth) // all except Explorer
return self.innerWidth
else if (document.documentElement && document.documentElement.clientWidth)// Explorer 6 Strict Mode
return document.documentElement.clientWidth
else if (document.body) // other Explorers
return document.body.clientWidth
else return 0
}
function elementWidth(el){
return Math.max(el.scrollWidth, el.offsetWidth)
}
function getMousePos(ev){
var posx = 0; var posy = 0
if (ev.pageX)
return [ev.pageX, ev.pageY]
else if (ev.clientX)
return [ev.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
ev.clientY + document.body.scrollTop + document.documentElement.scrollTop]
else return null
}
function setRoadMap() {
var expdate = new Date();
var where = window.location.pathname;
if (where.substring(0,6) == "/wiki/")
where = where.substring(6);
expdate.setMonth(expdate.getMonth()+1);
setCookie ("roadmappage", where, expdate, "/");
myBkmPagex = where;
myBkmURL = wgServer + wgArticlePath.replace('$1','') + myBkmPagex;
bkmMenu = null;
}
function resetRoadMap(){
var expdate = new Date();
setCookie ("roadmappage", "", expdate, "/");
validatePage();
bkmMenu = null;
}
function validatePage() {
if (!window.myBkmPage)
myBkmPagex = '/Bookmarks';
else
myBkmPagex = myBkmPage;
if (myBkmPagex.charAt(0)=='/') myBkmPagex = 'User:' + wgUserName + myBkmPagex
myBkmURL = wgServer + wgArticlePath.replace('$1','') + myBkmPagex;
}
// name - name of the cookie
// * return string containing value
// of specified cookie or null if cookie
// does not exist
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex +
prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex +
prefix.length,
cookieEndIndex))
}
function setCookie (sName, vValue)
{
var argv = setCookie.arguments, argc = setCookie.arguments.length;
var sExpDate = (argc > 2) ? "; expires="+argv[2].toGMTString() : "";
var sPath = (argc > 3) ? "; path="+argv[3] : "";
var sDomain = (argc > 4) ? "; domain="+argv[4] : "";
var sSecure = (argc > 5) && argv[5] ? "; secure" : "";
document.cookie = sName + "=" + escape(vValue,0) + sExpDate + sPath + sDomain + sSecure + ";";
}