Gebruiker:MGA73/common.js
Let wel: Na die wysiging is dit dalk nodig om u blaaier se kasgeheue te verfris voordat u die veranderinge sal sien:
- Firefox / Safari: hou Shift en kliek Herlaai, of druk Ctrl-F5 of Ctrl-R (⌘-R op 'n Mac)
- Google Chrome: Druk Ctrl-Shift-R (⌘-Shift-R op 'n Mac)
- Internet Explorer / Edge: Hou Ctrl en kliek Refresh, of druk Ctrl-F5
- Opera: Gaan na Kieslys → Settings (Opera → Preferences op 'n Mac) en dan na Privacy & security → Clear browsing data → Cached images and files.
$(document).ready(function() {
// Only run this script on File pages
if (mw.config.get('wgNamespaceNumber') === 6) {
// Function to check for Commons duplication and extract the filename
function getCommonsFilename() {
var contentText = $('#mw-content-text').text();
var searchText = "from Wikimedia Commons";
if (contentText.includes(searchText)) {
var startIndex = contentText.indexOf("Lêer:") + "Lêer:".length;
var endIndex = contentText.indexOf(searchText);
var commonsFilename = contentText.substring(startIndex, endIndex).trim();
// Remove any unwanted characters or spaces
commonsFilename = commonsFilename.replace(/_/g, ' ');
return commonsFilename;
}
return null;
}
// Get the Commons filename if it exists
var commonsFilename = getCommonsFilename();
if (commonsFilename) {
// Create the "Add NowCommons" button
var addNowCommonsLink = $('<a>')
.text('Add NowCommons')
.attr('href', '#')
.css({
'cursor': 'pointer',
'color': '#0645AD',
'margin-left': '10px',
})
.click(function(event) {
event.preventDefault();
// Redirect to the edit page with NowCommons marker
var editUrl = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', nowcommons: commonsFilename });
window.location.href = editUrl;
});
// Add the link to the page (e.g., next to the edit button)
$('#ca-edit').after(addNowCommonsLink);
}
// Automatically insert the NowCommons template and edit summary if the page is in edit mode
var urlParams = new URLSearchParams(window.location.search);
if (mw.config.get('wgAction') === 'edit' && urlParams.has('nowcommons')) {
var commonsFilename = urlParams.get('nowcommons');
var nowCommonsTemplate = '{{NowCommons|' + commonsFilename + '}}';
var editBox = $('#wpTextbox1');
var currentText = editBox.val();
editBox.val(nowCommonsTemplate + '\n' + currentText);
// Set the edit summary
$('#wpSummary').val('Adding NowCommons template for file duplicated on Commons (' + commonsFilename + ')');
}
}
});