משתמש:חזרתי/Script 45.js

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

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

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
/** 45 סקריפט **/
/** צביעת שם המשתמש בדפי שיחה בצבע אדום **/
// שופץ על ידי [[משתמש:חיים 7]] ,[[en:User:ais523/highlightmyname2.js]] נוצר על ידי
/* (יש באג – הסקריפט צובע מחרוזת זהה לשם המשתמש או למחרוזת שהוגדרה לא רק בדפי שיחה אלא בכל רחבי מרחבי ויקיפדיה (לא כולל תפריטים וכותרות דפים */
/* הוספתי הגבלות למרחבי שם מסוימים – שורה ראשונה, שנייה, שלישית ואחרונה בסקריפט */

mw.util.addCSS( '.word7h {background-color:#FF0000!important; color:#FFFFFF !important;}' ); /* צביעת המחרוזת בלבן עם רקע אדום */
wordh="חזרתי"; /* קביעת המחרוזת שתיצבע */

/* התחלת הסקריפט */
$(function () {
    if (mw.config.get('wgNamespaceNumber') != "1" && mw.config.get('wgNamespaceNumber') != "3" && mw.config.get('wgNamespaceNumber') != "2600")
        return;  // restrict to Talk (1) and User talk (3) and Topic (NOSSE) (2600)

	var w7exception;
	try
	{
	  if(wordh===undefined||wordh===null) wordh="";
	}
	catch(w7exception)
	{
	  wordh="";
	}
	function highlightmyname(n,p) //node, parent node
	{
	  while(n!==null)
	  {
	    if(n.nodeType==3) //text node
	    {
	      if(n.data.toLowerCase().indexOf(wordh.toLowerCase())!=-1)
	      {
	        var ix=n.data.toLowerCase().indexOf(wordh.toLowerCase());
	        var t1=ix?document.createTextNode(n.data.substr(0,ix)):null;
	        var t2=document.createTextNode(n.data.substr(ix,wordh.length));
	        var t3=ix+wordh.length==n.data.length?null:
	          document.createTextNode(n.data.substr(ix+wordh.length));
	        var s1=document.createElement("span");
	        s1.style.color="#FF0000";
	        s1.className="word7h";
	        s1.appendChild(t2);
	        var s2=document.createElement("span");
	        if(t1!==null) s2.appendChild(t1);
	        s2.appendChild(s1);
	        if(t3!==null) s2.appendChild(t3);
	        p.replaceChild(s2,n);
	        if(t3!==null) highlightmyname(t3,s2); //find remaining occurences in the new nodes
	        n=s2.nextSibling;
	      }
	      else
	        n=n.nextSibling;
	    }
	    else
	    {
	      if(n.firstChild!==null) highlightmyname(n.firstChild,n);
	      n=n.nextSibling;
	    }
	  }
	}
	  
	$(function() {
	  // Don't run on pages that don't have bodyContent
	  if(document.getElementById('bodyContent') === null) {
	  	return;
	  }
	  
	  if(wordh==="") wordh=mw.config.get('wgUserName');
	  // The two occurrences of 'word7' in the following line are to prevent conflicts with
	  // other scripts I've written; don't change them to your own username (the script will
	  // change to your username automatically).
	  if(location.href.indexOf("?word7")==-1&&location.href.indexOf("&word7")==-1&&
	     location.href.indexOf("?action=edit")==-1&&location.href.indexOf("?action=submit")==-1&&
	     location.href.indexOf("&action=edit")==-1&&location.href.indexOf("&action=submit")==-1&&
	     location.href.indexOf("&action=raw")==-1&&mw.config.get('wgPageName')!="Special:Preferences")
	    highlightmyname(document.getElementById('bodyContent').firstChild,
	                    document.getElementById('bodyContent'));
	});

});