משתמש:MGA73/common.js
מראה
הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.
- פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
- גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
- אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
$(document).ready(function() {
function addButtons() {
if (mw.config.get('wgNamespaceNumber') === 6 || mw.config.get('wgPageName') === 'משתמש:MGA73/Sandbox') {
var buttonContainer = $('<div>').css({'margin': '10px 0'});
var relicenseButton = $('<button>')
.text('Relicense')
.css({
'cursor': 'pointer',
'margin-right': '10px'
})
.click(function(event) {
event.preventDefault();
// Redirect to the edit page with relicense marker
var editUrl = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', relicense: true });
window.location.href = editUrl;
});
var notEligibleButton = $('<button>')
.text('Not-eligible')
.css({
'cursor': 'pointer',
'margin-right': '10px'
})
.click(function(event) {
event.preventDefault();
// Redirect to the edit page with not-eligible marker
var editUrl = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', noteligible: true });
window.location.href = editUrl;
});
var redundantButton = $('<button>')
.text('Redundant')
.css({
'cursor': 'pointer'
})
.click(function(event) {
event.preventDefault();
// Redirect to the edit page with redundant marker
var editUrl = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', redundant: true });
window.location.href = editUrl;
});
buttonContainer.append(relicenseButton).append(notEligibleButton).append(redundantButton);
var content = $('#content');
if (content.length) {
content.prepend(buttonContainer);
}
}
}
function applyChangesOnEditPage() {
if (mw.config.get('wgAction') === 'edit') {
var urlParams = new URLSearchParams(window.location.search);
var relicense = urlParams.get('relicense');
var noteligible = urlParams.get('noteligible');
var redundant = urlParams.get('redundant');
var newGFDLTemplate;
var newGFDLWithDisclaimersTemplate;
var summary;
if (relicense) {
newGFDLTemplate = '{{GFDL|migration=relicense}}';
newGFDLWithDisclaimersTemplate = '{{GFDL-with-disclaimers|migration=relicense}}';
summary = 'Eligible for [[:w:en:Wikipedia:Image license migration|GFDL relicense]]. Uploaded before August 2009.';
} else if (noteligible) {
newGFDLTemplate = '{{GFDL|migration=not-eligible}}';
newGFDLWithDisclaimersTemplate = '{{GFDL-with-disclaimers|migration=not-eligible}}';
summary = 'Not eligible for [[:w:en:Wikipedia:Image license migration|GFDL relicense]]. Uploaded after August 2009. Uploader please consider adding {{Cc-by-sa-4.0}} (or {{PD-old}} if that is more relevant).';
} else if (redundant) {
newGFDLTemplate = '{{GFDL|migration=redundant}}';
newGFDLWithDisclaimersTemplate = '{{GFDL-with-disclaimers|migration=redundant}}';
summary = 'File is considered redundant for [[:w:en:Wikipedia:Image license migration|GFDL relicense]]..';
}
if (newGFDLTemplate && newGFDLWithDisclaimersTemplate) {
var editBox = $('#wpTextbox1');
var currentText = editBox.val();
// Replace {{GFDL}} and {{GFDL-with-disclaimers}} with the new templates
var updatedText = currentText
.replace(/{{GFDL}}/g, newGFDLTemplate)
.replace(/{{GFDL-with-disclaimers}}/g, newGFDLWithDisclaimersTemplate);
editBox.val(updatedText);
}
if (summary) {
$('#wpSummary').val(summary);
}
}
}
addButtons();
applyChangesOnEditPage();
});