User:Polygnotus/Scripts/ReferenceHighlighter.js: Difference between revisions

Content deleted Content added
Created page with '// Wikipedia Reference Highlighter $(function() { // Function to highlight all references with the same base ID function highlightReferences(baseId) { // Remove previous highlights $('.reference-highlight').removeClass('reference-highlight'); // Highlight all references with the same base ID $('sup.reference a[href^="#cite_note-' + baseId + '"]').each(function() { $(this).closest('sup').addClass('...'
 
also highlight a b c
Line 2:
$(function() {
// Function to highlight all references with the same base ID
function highlightReferences(baseId, clickedElement) {
// Remove previous highlights
$('.reference-highlight, .reference-highlight-clicked').removeClass('reference-highlight reference-highlight-clicked');
// Highlight all references with the same base ID in the main text
$('sup.reference a[href^="#cite_note-' + baseId + '"]').each(function() {
$(this).closest('sup').addClass('reference-highlight');
Line 12:
// Highlight the reference in the list at the bottom
var citationElement = $('#cite_note-' + baseId).addClass('reference-highlight');
citationElement.addClass('reference-highlight');
// Highlight the "Jump up to" links
citationElement.find('.mw-cite-backlink a[href^="#cite_ref-' + baseId + '"]').addClass('reference-highlight');
// Highlight the clicked element differently
$(clickedElement).closest('sup, li, a').addClass('reference-highlight-clicked');
}
// Add click event listener to all reference links in the main text
$('sup.reference a').on('click', function(e) {
e.preventDefault();
var href = $(this).attr('href');
var baseId = href.split('-')[1].split('#')[0];
highlightReferences(baseId, this);
// Scroll to the reference list item
var target = $(href);
$('html, body').animate({
scrollTop: target.offset().top
}, 500);
});
// Add click event listener to the "Jump up to" links in the references section
$('.mw-cite-backlink a').on('click', function(e) {
e.preventDefault();
var href = $(this).attr('href');
var baseId = href.split('-')[1].split('-')[0];
highlightReferences(baseId, this);
// Scroll to the reference in the main text
var target = $(href);
$('html, body').animate({
Line 39 ⟶ 60:
.reference-highlight a {
color: white !important;
}
.reference-highlight-clicked {
background-color: orange !important;
color: black !important;
}
.reference-highlight-clicked a {
color: black !important;
}
`)