User:Twinzor/wikimarkbeta.js

This is an old revision of this page, as edited by Twinzor (talk | contribs) at 04:35, 15 January 2009 (Making sure it works). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
//<nowiki>
//WikiMark
//
//A bookmarking tool for Wikipedia.
//
//By User:Twinzor on enwp.
//
//99% of the code is copied from other scripts on WP.
//
//If you improve my sloppy code, I would
//appreaciate it if you could drop me
//a line on my talkpage. Thanks!
//
//To configure the script for yourself, you'll
//first have to copy it to a user subpage of
//you own.
//
//Script doesn't work in IE, so prevent it from loading alltogether.

var browser = navigator.appName;
//if (browser != "Explorer") {

//Reading configuration or setting defaults if not present:

if(typeof WikimarkConfigWikimarksPage == 'undefined') {
    var wikimarkspage = "/WikiMarks";
}
else {
    var wikimarkspage = "/"+WikimarkConfigWikimarksPage;
}

if(typeof WikimarkConfigListType == 'undefined') {
    var listtype = "*";
}
else {
    var listtype = WikimarkConfigListType;
}

if(typeof WikimarkConfigAddMenu == 'undefined') { 
    var addMenulocation = "p-cactions";
    var menuPrefix = "ca-";
}
else if( WikimarkConfigAddMenu == "cactions" ) {
    var addMenulocation = "p-cactions";
    var menuPrefix = "ca-";
} 
else if( WikimarkConfigAddMenu == "personal" ) {
    var addMenulocation = "p-personal";
    var menuPrefix = "pt-";
} 
else if( WikimarkConfigAddMenu == "toolbox" ) {
    var addMenulocation = "p-tb";
    var menuPrefix = "t-";
} 
else if( WikimarkConfigAddMenu == "navigation" ) {
    var addMenulocation = "p-navigation";
    var menuPrefix = "n-";
} 
else {
    var addMenulocation = "p-cactions";
    var menuPrefix = "ca-";
}

if(typeof WikimarkConfigViewMenu == 'undefined') { 
    var viewMenulocation = "p-cactions"; 
    var menuPrefixV = "ca-";
}
else if( WikimarkConfigViewMenu == "cactions" ) {
    var viewMenulocation = "p-cactions";
    var menuPrefixV = "ca-";
} 
else if( WikimarkConfigViewMenu == "personal" ) {
    var viewMenulocation = "p-personal";
    var menuPrefixV = "pt-";
} 
else if( WikimarkConfigViewMenu == "toolbox" ) {
    var viewMenulocation = "p-tb";
    var menuPrefixV = "t-";
} 
else if( WikimarkConfigViewMenu == "navigation" ) {
    var viewMenulocation = "p-navigation";
    var menuPrefixV = "n-";
} 
else {
    var viewMenulocation = "p-cactions";
    var menuPrefixV = "ca-";
}

if(typeof WikimarkConfigViewNextTo == 'undefined') { 
    var viewNextto = '';
}
else {
    var viewNextto = document.getElementById("p-personal");
//    var viewNextto = document.getElementById(WikimarkConfigViewNextTo);
//    var viewNextto = menuPrefixV+WikimarkConfigViewNextTo;
}

if(typeof WikimarkConfigAddNextTo == 'undefined') { 
    var addNextto = '';
}
else {
    var addNextto = document.getElementById(WikimarkConfigAddNextTo);
//    var addNextto = menuPrefix+WikimarkConfigAddNextTo;
}


var wikimarklinkprefix = wgServer+wgScript;
var wikimarkEncodedUserName = encodeURIComponent(wgUserName);
 
addOnloadHook(WikiMarkInit);
 
function WikiMarkInit () {
    var viewNextto = document.getElementById(menuPrefixV+WikimarkConfigViewNextTo);
    jsMsg(WikimarkConfigViewNextTo+" "+viewNextto);
    addPortletLink (addMenulocation, 'javascript:doAddWikiMark()', 'WikiMark', menuPrefix+'addwikimark', 'WikiMark this page', '', addNextto);
    addPortletLink (viewMenulocation, wikimarklinkprefix+"?title=User:"+wikimarkEncodedUserName+wikimarkspage, 'My WikiMarks', menuPrefixV+'showwikimark', 'Open your WikiMarks', '', viewNextto);
}
 
function doAddWikiMark () {
    var wikimarkNewpage = wgPageName.replace("_", " ");
    var f;
    f=document.createElement("IFRAME");
    f.id="WikiMarksLoader";
    f.onload=function() {
        var wikimark_cmt = "Adding [["+wikimarkNewpage+"]] to my WikiMarks list. (Using [[User:Twinzor/Wikimark|WikiMark]])";
        e=f.contentWindow.document.editform,e.wpTextbox1.value+=listtype+"["+"["+wikimarkNewpage+"]"+"]\n",e.wpSummary.value=wikimark_cmt,e.wpSave.click();
        var iframe = document.getElementById('WikiMarksLoader');
        if (browser=="Safari") {        
            iframe.style.display="none";
        }
        else {
            iframe.parentNode.removeChild(iframe);
        }
        jsMsg("'''"+wikimarkNewpage+"''' has been added to your WikiMarks.");
    };
    f.src=wikimarklinkprefix+"?title=User:"+wikimarkEncodedUserName+wikimarkspage+"&action=edit",document.body.appendChild(f);
};

//}

// </nowiki>