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

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

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

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
/* change recent changes or watch list to patroll mode
   written by [[User:Mikimik]] */
function initPatrolMode()
{
 try
  {
    var knownUsers = new Array();

    nonflaggedBots = "|Dxar|Michael Kühntopf|Jhendin|Cekli829|Asfarer|Ev|Istcol|Nipisiquit|Mutari|Dinamik-bot|JCIV|" +  // bots without a bot flag
                     "Bjankuloski06he|Ashot Gabrielyan|Ver-bot|Gemini1980|Wikix|TjBot|JhsBot|BOTijo|" +
                     "Sverigekillen|MrPanyGoff|Zil|Cekli829|Jackie|Gleb Borisov|Mahmudmasri|";   // non bot users from foreign wikis working like a bot

//---
    var lines = document.getElementById("bodyContent").getElementsByTagName("li");
    var keeppage = new Array();
    var keepline = null;
    var topEditByBot = new Array();
    var originalNumberOfLines = lines.length;

    for ( var i = 0 ; i < lines.length ; )
        if ( !/\beditaction\b/.test(lines[i].className) || !lines[i].getElementsByClassName("mw-userlink")[0] )
            lines[i].parentNode.removeChild ( lines[i] );               // if it's not an edit or the user name was removed - remove the line
         else
        {
            var title = lines[i].pagetitle;                                                         // get page title from the line
            var username = lines[i].getElementsByClassName("mw-userlink")[0].firstChild.nodeValue;  // get the user name from the user link

            if ( topEditByBot[title] )                                            // the top edit was deleted because it was a bot edit
            {
                topEditByBot[title] = false;
                lines[i].className = lines[i].className.replace ( "nontopedit", "topedit" );  // so this line becomes the new top edit
            }

            if ( nonflaggedBots.indexOf("|" + username + "|") != -1 )        // -- bot edit --
            {
                 keepline = false;                                           // delete line. don't change keeppage
                 if ( /\btopedit\b/.test(lines[i].className) )               // and, if this line is the top edit:
                     topEditByBot[title] = true;                             // mark it so the next line will become top edit
            }
             else if ( /\bunpatrolledaction\b/.test(lines[i].className) &&                 // line wasn't patrolled yet
                       ( /\btopedit\b/.test(lines[i].className) || keeppage[title] ) &&    // it's a top edit or a page I wanna keep checking
                                                                                           // it's not certain uninteresting pages
                       !/^ויקיפדיה:(ארגז חול|בקשות ממפעילים|דלפק ייעוץ|הכה את המומחה|ייעוץ.*|כיכר העיר|לוח מודעות|מזנון|מפעיל נולד|סדנה לגרפיקה|ספר אורחים|פרלמנט)$/.test(title) )
            {
                if ( /^[0-9\.]+$/.test(username) )                           // -- IP edit --
                {
                    keepline = true;
                    lines[i].className += " IPuserEdit";
                }
                 else                                                        // not IP or bot - check if it's a known user
                {
                    for ( var k = 0 ; k < knownUsers.length ; k++ )
                        if ( knownUsers[k][0].indexOf("|" + username + "|") != -1 ) break;
                    keepline = k == knownUsers.length;
                }

                if ( keepline && title.indexOf(":") != -1 )                  // find edits of a user in his user or user talk namespaces
                    if ( new RegExp("^(" + wgFormattedNamespaces[2] + "|" + wgFormattedNamespaces[3] + "):" + username + "(\\/|$)").test(title) )
                        keepline = false;

                keeppage[title] = keepline;
            }
             else
            {
                keepline = false;
                keeppage[title] = false;
            }

            if ( !keepline ) lines[i].parentNode.removeChild ( lines[i] );
             else i++;
        }

    customizeWLRC.mergeChangesLists();                                // merge lists

    document.getElementById("mergedListTitle").appendChild ( document.createTextNode(" (" + originalNumberOfLines + " -> " + i + ")") );
    appendCSS ( "#content { background-color:#F8DFFF !important; } .IPuserEdit { background-color:#FFFFDD } abbr.unpatrolled { display:none; }" );
  }
 catch(e)
  {
    return;        // lets just ignore what's happened
  }
}

function createPatrolModeButton()
{
    function addInputToForm ( name, value )
    {
        var input = document.createElement("INPUT");
        input.type = "hidden";
        input.name = name;
        input.value = value;
        boxform.appendChild ( input );
    }

 try
  {
    var point = document.getElementById("localInfoTogglesHolder");
    if ( !point ) point = document.getElementById("firstHeading");
    if ( !point ) return;

    var aNode = document.createElement("a");
    aNode.id = "patrolModeButton";
    aNode.href = wgScript + "?title=Special:" + wgCanonicalSpecialPageName +
                 ( getParamValue("from") ? "&from=" + getParamValue("from") : "" ) +
                 ( wgCanonicalSpecialPageName == "Recentchanges" ? "&limit=" + ( getParamValue("limit") ? getParamValue("limit") : "500" ) : "" ) +
                 ( getParamValue("days") ? "&days=" + getParamValue("days") : wgCanonicalSpecialPageName == "Recentchanges" ? "&days=30" : "" ) +
                 ( getParamValue("namespace") ? "&namespace=" + getParamValue("namespace") : "" ) +
                 ( getParamValue("invert") ? "&invert=" + getParamValue("invert") : "" ) +
                 ( getParamValue("patrolMode") ? "" : wgCanonicalSpecialPageName == "Recentchanges" ?
                   "&patrolMode=yes&hideminor=0&hidebots=1&hideanons=0&hideliu=0&hidepatrolled=0&hidemyself=0" :
                   "&patrolMode=yes&hideMinor=0&hideBots=1&hideAnons=0&hideLiu=0&hideOwn=0&hidePatrolled=0"      );
    aNode.title = getParamValue("patrolMode") ? "עזוב מצב ניטור" : "הפעל מצב ניטור";
    aNode.appendChild ( document.createTextNode(aNode.title) );

    point.appendChild ( document.createTextNode("[") );
    point.appendChild ( aNode );
    point.appendChild ( document.createTextNode("]") );

//---
    if ( !getParamValue("patrolMode") ) return;

    var box = document.getElementsByTagName("FIELDSET")[0];
    for ( var item = box.firstChild ; item.nodeName != "A" ; ) item = item.nextSibling;  // find the first link
    for ( ; item.nodeName != "BR" ; item = item.nextSibling )                            // fix all links until the linebreak
        if ( item.nodeName == "A" && /^http:\/\//.test(item.href) )
            if ( /&limit=\d+/.test(item.href) )                                          // a recent changes link
            {
                var from = /&from=\d+/.test(item.href) ? item.href.match(/(&from=\d+)/)[1] : "";
                if ( item.href.match(/&limit=(\d+)/)[1] == getParamValue("limit") && /&days=\d+/.test(item.href) )
                    item.href = window.location.href.replace(/&days=\d+/,item.href.match(/(&days=\d+)/)[1]);
                 else item.href = window.location.href.replace(/&limit=\d+/,item.href.match(/(&limit=\d+)/)[1]);
                if ( from ) item.href = item.href.replace(/(&from=\d+|(&limit=))/,from + "$2");
            }
             else item.href = window.location.href.replace(/&days=\d+(\.\d+)?/,item.href.match(/(&days=\d+(\.\d+)?)/)[1]);

    while ( !item.nextSibling.tagName || ( item.nextSibling.tagName != "HR" && item.nextSibling.tagName != "FORM" ) )
        box.removeChild ( item.nextSibling );                                    // remove wiki-generated "hide/display" links
    box.removeChild ( item );                                                    // remove the linebreak

    var boxform = box.getElementsByTagName("FORM")[0];                           // add the following parameters to the "namespace" select list
    addInputToForm ( "patrolMode", "yes" );
    addInputToForm ( wgCanonicalSpecialPageName == "Recentchanges" ? "hideminor"     : "hideMinor"    , "0" );
    addInputToForm ( wgCanonicalSpecialPageName == "Recentchanges" ? "hidebots"      : "hideBots"     , "1" );
    addInputToForm ( wgCanonicalSpecialPageName == "Recentchanges" ? "hideanons"     : "hideAnons"    , "0" );
    addInputToForm ( wgCanonicalSpecialPageName == "Recentchanges" ? "hideliu"       : "hideLiu"      , "0" );
    addInputToForm ( wgCanonicalSpecialPageName == "Recentchanges" ? "hidepatrolled" : "hidePatrolled", "0" );
    addInputToForm ( wgCanonicalSpecialPageName == "Recentchanges" ? "hidemyself"    : "hideOwn"      , "0" );
  }
 catch(e)
  {
    return;        // lets just ignore what's happened
  }
}

if ( wgServer == "http://he.wikipedia.org" && ( wgCanonicalSpecialPageName == "Recentchanges" || wgCanonicalSpecialPageName == "Watchlist" ) )
{
    addOnloadHook ( createPatrolModeButton );
    if ( getParamValue("patrolMode") ) addOnloadHook ( function() { setTimeout("initPatrolMode();",5000); } );
}