Jump to content

User:Twinzor/wikimark.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Twinzor (talk | contribs) at 15:46, 15 January 2009 (Removing some not needed code). 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!
//
//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-";
}

var wikimarklinkprefix = wgServer+wgScript;
var wikimarkEncodedUserName = encodeURIComponent(wgUserName);
 
addOnloadHook(WikiMarkInit);
 
function WikiMarkInit () {
    if(typeof WikimarkConfigViewNextTo == 'undefined') { 
        var viewNextto = '';
    }
    else {
        var viewNextto = document.getElementById(menuPrefixV+WikimarkConfigViewNextTo);
    }

    if(typeof WikimarkConfigAddNextTo == 'undefined') { 
        var addNextto = '';
    }
    else {
        var addNextto = document.getElementById(menuPrefix+WikimarkConfigAddNextTo);
    }
    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');
        jsMsg("'''"+wikimarkNewpage+"''' has been added to your WikiMarks.");
        iframe.style.display="none";
    };
    f.src=wikimarklinkprefix+"?title=User:"+wikimarkEncodedUserName+wikimarkspage+"&action=edit",document.body.appendChild(f);
};

// </nowiki>