From Wikipedia, the free encyclopedia
Content deleted Content added
|
 |
|||
| Line 17: | Line 17: | ||
|
// Observe DOM changes to catch dynamically loaded section edit links |
// Observe DOM changes to catch dynamically loaded section edit links |
||
|
const observer = new MutationObserver(renameEditSource); |
const observer = new MutationObserver(renameEditSource); |
||
|
observer.observe(document.body, { childList: true, subtree: true }); |
|||
|
console.log(“✅ Wikipedia script loaded for Joko2468 (section Edit links)”); |
|||
|
// Function to add classic-style “Edit” links |
|||
|
function addClassicSectionEdits() { |
|||
|
const pageName = mw.config.get(‘wgPageName’); |
|||
|
let sectionIndex = 0; |
|||
|
$(‘.mw-parser-output’).children(‘h2, h3, h4, h5, h6’).each(function() { |
|||
|
// Skip if already has our link |
|||
|
if ($(this).find(‘.section-edit-link’).length) return; |
|||
|
// Create the link |
|||
|
const link = $(‘<a>’) |
|||
|
.addClass(‘section-edit-link’) |
|||
|
.attr(‘href’, `/w/index.php?title=${encodeURIComponent(pageName)}&action=edit§ion=${sectionIndex}`) |
|||
|
.text(‘Edit’); |
|||
|
// Append after the heading text |
|||
|
$(this).append(‘ ‘).append(link); |
|||
|
sectionIndex++; |
|||
|
}); |
|||
|
} |
|||
|
// Run initially |
|||
|
addClassicSectionEdits(); |
|||
|
// Run on dynamic changes |
|||
|
const observer = new MutationObserver(addClassicSectionEdits); |
|||
|
observer.observe(document.body, { childList: true, subtree: true }); |
observer.observe(document.body, { childList: true, subtree: true }); |
||
Latest revision as of 22:40, 9 November 2025
// Confirm script loaded
console.log("✅ Wikipedia script loaded for Joko2468");
// Function to rename "Edit source" → "Edit"
function renameEditSource() {
$('a, button').each(function() {
const text = $(this).text().trim();
if (text === 'Edit source') {
$(this).text('Edit');
}
});
}
// Run immediately in case some links already exist
renameEditSource();
// Observe DOM changes to catch dynamically loaded section edit links
const observer = new MutationObserver(renameEditSource);
observer.observe(document.body, { childList: true, subtree: true });


