MediaWiki:Common.js
Revision as of 09:38, 3 March 2025 by Jemaleddin (talk | contribs)
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */ $(document).ready(function() { const editLinks = document.querySelectorAll('.mw-editsection a'); // Select edit links const headings = document.querySelectorAll('h2'); // Select H2 headings function handleScroll() { editLinks.forEach(editLink => { const editSection = editLink.parentElement.parentElement; // Get the edit section element const heading = editSection.parentElement; // Get the parent heading element. const rect = editSection.getBoundingClientRect(); const headingRect = heading.getBoundingClientRect(); let nextHeadingRect = null; for (let i = 0; i < headings.length; i++) { if (headings[i] === heading && i + 1 < headings.length) { nextHeadingRect = headings[i + 1].getBoundingClientRect(); break; } } if (rect.top < 0 && (nextHeadingRect === null || rect.bottom < nextHeadingRect.top)) { editLink.classList.add('edit-link-fixed'); console.log("make it fixed"); } else { editLink.classList.remove('edit-link-fixed'); } }); } window.addEventListener('scroll', handleScroll); handleScroll(); // Initial check on page load var $elem = jQuery('<script/>', { 'data-aff': "amazon.com, www.amazon.com : tag = internsocie02-20", 'type': "text/javascript", 'src': "https://cdn.jsdelivr.net/npm/affiliate@2.0.3/dist/affiliate.js", 'id': "aff-js", 'async': "" }); $("head").append($elem); });