User:Polygnotus/Scripts/NewCommentsNavigator.js
Appearance
From Wikipedia, the free encyclopedia
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.
This code will be executed when previewing this page.
Documentation for this user script can be added at User:Polygnotus/Scripts/NewCommentsNavigator.
// Wikipedia Highlighted Comments Navigator // Add to your common.js to navigate through unread highlighted comments $(document).ready(function(){ // Wait a bit for the page to fully load and highlights to be applied setTimeout(function(){ initCommentNavigator(); },1000); }); functioninitCommentNavigator(){ consthighlights=$('.ext-discussiontools-init-highlight'); // Only show navigator if there are more than 1 highlighted comment if(highlights.length<=1){ return; } letcurrentIndex=0; // Create navigation controls constnavHtml=` <div id="comment-navigator" style=" position: fixed; bottom: 0; left: 0; right: 0; background: #f8f9fa; border-top: 2px solid #a2a9b1; padding: 8px 20px; box-shadow: 0 -2px 4px rgba(0,0,0,0.1); z-index: 1000; font-size: 14px; display: flex; align-items: center; justify-content: center; gap: 15px; "> <button id="prev-comment" type="button" style=" background: #0645ad; color: white; border: none; border-radius: 3px; padding: 6px 12px; cursor: pointer; font-size: 14px; min-width: 60px; ">←</button> <span style=" font-weight: bold; color: #222; font-size: 16px; min-width: 80px; text-align: center; "><span id="comment-counter">1</span> / ${highlights.length}</span> <button id="next-comment" type="button" style=" background: #0645ad; color: white; border: none; border-radius: 3px; padding: 6px 12px; cursor: pointer; font-size: 14px; min-width: 60px; ">→</button> <button id="close-navigator" type="button" style=" background: #a2a9b1; color: #222; border: none; border-radius: 3px; padding: 4px 8px; cursor: pointer; font-size: 12px; margin-left: 20px; ">✕</button> </div> `; $('body').append(navHtml); // Function to update the current comment selection functionupdateSelection(index){ // Remove outline from all highlights highlights.css('outline',''); // Add outline to current highlight constcurrentHighlight=highlights.eq(index); currentHighlight.css('outline','3px solid #0645ad'); // Scroll to the current highlight $('html, body').animate({ scrollTop:currentHighlight.offset().top-100 },300); // Update counter $('#comment-counter').text(index+1); // Update button states $('#prev-comment').prop('disabled',index===0); $('#next-comment').prop('disabled',index===highlights.length-1); } // Initialize with first comment updateSelection(currentIndex); // Event handlers $('#prev-comment').click(function(e){ e.preventDefault(); e.stopPropagation(); if(currentIndex>0){ currentIndex--; updateSelection(currentIndex); } returnfalse; }); $('#next-comment').click(function(e){ e.preventDefault(); e.stopPropagation(); if(currentIndex<highlights.length-1){ currentIndex++; updateSelection(currentIndex); } returnfalse; }); $('#close-navigator').click(function(e){ e.preventDefault(); e.stopPropagation(); // Remove outlines and hide navigator highlights.css('outline',''); $('#comment-navigator').remove(); returnfalse; }); // Keyboard shortcuts $(document).keydown(function(e){ // Only work if navigator is visible and not typing in an input if($('#comment-navigator').is(':visible')&&!$(e.target).is('input, textarea')){ if(e.key==='ArrowUp'||e.key==='ArrowLeft'){ e.preventDefault(); $('#prev-comment').click(); }elseif(e.key==='ArrowDown'||e.key==='ArrowRight'){ e.preventDefault(); $('#next-comment').click(); }elseif(e.key==='Escape'){ e.preventDefault(); $('#close-navigator').click(); } } }); // Auto-hide after 30 seconds of inactivity lethideTimer=setTimeout(function(){ $('#comment-navigator').fadeOut(); },30000); // Reset timer on interaction $('#comment-navigator').on('mouseenter click',function(){ clearTimeout(hideTimer); $(this).fadeIn(); hideTimer=setTimeout(function(){ $('#comment-navigator').fadeOut(); },30000); }); console.log('Comment navigator initialized with '+highlights.length+' highlighted comments'); }