Zum Inhalt springen

„Benutzer:Revvar/wikibits.js“ – Versionsunterschied

aus Wikipedia, der freien Enzyklopädie
Inhalt gelöscht Inhalt hinzugefügt
Revvar (Diskussion | Beiträge)
+importJavascript & importCSS als verallgemeinertes und gesichertes importPage, basierend auf http://de.wikipedia.org/w/index.php?title=Benutzer:PDD/monobook.js&oldid=29273204
 
Revvar (Diskussion | Beiträge)
K Leerzeichen
Zeile 8: Zeile 8:
@param lang (optional) Language code of the corresponding wikipedia project. Default is the callers project.
@param lang (optional) Language code of the corresponding wikipedia project. Default is the callers project.
@return "true" on success, "false" otherwise
@return "true" on success, "false" otherwise
*/
*/

function importJavascript(page, lang)
function importJavascript(page, lang)
{
{
try {
try {
/* check the parameters and set defaults */
/* check the parameters and set defaults */
Zeile 34: Zeile 34:
return false;
return false;
}
}
}
}


/**
/**
Zeile 45: Zeile 45:
@param lang (optional) Language code of the corresponding wikipedia project. Default is the callers project.
@param lang (optional) Language code of the corresponding wikipedia project. Default is the callers project.
@return "true" on success, "false" otherwise
@return "true" on success, "false" otherwise
*/
*/

function importCSS(page, lang)
function importCSS(page, lang)
{
{
try {
try {
/* check the parameters and set defaults */
/* check the parameters and set defaults */
Zeile 71: Zeile 71:
return false;
return false;
}
}
}
}

Version vom 23. März 2007, 11:50 Uhr

/**
 Imports a user javascript page from any wikipedia project into the actual document.
 
 @version 0.1
 @date 2007/03/22
 @author: based on function importPage from [[de:User:PDD]]s monobook.js, extended by [[de:User:Revvar]]
 @param page Name of the user page without the "user:" prefix
 @param lang (optional) Language code of the corresponding wikipedia project. Default is the callers project.
 @return "true" on success, "false" otherwise
 */
 
 function importJavascript(page, lang)
 {
    try {
        /* check the parameters and set defaults */
        if(!page) throw("importJavascript: Missing parameter page.");
        if(!lang) lang = wgContentLanguage;
 
        /* create import url */
        var import_url = 'http://' + lang + '.wikipedia.org' + wgScriptPath + '/index.php?title=User:' + page +
           '&action=raw&ctype=text/javascript&smaxage=2678400&dontcountme=s';
 
        /* import page */
        var Head = document.getElementsByTagName('head').item(0);
        var Script = document.createElement('script');
        Script.setAttribute('type', 'text/javascript');
        Script.setAttribute('src', import_url);
        Script.setAttribute('charset', 'utf-8');
        Head.appendChild(Script);
 
        return true;
    } catch(e) {
        alert(e.message);
        return false;
    }
 }

/**
 Imports a user css page from any wikipedia project into the actual document.
 
 @version 0.1
 @date 2007/03/22
 @author: based on function importPage from [[de:User:PDD]]s monobook.js, rewritten by [[de:User:Revvar]]
 @param page Name of the user page without the "user:" prefix
 @param lang (optional) Language code of the corresponding wikipedia project. Default is the callers project.
 @return "true" on success, "false" otherwise
 */
 
 function importCSS(page, lang)
 {
    try {
        /* check the parameters and set defaults */
        if(!page) throw("importCSS: Missing parameter page.");
        if(!lang) lang = wgContentLanguage;
 
        /* create import url */
        var import_url = 'http://' + lang + '.wikipedia.org' + wgScriptPath + '/index.php?title=User:' + page +
           '&action=raw&ctype=text/css&smaxage=2678400&dontcountme=s';
 
        /* import page */
        var Head = document.getElementsByTagName('head').item(0);
        var CSS = document.createElement('style');
        CSS.setAttribute('type', 'text/javascript');
        CSS.setAttribute('charset', 'utf-8');
        CSS.appendChild(document.createTextNode("@import url(" + import_url + ");"));
        Head.appendChild(CSS);
 
        return true;
    } catch(e) {
        alert(e.message);
        return false;
    }
 }