মিডিয়াউইকি:Gadget-Adiutor.js
লক্ষ্য করুন: প্রকাশ করার পর, পরিবর্তনগুলো দেখতে আপনাকে আপনার ব্রাউজারের ক্যাশে পরিষ্কার করার প্রয়োজন হতে পারে।
- ফায়ারফক্স / সাফারি: পুনরায় লোড-এ ক্লিক করার সময় শিফট টিপে ধরে রাখুন, অথবা হয় Ctrl-F5 বা Ctrl-R টিপুন (ম্যাকে ⌘-R টিপুন)
- গুগল ক্রোম: Ctrl-Shift-R (ম্যাকে ⌘-Shift-R) টিপুন
- এজ: Ctrl ধরে রাখা অবস্থায় Refresh-এ ক্লিক করুন, অথবা Ctrl-F5 টিপুন।
- অপেরা: Ctrl-F5 টিপুন।
/* Adiutor: Enhancing Wikipedia Editing Through a Comprehensive Set of Versatile Tools and Modules.
* Author: Vikipolimer
* Learn more at: https://meta.wikimedia.org/wiki/Adiutor
* License: Licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
<nowiki> */
var api = new mw.Api();
var wikiOptions = 'userjs-adiutor-' + mw.config.get('wgWikiID');
// Function to update user options
function updateOptions(options) {
api.postWithEditToken({
action: 'globalpreferences',
format: 'json',
optionname: wikiOptions,
optionvalue: JSON.stringify(options),
formatversion: 2,
}, function() {});
}
// Function to update translations
function updateTranslations() {
api.get({
action: 'query',
prop: 'revisions',
titles: 'MediaWiki:Gadget-Adiutor-i18.json',
rvprop: 'content',
formatversion: 2
}).done(function(data) {
var page = data.query.pages[0];
if(page && page.revisions && page.revisions[0]) {
var jsonData = JSON.parse(page.revisions[0].content);
// Check if jsonData is an object
if(typeof jsonData === 'object') {
for(var langCode in jsonData) {
if(jsonData.hasOwnProperty(langCode) && langCode !== '@metadata') {
// Pass necessary data as arguments to the function
processTranslation(langCode, jsonData[langCode]);
}
}
} else {
console.error('JSON content is not an object:', jsonData);
}
} else {
console.error('No valid revision data found in the response.');
}
}).fail(function(err) {
console.error('Failed to fetch translation data:', err);
});
}
function processTranslation(langCode, translationData) {
var optionValue = JSON.stringify(translationData);
api.postWithEditToken({
action: 'globalpreferences',
format: 'json',
optionname: 'userjs-adiutor-i18-' + langCode,
optionvalue: optionValue,
formatversion: 2
}).done(function(response) {
console.log('Updated translation for langCode: ' + langCode);
}).fail(function(err) {
console.error('Failed to update translation for langCode: ' + langCode, err);
});
}
// Define default user options for the Adiutor gadget
var adiutorUserOptionsDefault = {
"myWorks": [],
"myCustomSummaries": [],
"speedyDeletion": {
"csdSendMessageToCreator": true,
"csdLogNominatedPages": true,
"csdLogPageName": "দ্রুত অপসারণ লগ",
},
"articlesForDeletion": {
"afdSendMessageToCreator": true,
"afdLogNominatedPages": true,
"afdLogPageName": "AFD log",
"afdNominateOpinionsLog": true,
"afdOpinionLogPageName": "AFD opinion log"
},
"proposedDeletion": {
"prdSendMessageToCreator": true,
"prdLogNominatedPages": true,
"prdLogPageName": "PROD log"
},
"status": {
"showMyStatus": true,
"myStatus": "active"
},
"stats": {
"csdRequests": 0,
"afdRequests": 0,
"prodRequests": 0,
"blockRequests": 0,
"userWarnings": 0,
"pageTags": 0
},
"inlinePageInfo": true,
"showEditSummaries": true,
"modules": {
"afd": false, //temporarily changed it to false
"aiv": true,
"bdm": true,
"cmr": true,
"cov": true,
"csd": true,
"das": true,
"del": true,
"inf": true,
"pmr": true,
"prd": false,
"rdr": true,
"sum": true,
"tag": true,
"ubm": true,
"upw": true,
"wrn": true
},
"adiutorVersion": "v1.2.6"
};
// Get user options related to the Adiutor gadget
var adiutorUserOptions = JSON.parse(mw.user.options.get(wikiOptions));
// Check if user options are not present or empty
if(!adiutorUserOptions || Object.keys(adiutorUserOptions).length === 0) {
// Send default user options to the server using API
updateOptions(adiutorUserOptionsDefault);
// Retrieve default translation data
updateTranslations();
} else {
var hasNewOptions = false; // Flag to check if there are new options
// Loop through the properties in adiutorUserOptionsDefault
for(var key in adiutorUserOptionsDefault) {
if(adiutorUserOptionsDefault.hasOwnProperty(key)) {
// Check if the property exists in adiutorUserOptions
if(!adiutorUserOptions.hasOwnProperty(key)) {
// New setting found, set the flag
hasNewOptions = true;
adiutorUserOptions[key] = adiutorUserOptionsDefault[key]; // Add the new option
}
}
}
// Update user options if new settings are found
if(hasNewOptions) {
updateOptions(adiutorUserOptions);
updateTranslations();
}
}
try {
var userLanguage = mw.config.get('wgUserLanguage'); // Get user's language
var adiutorUserInterfaceTranslations = mw.user.options.get('userjs-adiutor-i18-' + userLanguage); // Get translation for user's language
// If there is no translation, use English as a fallback.
if(!adiutorUserInterfaceTranslations) {
adiutorUserInterfaceTranslations = mw.user.options.get('userjs-adiutor-i18-en');
}
// Ensure messages is an object with valid translations.
var messages = JSON.parse(adiutorUserInterfaceTranslations);
if(typeof messages !== 'object' || Object.keys(messages).length === 0) {
throw new Error('Invalid or empty translations');
}
// If so, work with the messages object.
mw.messages.set(messages);
// Load the Adiutor interface launcher
mw.loader.load(mw.util.getUrl('MediaWiki:Gadget-Adiutor-AIL.js', {
action: 'raw'
}) + '&ctype=text/javascript', 'text/javascript');
} catch(error) {
console.error('Error fetching and processing translations:', error);
}
/* </nowiki> */