Jump to content

User:GeorgeMoney/UserScripts/helpers/all

From Wikipedia, the free encyclopedia

This is a list of helper functions needed for my scripts. To install, copy everything needed into your monobook.js:

Helpers:

[edit]

Cookies

[edit]
//COOKIE FUNCTIONS
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;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function eraseCookie(name) {
	createCookie(name,"",-1);
}

//END
[edit]

Note: This is not like the AdLiLinks from WP:US. This is much different.

//    --- ADD VARIOUS LINKS ----
if(!addToolBoxLink) {
function addToolboxLink(url, name, id){
    var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
    addlilink(tb, url, name, id);
}}
// 
if(!addTopLink) {
function addTopLink(url, name, id){
    var personal = document.getElementById('p-personal').getElementsByTagName('ul')[0];
    addlilink(personal, url, name, id);
}}
// 
if(!addNavLink) {
function addNavLink(url, name, id){
    var navigation = document.getElementById('p-navigation').getElementsByTagName('ul')[0];
    addlilink(navigation, url, name, id);
}}
// 
if(!addTab) {
function addTab(url, name, id, title, key){
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    return addlilink(tabs, url, name, id, title, key);
}}

if(!addLink) {
function addLink(where, url, name, id, title, key, after){
    //* where is the id of the toolbar where the button should be added;
    //   i.e. one of "p-cactions", "p-personal", "p-navigation", or "p-tb".
    //
    //* url is the URL which will be called when the button is clicked.
    //   javascript: urls can be used to do more complex things.
    //
    //* name is what will appear as the name of the button.
    //
    //* id is the id of the button; it's best to define one.  
    //   Use a prefix to make sure its unique. Optional.
    //
    //* title is the tooltip title that gives a longer description 
    //   of the button; if you define a accesskey, mention it here. Optional.
    //
    //* key is the char you want for the accesskey. Optional.
    //
    //* after is the id of the button you want to follow this one. Optional.
    //
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
    var tabs = document.getElementById(where).getElementsByTagName('ul')[0];
    if(after) {
        tabs.insertBefore(li,document.getElementById(after));
    } else {
        tabs.appendChild(li);
    }
    if(id) {
        if(key && title) { ta[id] = [key, title]; }
        else if(key) { ta[id] = [key, '']; }
        else if(title) { ta[id] = ['', title];} 
    }
    // re-render the title and accesskeys from existing code in wikibits.js
    akeytt();
    return li;
}}
if(!addlilink) {
function addlilink(tabs, url, name, id, title, key){
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    if(id)
    {
        if(key && title)
        {
            ta[id] = [key, title];
        }
        else if(key)
        {
            ta[id] = [key, ''];
        }
        else if(title)
        {
            ta[id] = ['', title];
        }
    }
    // re-render the title and accesskeys from existing code in wikibits.js
    akeytt();
    return li;
}}

Include

[edit]
function loadJS(s) {
    s = s.replace(/^\[\[/, '').replace(/\]\]$/, '').replace(" ", "_");
    document.write('<script type="text/javascript" src="'
             + 'http://wiki.riteme.site/w/index.php?title=' + s
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
}

function loadJSext(s) {
    document.write('<script type="text/javascript" src="'+ s + '"></script>');
}

function loadCSS(page){
  page=page.replace(" ", "_");
  document.write('<style type="text/css">@import "'+wgServer+wgScriptPath+'/index.php?title='+page+'&action=raw&ctype=text/css";</style>');
}
function loadCSSext(page){
  document.write('<style type="text/css">@import "'+page+'";</style>');
}