「利用者:Dragoniez/scripts/AN Reporter.js」の版間の差分

削除された内容 追加された内容
v4.1: ANR-B002, ダイアログの表示バグの改善試行
v4.2: ウィキテキストからテンプレートを抽出する関数のマイナーバグを修正、コードのクリーンナップ
2行目:
* AN Reporter (ANR)
* Author: Dragoniez
* Version: 4.12
*************************************/
//<nowiki>
113行目:
let checkDuplicateReportsBeforeEdit = true;
 
// Add ANR tab ('報告β' when debugging)
$(mw.util.addPortletLink(btnPosition, '#', '報告', 'ca-anr', '管理者伝言板に利用者を報告', null, '#ca-move')) // '報告β' when debugging
.click(function(e){
 
159行目:
 
// Sections on WP:AN/I
letconst sectionsI =
//<div class="anr-section-div">
` <label for="anr-section-options-i" style="${labelCSS}">節</label>` +
173行目:
// Sections on WP:AN/S
letconst sectionsS =
//<div class="anr-section-div">
` <label for="anr-section-options-s" style="${labelCSS}">名称</label>` +
313行目:
 
// The whole html contour
letconst modalHtml =
`<div class="anr-modal-dialog" title="AN Reporter" style="max-height: 80vh;">` +
` <div class="anr-modal-header">` +
376行目:
'modal': true,
'position': { my: 'center', at: 'top', of: window },
'open': function(){initializeDialog,
'buttons': [{
'text': 'プレビュー',
'click': previewBtn
}, {
'text': '報告',
'click': reportBtn
}]
});
 
// ********** EVENT HANDLERS AND FUNCTIONS // CSS**********
dialogCSS();
// Show VIP list
VIPList();
 
// Function to initialze the modal // Initialize variablesdialog
function checkBlockStatusBeforeEdit = true;initializeDialog(){
 
checkDuplicateReportsBeforeEdit = true;
// CSS
/* NOTE: The value of Logids is inherited from before reopening the dialog.
dialogCSS();
* If any bug is reported, consider resetting the variable here as well. */
}
// Show VIP list
VIPList();
 
// Get the name of the user to report if it can be retrieved from theInitialize pagevariables
checkBlockStatusBeforeEdit = true;
let username = mw.config.get('wgRelevantUserName'); // Note: This does not pick up IP ranges
checkDuplicateReportsBeforeEdit = true;
/* NOTE: The value of Logids is inherited from before reopening the dialog.
* If any bug is reported, consider resetting the variable here as well. */
 
// Get the name //of Workaroundthe user to pickreport if it can be retrieved upfrom IPthe rangespage
let if (username === null && mw.config.get('wgCanonicalSpecialPageNamewgRelevantUserName'); ===// Note: 'Contributions')This does not pick up IP {ranges
 
let relUsername = $('#firstHeading').text().replace('の投稿記録', '');
// Workaround to pick up IP if (mw.util.isIPAddress(relUsername, true)) {ranges
if (!username || username === null && mw.config.get('wgUserNamewgCanonicalSpecialPageName') === 'Contributions') {
username = relUsername;
let relUsername = $('#firstHeading').text().replace('の投稿記録', }'');
}if (mw.util.isIPAddress(relUsername, true)) {
username = relUsername;
// Exit function if the current user is on his/her own page or username has remained undefined or null
if (!username || username === mw.config.get('wgUserName')) {
return;
}
}
// Exit function if the current user is on his/her own page or username has remained undefined or null
if (!username || username === mw.config.get('wgUserName')) {
return;
return 0; }
 
/* Initialize the username input and type dropdown
* Note: The functioncode below is partially a duplicate of updateTypeDropdown(), but deliberately coded that way
* to prevent bugs and eliminate unnecessary API requests */
const inputID = async function initializeTypeDropdown() {'#anr-user1-input';
const selectID = '#anr-user1-select';
const let inputIDcheckboxDivID = '#anr-user1-inputcheckbox-div';
$(inputID).val(username); // Fill the input with the let selectID = '#anr-user1-select';username
let checkboxDivID = '#anr-user1-checkbox-div';
$(inputID).val(username); // Fill the input with the username
 
$(selectID).prop('disabled', false); // enable dropdown
if (mw.util.isIPAddress(username, true)) { // if IP
 
$(selectID).children('.anr-opt-UNL').prop('hidden', true);
$(selectID).children('.anr-opt-User2').prop('hidden', true);
$(selectID).children('.anr-opt-IP2').prop({'hidden': false, 'selected': true});
$(selectID).children('.anr-opt-logid').prop('hidden', true);
$(selectID).children('.anr-opt-diff').prop('hidden', true);
$(selectID).children('.anr-opt-none').prop('hidden', false);
$(checkboxDivID).css('display', 'none'); // hide 'hide username' checkbox
await toggleBlockStatusLink(inputID, false, false);
 
} else { // if user
 
$(selectID).children('.anr-opt-UNL').prop({'hidden': false, 'selected': true});
$(selectID).children('.anr-opt-User2').prop('hidden', false);
$(selectID).children('.anr-opt-IP2').prop('hidden', true);
$(selectID).children('.anr-opt-logid').prop('hidden', true);
$(selectID).children('.anr-opt-diff').prop('hidden', true);
$(selectID).children('.anr-opt-none').prop('hidden', false);
$(checkboxDivID).css('display', 'block'); // show 'hide username' checkbox
await toggleBlockStatusLink(inputID, false, false);
}
}
initializeTypeDropdown();
 
},
'buttons': [{
'text': 'プレビュー',
'click': previewBtn
}, {
'text': '報告',
'click': reportBtn
}]
});
 
// ********** EVENT HANDLERS AND FUNCTIONS **********
// Function to change the CSS of the dialog
1,097 ⟶ 1,095行目:
}
}
//console.log('The contents of each section:');
//console.log(sectionContent);
 
// Get all the reportees in the inputs, and if user, try to get logids
1,772 ⟶ 1,770行目:
const textSplit = text.split('{{');
let templates = [];
//console.log(textSplit);
/* Explanation
1,783 ⟶ 1,782行目:
} else { // If the text has some templates in it
 
let nest = []; // Array to store element numbers of the split segments that involving nested templates
 
for (let i = 1; i < textSplit.length; i++) { // Loop through all elements (but arr[0]) in the split array
1,791 ⟶ 1,792行目:
switch(true) {
case TLCloseCnt === 0: // If the split segment doesn't have any '}}' (= it nests another template)
nest.push(i); // DoPush the element number into the nothingarray
break;
1,821 ⟶ 1,822行目:
} else { // Nesting templates
 
/*let ExplanationelNum = nest[nest.length -1];
username = relUsername nest.pop();
let curSegSplit = textSplit[i].split('}}'); // Array of the current segment split by '}}'
temp = '{{' + textSplit[.slice(elNum, i).join('{{') -+ j]'{{' + tempcurSegSplit.slice(0, +j textSplit[i]+1).splitjoin('}}')[j] + '}}';
if (!isInArray(temp, templates)) {
templates.push(temp);
}
/* Explanation
* Assume that i is 3 and j is 1. Then the 'temp' variable has the value '{{User|EXAMPLE}}'
* because this is the value returned when j is 0. We want to nest this inside its parent
* template, and the left segment of the parent template is in textSplit[2] (thus 3 - 1).
* Now we just want to add the child template (stored in 'temp'), then what remains is the
* right segment of the parent template, and this is just the splitArr[1] of textSplit[3]
* (see also the explanation for when TLCloseCnt === 1.) If there are more templates,
* looping this process will do.
*/
}
1,844 ⟶ 1,839行目:
default:
// Do nothing
}
}
1,852 ⟶ 1,847行目:
// Check if the optional parameter is specified
if (templateName !== undefined && templates.length !== 0) {
let templateRegExp = new RegExp(templateName, 'i'); // Template names are case-insensitive
for (let i = templates.length -1; i >= 0; i--) {
if (templates[i].split('|')[0].search(templateRegExp) === -1) { // If the array element doesn't contain the template name
templates.splice(i, 1); // Remove the element
}
2,644 ⟶ 2,639行目:
*/
function isInArray (el, arr) {
ifreturn (arr.indexOf(el) !== -1) {;
return true;
} else {
return false;
}
}
2,672 ⟶ 2,663行目:
*/
function userIsInGroup(group) {
ifreturn (isInArray(group, mw.config.get('wgUserGroups'))) {;
return true;
} else {
return false;
}
}
 
2,692 ⟶ 2,679行目:
}
return false;
}
 
/**
* Function to count the number of an element in an array
* @param {String} el The array element to count
* @param {Array} arr The array in which to count the element
* @returns {integer} The number of the element in the array
*/
function countElementsInArray(el, arr) {
const counts = {};
arr.forEach(function(x) {
counts[x] = (counts[x] || 0) + 1;
});
if (counts[el] === undefined) {
return 0;
} else {
return counts[el];
}
}