This is an old revision of this page, as edited by Gary(talk | contribs) at 19:23, 21 February 2014(This seems to do the trick?). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.Revision as of 19:23, 21 February 2014 by Gary(talk | contribs)(This seems to do the trick?)
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/comments in local time.js]] for now). FIXME Remove dependency on [[User:Gary/comments in local time.js]]. FIXME Fix on [[WP:RFA]] nominations (!votes, as in comments wrapped in <li>s).*/functioncommentHighlighter(){// Get the closest parent node for a comment.functionsortParents(a,b){returna[1]-b[1];}functiongetCommentParent(node,commentDivsExist){varpossibleParentNodes=['DD','DIV','LI','P'];varparent=node.parent();if(parent.parentsUntil('.diff').parent().hasClass('diff'))return$();elseif(commentDivsExist&&$.inArray(parent[0].nodeName,possibleParentNodes)>-1)returnparent;varpossibleParents=[];for(vari=0;i<possibleParentNodes.length;i++){varpossible=possibleParentNodes[i].toLowerCase();eval('var '+possible+' = node.parentsUntil(\''+possible+'\');');possibleParents.push([eval(possible).eq(0).parent(),eval(possible).length]);}possibleParents.sort(sortParents);if(possibleParents[0][1])parent=possibleParents[0][0];if(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;}else{returnparent;}}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,false);if(!parent.length)returntrue;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.varmyUsername=mw.config.get('wgUserName');varformattedUsername='User:'+myUsername.replace(/ /g,'_');varusernameBackground='#eef';if(myUsername=='Gary')varsecondUsername='User:Gary_King';elsevarsecondUsername;functionlinkLinksToUsername(username,link){if(link.attr('href').indexOf(username)>-1&&link.attr('href').indexOf(username)==(link.attr('href').length-username.length))returntrue;elsereturnfalse;}$('#bodyContent a').each(function(){varlink=$(this);varlinkIsGood=link&&link.attr('href');varusernameCheck=linkLinksToUsername(formattedUsername,link);if(secondUsername)varsecondUsernameCheck=linkLinksToUsername(secondUsername,link);elsevarsecondUsernameCheck=false;if(linkIsGood&&(usernameCheck||secondUsernameCheck)&&!link.parents('#contentSub').length){varparent=getCommentParent(link,true);if(!parent.length)returntrue;parent.css('background-color',usernameBackground);link.parentsUntil('.mw-content-ltr').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)||mw.config.get('wgPageName').indexOf('/Archive_')>-1;if(!isDiscussionPage)$.get(mw.config.get('wgScript')+'?title=User:Gary/discussion_pages.js&action=raw',checkIfDiscussionPage);elsecommentHighlighter();});