משתמש:Mikimik/js/customizeTabs.js

מתוך ויקיפדיה, האנציקלופדיה החופשית

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
/* add a tab to edit the first section of the page (section 0)                   */
/* based on [[w:he:MediaWiki:Gadget-editIntro.js]], extended by [[User:Mikimik]] */
function addEditFirstSection()
{
 try {
    var caEdit = document.getElementById("ca-edit");
    if ( !caEdit || document.getElementById("ca-edittop") ) return;
    if ( !new RegExp("&action=edit(&oldid=" + wgCurRevisionId + ")?$").test(caEdit.getElementsByTagName("a")[0].href) ) return; // is it a normal edit ?

    var section0Link = document.createElement("a");                            // create 0-link element
    section0Link.appendChild ( document.createTextNode("0") );
    section0Link.href = caEdit.getElementsByTagName("a")[0].href + "&section=0";
    section0Link.title = wgUserLanguage == "he" ? "עריכת ההקדמה" : "edit head section";

    var caEditSection0 = document.createElement("li");                         // create 0-list element
    caEditSection0.id = "ca-edittop";
    caEditSection0.appendChild (section0Link);

    caEdit.parentNode.insertBefore (caEditSection0, caEdit.nextSibling);       // add "0" tab after "edit" tab

    if ( /&action=edit&section=0$/.test(window.location.href) )                // if I'm editing section 0 now
    {                                                                          // then mark "0" as seleted:
        caEditSection0.className = caEdit.className;                           // copy original classes from caEdit
        caEdit.className = "";                                                 // and remove them from caEdit
                                                                               // add summary
        document.getElementById("wpSummary").value = ( wgContentLanguage == "he" ? "/* עריכת ההקדמה */ " : "/* head section */ " ) +
                                                     document.getElementById("wpSummary").value;
    }
  }
 catch (e)
  {
    return;        // lets just ignore what's happened
  }
}

if ( wgArticleId ) addOnloadHook ( addEditFirstSection );


/* add a link to the "history" tab to watch the last difference in the page */
/* written by [[User:Mikimik]]  */
function addLastDifferenceLink()
{
 try {
    var caHistory = document.getElementById("ca-history");
    if ( !caHistory || !caHistory.getElementsByTagName("a")[0] ) return;

    addLinktoTab( caHistory, "#",
                  wgAction == "rollback" && document.getElementById("mw-returnto")
                  ? caHistory.getElementsByTagName("a")[0].href.replace("&action=history", "&diff=next&oldid=" + wgCurRevisionId )
                  : caHistory.getElementsByTagName("a")[0].href.replace("&action=history", "&diff=" + wgCurRevisionId + "&oldid=prev"),
                  wgUserLanguage == "he" ? "שינוי אחרון בדף זה" : "last change" );

/*    addLinktoTab( caHistory, "P",
                  caHistory.getElementsByTagName("a")[0].href.replace("&action=history", "&action=purge"),
                  "purge" );*/
  }
 catch (e)
  {
    return;        // lets just ignore what's happened
  }
}

$ ( addLastDifferenceLink );


/* add a "catscan" tab to categories */
/* adapted from [[commons:MediaWiki:Extra-tabs.js]] */
function addCatScanTab()
{
 try {
    addPortletLink ( "p-cactions",
                     "http://toolserver.org/~daniel/WikiSense/CategoryIntersect.php?wiki=" + wgServer.replace("http://","") +
                     "&basecat=" + encodeURIComponent(wgTitle),
                     "catscan" );
  }
 catch (e)
  {
    return;        // lets just ignore what's happened
  }
}

if ( wgNamespaceNumber == 14 ) addOnloadHook ( addCatScanTab );


/* add a link to the "page" tab to watch the statistics of the page */
/* written by [[User:Mikimik]]  */
function addStatisticsLink()
{
 try {
    var myDate = new Date();
    addLinktoTab ( document.getElementById("p-cactions").getElementsByTagName("li")[0], "#",
                   "http://stats.grok.se/" + wgContentLanguage + (wgDBname.indexOf("quote") == -1 ? "" : ".q") + "/" +
                   myDate.getFullYear() + (myDate.getMonth() < 9 ? "0" : "") + (myDate.getMonth()+1) + "/" + encodeURIComponent(mw.config.get('wgPageName')),
                   "traffic statistics" );
  }
 catch (e)
  {
    return;        // lets just ignore what's happened
  }
}

if ( wgNamespaceNumber >= 0 ) addOnloadHook ( addStatisticsLink );


/* add a "sysop stats" tab to the main page - to see sysop statistics for the local wiki */
function addSysopStatsTab()
{
 try {
                                                 // check if the interwiki points to a main page (or crash if there's no interwiki)
    if ( /\/wiki\/$/.test(document.getElementById("p-lang").getElementsByTagName("li")[0].getElementsByTagName("a")[0].href) )
        addPortletLink ( "p-cactions", "http://toolserver.org/~vvv/adminstats.php?wiki=" + wgDBname + "_p&tlimit=none",
                         wgUserLanguage == "he" ? "סטט' מפעילים" : "sysop stats" );
  }
 catch (e)
  {
    return;        // lets just ignore what's happened
  }
}

if ( ( wgNamespaceNumber == 0 || wgNamespaceNumber == 4 || wgNamespaceNumber == 100 ) && wgAction == "view" ) addOnloadHook ( addSysopStatsTab );


/*
 * Colors the "edit" tab according to the protection level:
 * light yellow: semi protection.
 * light pink: full protection.
 * gray: full move-protected (no edit protection)
 * light blue: semi move-protected (no edit protection)
 * green: create protection
 *
 * from [[w:he:User:Yonidebest/monobook.js/colorProtected.js]]
 * extended and fixed by [[he:User:Mikimik]]
 */
function TabColorProtected()
{
 try {
    var caEditTab = document.getElementById("ca-edit");                       /* get "edit" tab */
    if ( !caEditTab ) caEditTab = document.getElementById("ca-viewsource");   /* if not, get "viewsource" tab */
    if ( !caEditTab ) return;                                                 /* if not, exit */

    var caEdit = caEditTab.getElementsByTagName("a")[0];
    var tabcolor = "#000000";                                 /* error (black) */

    if ( wgRestrictionEdit[0] || wgRestrictionMove[0] )       /* page is edit or move protected */
    {
        if ( wgRestrictionEdit[0] && wgRestrictionEdit[0] == "autoconfirmed" )
          tabcolor = "#FCFF00";                                                      /* light yellow */
         else if ( wgRestrictionEdit[0] && wgRestrictionEdit[0] == "sysop" )
                tabcolor = "#FFA9E5";                                                /* light pink */
          else if ( wgRestrictionMove[0] && wgRestrictionMove[0] == "autoconfirmed" )
                 tabcolor = "#CCFFFF";                                               /* light blue */
           else if ( wgRestrictionMove[0] && wgRestrictionMove[0] == "sysop" )
                  tabcolor = "#AFAFAF";                                              /* gray */
    }
    else if ( document.getElementsByClassName("mw-titleprotectedwarning")[0] )       /* title is protected */
    {
        tabcolor = "#00FF00";                                                        /* green */
    }
    else return;

    caEdit.style.backgroundColor = tabcolor;
    caEditTab.style.backgroundColor = tabcolor;
  }
 catch (e)
  {
    return;        // lets just ignore what's happened
  }
}

if ( wgNamespaceNumber >= 0 ) addOnloadHook ( TabColorProtected );


/* duplicate tabs at bottom with id "mytabs" */
/* from [[w:en:Wikipedia:WikiProject User scripts/Scripts/Duplicate tabs at bottom]] */
function createMyTabs()
{
 try {
    var tabs = document.getElementById("p-cactions").cloneNode(true);
    tabs.id = "mytabs";

    var items = tabs.getElementsByTagName("li");
    for ( i = 0 ; i < items.length ; i++ )
        if ( items[i].id ) items[i].id = "mytabs-" + items[i].id;

    var content = document.getElementById("content");              // find the content div
    content.parentNode.insertBefore (tabs, content.nextSibling);   // place tab list right after content div
  }
 catch(e)
  {
    return;        // lets just ignore what's happened
  }
}

$ ( createMyTabs );


/* general purpose function - add a link inside a tab */
function addLinktoTab ( tab, linktext, linkhref, linktitle )
{
    var lastlink = tab.lastChild;

    var newlink = document.createElement("a");
    newlink.innerHTML = linktext;
    newlink.href = linkhref;
    newlink.title = linktitle;

// ********** the padding change works nicely only if there is one link in the tab ****************

    var tspace = /\bselected\b/.test(tab.className) ? "1" : "0.8";            // different style if the tab is selected or not

    if ( wgUserLanguage == "he" )
    {
        newlink .style.cssText = "padding: 0            0.1em   0 " + tspace + "em !important;";   // top, right, bottom, left
        lastlink.style.cssText = "padding: 0 " + tspace + "em   0            0.1em !important;";
    }
    else
    {
        newlink .style.cssText = "padding: 0 " + tspace + "em 0            0.1em !important;";     // top, right, bottom, left
        lastlink.style.cssText = "padding: 0            0.1em 0 " + tspace + "em !important;";
    }

    tab.appendChild ( newlink );

    return newlink;
}