This is an old revision of this page, as edited by Gary(talk | contribs) at 15:57, 19 April 2011(outsource discussion pages). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.Revision as of 15:57, 19 April 2011 by Gary(talk | contribs)(outsource discussion pages)
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page.
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.
/* COMMENT HIGHLIGHTER Description: Highlights recent comments yellow, while your own comments are highlighted in blue. (Requires [[User:Gary King/comments in local time.js]] for now). FIXME Remove dependency on [[User:Gary King/comments in local time.js]]. FIXME Fix on [[WP:RFA]] nominations (!votes, as in comments wrapped in <li>s).*/if(typeof(unsafeWindow)!='undefined'){varaddOnloadHook=unsafeWindow.addOnloadHook;varmw=unsafeWindow.mw;}functioncommentHighlighter(){// Get the closest parent node for a comment.functionsortParents(a,b){returna[1]-b[1];}functiongetCommentParent(node,commentDivsExist){varparent=node.parent();if(parent.parentsUntil('.diff').parent().hasClass('diff'))return$();elseif(commentDivsExist&&(parent[0].nodeName=='DD'||parent[0].nodeName=='P'||parent[0].nodeName=='DIV'))returnparent;vardiv=node.parentsUntil('div');vardd=node.parentsUntil('dd');varp=node.parentsUntil('p');varpossibleParents=[[div.eq(0).parent(),div.length],[dd.eq(0).parent(),dd.length],[p.eq(0).parent(),p.length]];possibleParents.sort(sortParents);if(possibleParents[0][1])parent=possibleParents[0][0];elseif(parent.length&&!commentDivsExist&&parent.contents().length){varnewParent=$('<div class="comment"></div>');parent.contents().each(function(){varnode=$(this);if(node[0].nodeName=='DL')returnfalse;newParent.append(node);});parent.prepend(newParent);returnnewParent;}elsereturnparent;}functioncalculateColorRatio(maxTime,minPercentage,maxPercentage,timestamp){vartoday=newDate();minPercentage=minPercentage/100;maxPercentage=maxPercentage/100;varcolorRatio=((maxPercentage-minPercentage)*((today.getTime()-timestamp.getTime())/maxTime)+minPercentage)*100;if(colorRatio<minPercentage)colorRatio=minPercentage;returncolorRatio;}varmaxTime=1000*60*60*24;// Highlight messages posted today. (REQUIRES [[WP:COMMENTS IN LOCAL TIME]] SCRIPT)$('span.localcomments').each(function(){vartimestamp=$(this);vartimestampValue=parseInt(timestamp.attr('timestamp'));varparent=getCommentParent(timestamp);parent.attr('title',timestamp.text());if((newDate()).getTime()-timestampValue<maxTime){varcolorRatio=calculateColorRatio(maxTime,50,100,newDate(timestampValue));parent.css('background-color','rgb(100%, 100%, '+colorRatio+'%)');}});// Highlight discussion sections that I am linked from (i.e. that I participated or was mentioned in).// Also highlight the line itself.varformattedUsername='User:'+mw.config.get('wgUserName').replace(/ /g,'_');varusernameBackground='#eef';$('#bodyContent a').each(function(){varlink=$(this);if(link.attr('href').indexOf(formattedUsername)!=-1&&link.attr('href').indexOf(formattedUsername)==(link.attr('href').length-formattedUsername.length)&&!link.parents('#contentSub').length){varparent=getCommentParent(link,true);if(!parent.length)returntrue;parent.css('background-color',usernameBackground);link.parentsUntil('#bodyContent').last().prevUntil('h2').last().prev().css('background-color',usernameBackground);}});}functioncheckIfDiscussionPage(data){eval(data);if($.inArray(mw.config.get('wgPageName').split('/')[0].replace(/_/g,' '),discussionPages)!=-1)commentHighlighter();}// addOnloadHook required since this depends on Comments in Local Time.addOnloadHook(function(){if(mw.config.get('wgAction')!='view')returnfalse;// check if this is a discussion pagevarisDiscussionPage=mw.config.get('wgCanonicalNamespace').indexOf('talk')!=-1||mw.config.get('wgCanonicalNamespace').indexOf('Talk')!=-1||($('#ca-addsection').length?true:false);if(!isDiscussionPage)$.get(mw.config.get('wgScript')+'?title=User:Gary_King/discussion_pages.js&action=raw',checkIfDiscussionPage);elsecommentHighlighter();});