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

削除された内容 追加された内容
3.3.3RR: +LTA:AINO
v4.0: ブロック状態確認機能、重複報告確認機能、ほか変更・追加点多数
2行目:
* AN Reporter (ANR)
* Author: Dragoniez
* Version: 34.3.3RR0
*************************************/
//<nowiki>
14行目:
 
// Load CSS source for Select2
$('head')
.append($('<link />')
.attr({
'rel="': 'stylesheet"',
'href="': 'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css">');
})
);
 
// Run the script only if the user is autoconfirmed and the page is not an edit page
if (userIsInGroup('autoconfirmed') && mw.config.get('wgAction') !== 'edit') {
 
// ********** UTILITY FUNCTIONS **********
 
/**
* String method to get rid of the U+200E space, in addition to the function of $.trim()
* @returns {String}
*/
String.prototype.trim2 = function() {
return this.replace(/\u200e/g, '').trim();
};
 
/**
* String method (alternative) to replace all occurences of a string with another
* (takes a replacer and a replacee as arguments)
* @returns {String}
*/
String.prototype.replaceAll2 = function() {
let replaced = '';
if (arguments.length %2 !== 0) {
return new Error('SyntaxError: replaceAll2 takes an even number of arguments.');
} else {
for (let i = 0; i < arguments.length; i = i + 2) {
if (i === 0) {
replaced = this.split(arguments[i]).join(arguments[i + 1]);
} else {
replaced = replaced.split(arguments[i]).join(arguments[i + 1]);
}
}
return replaced;
}
};
 
// Define the position of the '報告' button
53 ⟶ 91行目:
// Default CSS for Select2
$('head').append(
'`<style>' +
' .select2-selection__rendered {' +
' padding: 1px 2px;' +
' font-size: 1em;' +
' line-height: normal !important;' +
' }' +
' .select2-results__option, .select2-results__group {' +
' padding: 1px 8px;' +
` font-size: ${s2fSize};` +
' margin: 0;' +
' }' +
.select2-container, .select2-selection--single {
'</style>'
height: auto !important;
}
</style>`
);
 
// Variables
let Logids = {}; // Object to store usernames and their corresponding logids
let checkBlockStatusBeforeEdit = true;
let checkDuplicateReportsBeforeEdit = true;
 
// Add ANR tab
$(mw.util.addPortletLink(btnPosition, '#', '報告', 'ca-anr', '管理者伝言板に利用者を報告', null, '#ca-move')) // '報告β' when debugging
.click(function(e){
 
77 ⟶ 123行目:
 
// CSS
letconst labelCSS = 'display: inline-block; width: 8ch;';
let marginCSS = 'margindisplay: 1em 0inline-block;'; +
'width: 8ch;' ;
let siCSS = 'border: 1px solid #d3d3d3; border-radius: 1%; background: white; padding: 2px 4px;'; // For select and input
const marginCSS =
let btnCSS = 'color: black; font-weight: normal; border: 1px solid #d3d3d3; background: white; padding: 0.2em 0.5em; border-radius: 10%;'; // For button
'margin: 1em 0;' ;
const siCSS = // For select and input
'border: 1px solid #d3d3d3;' +
'border-radius: 1%;' +
'background-color: white;' +
'padding: 2px 4px;' ;
const btnCSS = // For button
'color: black;' +
'font-weight: normal;' +
'border: 1px solid #d3d3d3;' +
'background-color: white;' +
'padding: 0.2em 0.5em;' +
'border-radius: 10%;' ;
/* Experimental design
const lsCSS = // Eliminate gap between inline-blocks
'letter-spacing: -1em;' +
'white-space: nowrap' ;
const rlsCSS = // Reset line-spacing in child elements
'letter-spacing: normal' ;
*/
// Page names
98 ⟶ 164行目:
` <select id="anr-section-options-i" style="${siCSS}">` +
` <option selected disabled hidden>選択してください</option>` +
` <option id="anr-section-options-i-date">${getSectionI()}</option>` +
` <option>不適切な利用者名</option>` +
` <option>公開アカウント</option>` +
127 ⟶ 193行目:
` <option>Asaklira系(ASA)</option>` +
` <option>麻原英太系 (ASACOV)</option>` +
` <option>アジアンビ系 (ASIANB)</option>` +
` <option>Bulut系 (Asperger、ASPE)</option>` +
` <option>백돌系(BAEG)</option>` +
139 ⟶ 205行目:
` <option>Ellsiemall系 (ELLS)</option>` +
` <option>イギリス可変IP系(ENS)</option>` +
` <option>放送局・送信所の記事で荒らしを行うIP(EOHS)</option>` +
` <option>EricNeedles3系 (ERIC3)</option>` +
` <option>IUCNレッドリスト関連荒らし系(FRL)</option>` +
178 ⟶ 244行目:
` <option>猛烈な勢いで赤リンクを無差別除去するアカウント群系(MOUAKA)</option>` +
` <option>MShared系 (MShared)</option>` +
` <option>名取の納豆系(NATO)</option>` +
` <option>Die ndbtk系 (NDBTK)</option>` +
` <option>NoSaito・みそかつおにんにく系 (NMT)</option>` +
215 ⟶ 281行目:
` </select>`;
//</div>
// Username input
let userHtml =
//<div class="anr-user-div">
` <div id="anr-user1-input-div">` +
` <label for="anr-user1-input" style="${labelCSS}">利用者</label>` +
` <input id="anr-user1-input" style="width: 34ch; ${siCSS}">` +
` <select disabled id="anr-user1-select" style="${siCSS}">` +
` <option class="anr-opt-UNL">UNL</option>` +
` <option class="anr-opt-User2">User2</option>` +
` <option class="anr-opt-IP2">IP2</option>` +
` <option class="anr-opt-logid">logid</option>` +
` <option class="anr-opt-diff">diff</option>` +
` <option selected class="anr-opt-none">none</option>` +
` </select>` +
` </div>` +
` <div id="anr-user1-checkbox-div" style="display: none;">` +
` <label class="anr-emptylabel" style="${labelCSS}"></label>` +
` <input type="checkbox" id="anr-user1-checkbox">` +
` <label for="anr-user1-checkbox">利用者名を隠す</label>` +
` </div>` +
` <div id="anr-user1-idlink-div" style="display: none;">` +
` <label for="anr-user1-idlink" style="${labelCSS}"></label>` +
` <a id="anr-user1-idlink" href="" target="_blank"></a>` +
` </div>` +
` <div id="anr-user1-blockstatus-div" style="display: none;">` +
` <label for="anr-user1-blockstatus" style="${labelCSS}"></label>` +
` <a id="anr-user1-blockstatus" href="" target="_blank" style="color: MediumVioletRed;">ブロックあり</a>` +
` </div>`;
//</div>
 
// The whole html contour
let modalHtml =
`<div class="anr-modal-dialog" title="AN Reporter" style="max-height: 80vh; min-width: 54ch;">` +
` <div class="anr-modal-header">` +
` <h2>利用者を報告</h2>` +
` </div>` +
` <div class="anr-modal-body">` +
` <form>` +
` <div class="anr-target-div" style="${marginCSS}">` +
` <label for="anr-target-options" style="${labelCSS}">報告先</label>` +
` <select id="anr-target-options" style="${siCSS}">` +
` <option selected disabled hidden>選択してください</option>` +
` <option>${ANI}</option>` +
` <option>${ANS}</option>` +
` <option>${AN3RR}</option>` +
` </select>` +
` <div class="anr-target-pagelink-div" style="display: none;">` +
` <label class="anr-emptylabel" for="anr-target-pagelink" style="${labelCSS}"></label>` +
` <a id="anr-target-pagelink" href="" target="_blank">報告先を確認</a>` +
` </div>` +
` </div>` +
` <div class="anr-section-div" style="${marginCSS} display: none;">` +
// sectionsX +
` </div>` +
` <div class="anr-user-div" style="${marginCSS}">` +
userHtml +
` <div class="anr-btn-div">` +
` <button type="button" class="anr-addBtn" style="${btnCSS}">追加</button>` +
` </div>` +
` </div>` +
` <div class="anr-reason-div" style="${marginCSS}">` +
` <label for="anr-reason-text" style="${labelCSS}">理由</label>` +
` <textarea id="anr-reason-text" rows="8" style="width: 100%"></textarea>` +
` </div>` +
` <div class="anr-summary-div" style="${marginCSS}">` +
` <input id="anr-summary-checkbox" type="checkbox">` +
` <label for="anr-summary-checkbox">要約を指定</label>` +
` <textarea id="anr-summary-text" rows="3" style="width: 100%; display: none;"></textarea>` +
` </div>` +
` <div class="anr-checkbox-div" style="${marginCSS}">` +
` <input checked id="anr-blockstatus-checkbox" type="checkbox">` +
` <label for="anr-blockstatus-checkbox">報告前にブロック状態をチェック</label>` +
` <br>` +
` <input checked id="anr-duplicatereport-checkbox" type="checkbox">` +
` <label for="anr-duplicatereport-checkbox">報告前に重複報告をチェック</label>` +
` </div>` +
` </form>` +
` </div>` +
`</div>`;
 
// Add the frame div to the page
$('body').append(modalHtml);
 
// Script ad for edit summary
const scriptAd = ' ([[User:Dragoniez/AN Reporter|AN Reporter]])';
//const scriptAd = ' ([[User:Dragoniez/AN Reporter|AN Reporter Experimental]])'; // For debugging
// Show dialog
$('.anr-modal-dialog').dialog({
'resizable': false,
'height': 'auto',
'width': 'auto',
'modal': true,
'position': { my: 'center', at: 'top', of: window },
'open': function(){
 
// CSS
dialogCSS();
// Show VIP list
VIPList();
 
// Initialize variables
checkBlockStatusBeforeEdit = true;
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 the user to report if it can be retrieved from the page
let username = mw.config.get('wgRelevantUserName'); // Note: This does not pick up IP ranges
 
// Workaround to pick up IP ranges
if (username === null && mw.config.get('wgCanonicalSpecialPageName') === 'Contributions') {
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;
}
 
/* Initialize the username input and type dropdown
* Note: The function below is partially a duplicate of updateTypeDropdown(), but deliberately coded that way
* to prevent bugs and eliminate unnecessary API requests */
async function initializeTypeDropdown() {
let inputID = '#anr-user1-input';
let selectID = '#anr-user1-select';
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
function dialogCSS() {
$('.ui-dialog-content, .ui-dialog-buttonpane, .ui-corner-all, .ui-draggable, .ui-resizable').css('background', '#FFF0E4');
$('.ui-button').css({
'color': 'black',
'background-color': 'white'
});
$('.ui-dialog-titlebar, .ui-dialog-titlebar-close').attr('style', 'background: #FEC493 !important;');
$('.ui-dialog').css('font-size', fSize);
}
 
// WP:VIP list (for copy to clipboard)
let VIPList = async function VIPList() {
return new Promise(function(resolve, reject) {
new mw.Api().get({
223 ⟶ 473行目:
'page': 'Wikipedia:進行中の荒らし行為',
'prop': 'sections',
'formatversion': '2'
}).then(function(res){
 
229 ⟶ 479行目:
 
// Get VIP's names
letconst sectionsParsedsectionInfo = res.parse.sections;
letconst excludeList = ['記述について', '急を要する二段階', '配列', 'ブロック等の手段', 'このページに利用者名を加える',
'記述について',
'注意と選択', '警告の方法', '未登録(匿名・IP)ユーザーの場合', '登録済み(ログイン)ユーザーの場合',
'警告中急を要する二段階', '関連項目'];
let sectionList = []; '配列',
for (let i = 0; i < sectionsParsed.length; i++) {'ブロック等の手段',
if (!isInArray(sectionsParsed[i].line, excludeList) && sectionsParsed[i].level === '3このページに利用者名を加える') {,
sectionList.push('<option>注意と選択' + sectionsParsed[i].line + '</option>');,
'警告の方法',
'未登録(匿名・IP)ユーザーの場合',
'登録済み(ログイン)ユーザーの場合',
'警告中',
'関連項目'
];
let vipList = [];
for (let i = 0; i < sectionInfo.length; i++) {
if (!isInArray(sectionInfo[i].line, excludeList) && sectionInfo[i].level === '3') {
vipList.push(`<option>${sectionInfo[i].line}</option>`);
}
}
 
// Show the VIP list on the dialog
letconst VIPListHtml =
'<div class="anr-viplist-div" style="width: 100%;">' +
' <select id="anr-viplist-select">' +
' <option selected disabled hidden>[[Wikipedia:進行中の荒らし行為]]を検索</option>' +
sectionListvipList.join() +
' </select>' +
` <button type="button" class="anr-viplist-btn" style="${btnCSS}">コピー</button>` +
263 ⟶ 523行目:
}
// UsernameCopy inputa VIP name when the 'copy' button is hit
$(document).off('click', '.anr-viplist-btn').on('click', '.anr-viplist-btn', function() {
let userHtml =
const vipSelectVal = $('#anr-viplist-select').find('option').filter(':selected').text().trim();
// <div class="anr-user-div">
` const vipLink = <div'[[WP:VIP#' id="anr-user1-input-div">`+ vipSelectVal + ']]';
if (vipSelectVal !== '[[Wikipedia:進行中の荒らし行為]]を検索') {
` <label id="anr-user1-label" for="anr-user1-input" style="${labelCSS}">利用者</label>` +
` <input id="anr-user1-input" style="width: 34chcopyToClipboard(vipLink); ${siCSS}">` +
` } else <select disabled id="anr-user1-select" style="${siCSS}">` +
` <option class="anr-opt-UNL">UNL</option>` +alert('ドロップダウンの値が選択されていません');
` <option class="anr-opt-User2">User2</option>` +}
});
` <option class="anr-opt-IP2">IP2</option>` +
` <option class="anr-opt-logid">logid</option>` +
` <option class="anr-opt-diff">diff</option>` +
` <option selected class="anr-opt-none">none</option>` +
` </select>` +
` </div>` +
` <div id="anr-user1-checkbox-div" style="display: none;">` +
` <label class="anr-emptylabel" style="${labelCSS}"></label>` +
` <input type="checkbox" id="anr-user1-checkbox">` +
` <label id="anr-user1-checkbox-hide" for="anr-user1-checkbox">利用者名を隠す</label>` +
` </div>` +
` <div id="anr-user1-a-div" style="display: none;">` +
` <label id="anr-user1-label" for="anr-user1-a" style="${labelCSS}"></label>` +
` <a id="anr-user1-a" href="" target="_blank"></a>` +
` </div>`;
// </div>
 
// TheFunction wholeto htmlcopy contoura string to the clipboard
letfunction modalHtmlcopyToClipboard(str) ={
try { // This <divshould class="anr-modal-dialog"handle title="ANbrowser Reporter">incompatibility
` <div classlet $temp ="anr-modal-header">` +$('<input>');
` $('body').append($temp); // Create <h2>利用者を報告</h2>`a temporarily hidden text +field
` < $temp.val(str).select(); /div>`/ Copy the text string into the field and select the +text
` <div class="anr-modal-body"document.execCommand('copy'); >`// +Copy it to the clipboard
` $temp.remove(); // Remove <form>`the +text field
` <div class="anr-target-div" style="${marginCSS}">` +
catch (err) {
` <label for="anr-target-options" style="${labelCSS}">報告先</label>` +
` <select id="anr-target-options" style="${siCSS}">` +alert('ご利用のブラウザはこの機能に対応していません');
console.log(err);
` <option selected disabled hidden>選択してください</option>` +
` <option>${ANI}</option>` +
` <option>${ANS}</option>` +
` <option>${AN3RR}</option>` +
` </select>` +
` <div class="anr-target-a-div" style="display: none;">` +
` <label class="anr-emptylabel" for="anr-target-a" style="${labelCSS}"></label>` +
` <a id="anr-target-a" href="" target="_blank">報告先を確認</a>` +
` </div>` +
` </div>` +
` <div class="anr-section-div" style="${marginCSS} display: none;">` +
// sectionsX +
` </div>` +
` <div class="anr-user-div" style="${marginCSS}">` +
userHtml +
` <div class="anr-btn-div">` +
` <button type="button" class="anr-addBtn" style="${btnCSS}">追加</button>` +
` </div>` +
` </div>` +
` <div class="anr-reason-div" style="${marginCSS}">` +
` <label for="anr-reason-text" style="${labelCSS}">理由</label>` +
` <textarea id="anr-reason-text" rows="8" style="width: 100%"></textarea>` +
` </div>` +
` <div class="anr-summary-div" style="${marginCSS}">` +
` <input id="anr-summary-checkbox" type="checkbox">` +
` <label for="anr-summary-checkbox">要約を指定</label>` +
` <textarea id="anr-summary-text" rows="3" style="width: 100%; display: none;"></textarea>` +
` </div>` +
` </form>` +
` </div>`;
// </div>`
 
// AddFunction theto framecheck divinformation totyped into the pageform
function editPrep() {
$('body').append('<div class="anr-modal-dialog" title="AN Reporter" style="max-height: 80vh;"/>');
let rqFieldsEmpty = false;
 
// Check if at least one username is given and get users to report (and their UserAN types)
// Create html elements inside the div
$('.anr-modal-dialog').html(modalHtml) let users = [];
let types = [];
let duplicates = [];
let usernameInInput = '';
let selectedType = '';
let tempUsername = ''; // An escape hatch for username (for t=logid)
 
// Script ad for edit(let i = 1; i < Infinity; i++) { // Loop through all summaryinputs
const scriptAd = ' ([[User:Dragoniez/AN Reporter|AN Reporter]])';
//const scriptAd = ' ([[User:Dragoniez/AN Reporter|AN Reporter Experimental]])'; // For debugging
 
if ($(`#anr-user${i}-input`).length === 0) { // if selector is not found
// Show dialog
$('.anr-modal-dialog').dialog({
'minHeight': 50,
'minWidth': '58ch',
'width': 'auto',
'modal': true,
'position': { my: 'center', at: 'top+20%', of: window },
'open': function(){
 
break; // CSSexit for
dialogCSS();
 
} else { // Showif selector VIPis listfound
VIPList();
 
// Get the name ofusernameInInput the= $(`#anr-user to report if it can be retrieved from the page${i}-input`).val().trim2();
selectedType = $(`#anr-user${i}-select`).children('option').filter(':selected').text();
let username = mw.config.get('wgRelevantUserName'); // Note: This does not pick up IP ranges
 
if (usernameInInput !== '') { // if input is not empty
 
// If t=logid, necessary to check if Logids has a username corresponding to the logid
if (selectedType === 'logid' && Logids[usernameInInput] !== undefined) {
 
// If the object has a username/logid pair, get username from the logid
tempUsername = Logids[usernameInInput];
 
// If either of the username or the logid is already in the array 'users',
// and if they have yet to be listed as duplicates
if ((isInArray(usernameInInput, users) || isInArray(tempUsername, users)) &&
!isInArray(usernameInInput, duplicates) && !isInArray(tempUsername, duplicates)) {
// List both the username and the logid as duplicates
duplicates.push(usernameInInput, tempUsername);
 
}
} else { // If logids are irrelevant
 
// If the username is already in the array 'users' and hasn't been listed as a duplicate
if (isInArray(usernameInInput, users) && !isInArray(usernameInInput, duplicates)) {
 
// List the username as a duplicate
duplicates.push(usernameInInput);
 
}
 
}
 
users.push(usernameInInput); // Push the username into the array
types.push(selectedType); // Push the UserAN type into the array
 
// Workaround to pick up IP ranges
if (username === null && mw.config.get('wgCanonicalSpecialPageName') === 'Contributions') {
let relUsername = $('#firstHeading').text().replace('の投稿記録', '');
if (mw.util.isIPAddress(relUsername, true)) {
username = relUsername;
}
}
 
// Reset variables
tempUsername = '';
 
}
 
// Get the name of the section to edit
let pageToEdit = $('#anr-target-options').children('option').filter(':selected').text();
let sectionToEdit = '選択してください';
const ANSOptSelected = $('#anr-section-options-s').find('option').filter(':selected').text();
let reportToANS = false;
 
if (pageToEdit === ANI) { // If WP:AN/I is selected as the target page to edit
 
sectionToEdit = $('#anr-section-options-i').children('option').filter(':selected').text();
 
// Update the target section for cases in which the date has changed since the date-dependent section was chosen
if (sectionToEdit.match(/^\d{4}年\d{1,2}月\d{1,2}日 - \d{1,2}日新規報告$/) !== null) {
sectionToEdit = getSectionI(false);
$('#anr-section-options-i-date').text(getSectionI(false));
}
 
} else if (pageToEdit === ANS) { // If WP:AN/S is selected as the target page to edit
 
reportToANS = true;
switch(ANSOptSelected) {
case 'Iccic系 (Iccic)':
pageToEdit = Iccic;
sectionToEdit = '新規依頼';
break;
case 'いせちか系 (ISECHIKA)':
pageToEdit = ISECHIKA;
sectionToEdit = '新規依頼';
break;
case '影武者系(KAGE)':
pageToEdit = KAGE;
sectionToEdit = '新規依頼';
break;
case '清島達郎系 (清島、KIYOSHIMA)':
pageToEdit = KIYOSHIMA;
sectionToEdit = '新規依頼';
break;
case '真珠王子系(SHINJU)':
pageToEdit = SHINJU;
sectionToEdit = '新規依頼';
break;
default:
sectionToEdit = ANSOptSelected;
}
 
} else if (pageToEdit === AN3RR) { // If WP:AN/3RR is selected as the target page to edit
 
sectionToEdit = '3RR';
 
}
 
// Check if necessary fields are filled
if (
pageToEdit === '選択してください' || // The page dropdown's remained 選択してください
sectionToEdit === '選択してください' || // The section dropdown's remained 選択してください
$('#anr-reason-text').val().trim2() === '' || // No reason is given
users.length === 0 // No username is given
) {
rqFieldsEmpty = true;
}
// UserAN template and the reason of the report
const UserAN = '{{UserAN|t=TYPE|USER}}';
let reason = $('#anr-reason-text').val().trim2();
if (reason.substring(reason.length - 4) !== '~~~~') { // If reason doesn't contain signature, add one
reason = reason + '--~~~~';
}
 
// Get edit summary
const editSummarySection = '/*' + sectionToEdit + '*/';
 
let editSummary =
$('#anr-summary-text').val().trim2() === '' ?
editSummarySection + genEditSummary().replace(' - ', '') + scriptAd:
editSummarySection + $('#anr-summary-text').val().trim2() + scriptAd;
 
// Get text to add to the page
let textToSubmit = '';
if (users.length < 2) { // If user to report is just one
textToSubmit = '\* ' + UserAN.replaceAll2('TYPE', types[0], 'USER', users[0]) + ' - ' + reason;
} else { // If two or more
for (let i = 0; i < users.length; i++) {
textToSubmit += '\* ' + UserAN.replaceAll2('TYPE', types[i], 'USER', users[i]) + '\n';
}
textToSubmit += ': ' + reason;
}
 
// Return values
return {
'users': users,
'types': types,
'duplicates': duplicates,
'pageToEdit': pageToEdit,
'sectionToEdit': sectionToEdit,
'reportToANS': reportToANS,
'rqFieldsEmpty': rqFieldsEmpty,
'editSummary': editSummary,
'textToSubmit': textToSubmit
}
}
 
// Function for the 'preview' button of the dialog
function previewBtn() {
 
// Check if the necessary fields are filled and get edit information
let ep = editPrep();
if (ep.rqFieldsEmpty) {
alert('必須項目が入力・選択されていません'); // Show error and cancel the preview
return;
}
 
// If the inputs have duplicates in them
if (ep.duplicates.length !== 0) {
 
let confirmMsg =
'以下の利用者について、重複入力がある可能性があります。\n\n' +
ep.duplicates.join(', ') + '\n\n' +
'プレビューを続行する場合は OK を、フォームに戻る場合は Cancel を押してください';
if (confirm(confirmMsg) === false) { // If cancelled
// If wgRelevantUserName returns null or the name of the current user, set the variable as a null string
if (!username || username === mw.config.get('wgUserName')) {return;
username = '';
}
 
// Show the user name on the dialog}
$('#anr-user1-input').val(username);
// Preview dialog typeDropdown('#anr-user1-input', '#anr-user1-select');contour
const ANSMisc = `<a if (username href=== "${mw.configutil.getgetUrl('wgRelevantUserNameWP:AN/S#OTH')}" && !mw.util.isIPAddress(username, true)) {target="_blank">WP:AN/S#その他</a>`;
const previewDiv =
$('#anr-user1-checkbox-div').css('display', 'block'); // Show 'hide username' if the name obtained is a user's
'<div class="anr-preview-dialog" title="AN Reporter Preview">' +
' <div id="anr-preview-header" style="padding: 0.5em;">' +
' <p id="anr-preview-loading">' +
` プレビューを読み込み中${toggleLoadingSpinner('add')}` +
' </p>' +
' <p id="anr-preview-warning" style="display: none;">' +
' 注意1: このプレビュー上のリンクは全て新しいタブで開かれます' +
' <br>' +
` 注意2: 報告先が ${ANSMisc} の場合、このプレビューには表示されませんが「他X月X日」のヘッダーは必要に応じて自動挿入されます` +
' </p>' +
' </div>' +
' <div id="anr-preview-body" style="display: none; font-size: 1.1em; padding-top: 1em; border-top: 1px solid silver;">' +
' <div id="anr-preview-text" style="border: 1px solid silver; padding: 0.2em 0.5em; background: white;">' +
// previewHtml
' </div>' +
' <div id="anr-preview-summary" style="margin-top: 0.8em; border: 1px solid silver; padding: 0.2em 0.5em; background: white;">' +
// summaryHtml
' </div>' +
' </div>' +
'</div>';
 
// Show preview dialog
$('body').append(previewDiv);
$('.anr-preview-dialog').dialog({
'height': 'auto',
'width': $('#content').width() * 0.8,
'modal': true,
'position': { my: 'center', at: 'top', of: window },
'open': async function(){
 
// CSS
dialogCSS();
 
// Convert text on the dialog to html
const parsed = await convertWikitextToHtml(ep.textToSubmit, ep.editSummary);
if (parsed) {
 
let previewHtml = parsed.htmltext;
let summaryHtml = parsed.htmlsummary.replaceAll2('API', ep.pageToEdit);
$('#anr-preview-text').append(previewHtml);
$('#anr-preview-summary').append(summaryHtml);
$('.autocomment a').css('color', 'gray'); // Change color of section spec in summary
$('.anr-preview-dialog a').attr('target', '_blank'); // Open all links on a new tab
$('#anr-preview-body').css('display', 'block');
$('#anr-preview-loading').remove();
$('#anr-preview-warning').css('display', 'inline');
 
} else {
$('#anr-preview-loading').text('プレビューの読み込みに失敗しました').css('color', 'MediumVioletRed');
setTimeout(function(){
$('.anr-preview-dialog').dialog('close');
}, 5000);
}
 
},
'buttons': [{
'text': '閉じる',
'click': function(){
$(this).dialog('close');
}
}]
});
}
 
/**
* Convert wikitext to its HTML format
* @param {String} wikitext The wikitext to convert
* @param {String} wikisummary The summary to convert
* @returns {{htmltext: string, htmlsummary: string}}
*/
async function convertWikitextToHtml(wikitext, wikisummary) {
return new Promise(function(resolve, reject) {
 
$.ajax({
'url': mw.util.wikiScript('api'),
'data': {
'format': 'json',
'action': 'parse',
'text': wikitext,
'summary': wikisummary,
'contentmodel': 'wikitext',
'prop': 'text',
'disableeditsection': true
},
'dataType': 'json',
'type': 'POST',
success: function(res) {
resolve({
'htmltext': res.parse.text['*'],
'htmlsummary': res.parse.parsedsummary['*']
});
},
error: function(err) {
console.log(err);
resolve();
}
});
 
});
}
 
// Function for the 'report' button of the dialog
function reportBtn() {
 
// Check if the necessary fields are filled and get edit information
let ep = editPrep();
if (ep.rqFieldsEmpty) {
alert('必須項目が入力・選択されていません'); // Show error and cancel the edit
return;
}
 
// If the inputs have duplicates in them
if (ep.duplicates.length !== 0) {
 
let confirmMsg =
'以下の利用者について、重複入力がある可能性があります。\n\n' +
ep.duplicates.join(', ') + '\n\n' +
'報告を続行する場合は OK を、フォームに戻る場合は Cancel を押してください';
if (confirm(confirmMsg) === false) { // If cancelled
return;
}
 
},
'buttons': [{
 
// 'Preview'Variables for buttonedit
let $dialog = 'text': $('プレビュー.anr-modal-dialog',);
let msgEditing = 'click':<div function()class="anr-editing" {/>';
let msgDone = ''; // Message to show when edit attempt is done
let wikiPagename = ep.pageToEdit + '#' + ep.sectionToEdit; // The wiki pagename for link
let editFailed = false; // Boolean value to pass to function when edit attempt is done
 
// Check if the necessary fields are filled and getChange editdialog informationcontent
$dialog.find('form').css('display', 'none'); // Hide dialog let ep = editPrep();content
$dialog.dialog({'buttons': [] }); // Hide the if (ep.rqFieldsEmpty) {button
$dialog.append(msgEditing);
alert('必須項目が入力・選択されていません'); // Show error and cancel the preview
 
return;
// For debugging
//ep.pageToEdit = '利用者:Dragoniez/test';
//ep.editSummary = 'Test edit via mediawiki API' + scriptAd;
 
/**
* Function to check block status before edit
* @returns {Array} [] if no one is blocked, [user1, user2...] if someone is blocked
*/
async function preeditBlockStatusQuery() {
 
// Update message on the dialog
msgEditing =
`<p>報告対象者のブロック情報を取得しています${toggleLoadingSpinner('add')}</p>`;
$('.anr-editing').append(msgEditing);
 
// Extract users and IPs from the array
let tar = [];
for (let i = 0; i < ep.users.length; i++) {
switch(ep.types[i]) {
case 'UNL':
case 'User2':
case 'IP2':
if (!isInArray(ep.users[i], tar)) {
tar.push(ep.users[i]);
}
break;
case 'logid':
if (Logids[ep.users[i]] !== undefined) { // If the logid can be converted to a username
if (!isInArray(Logids[ep.users[i]], tar)) {
tar.push(Logids[ep.users[i]]); // Push username instead of logid
}
}
break;
case 'diff':
case 'none':
// Do nothing
}
}
 
// Check if any of the users is blocked
const blocked = await getBlocked(tar);
 
// If any of the users is blocked
if (blocked.length !== 0) {
 
// Update message on the dialog
msgEditing =
toggleLoadingSpinner('remove') +
`<p style="color: MediumVioletRed">ブロック済みの利用者を検出しました</p>`;
$('.anr-editing').append(msgEditing);
//let Preview dialog contourinputVal;
constlet ANSMisc = `<a href="${mw.util.getUrl('WP:AN/S#OTH')}" target="_blank">WP:AN/S#その他</a>`bsLinkDiv;
let previewDiv =$bsLink;
'<div class="anr-preview-dialog" title="AN Reporter Preview">' +
' <div id="anr-preview-header" style="padding: 0.5em;">' +
' <p id="anr-preview-loading" style="font-weight: bold">' +
' プレビューを読み込み中...' +
' </p>' +
' <p id="anr-preview-warning" style="display: none;">' +
' 注意1: このプレビュー上のリンクは全て新しいタブで開かれます' +
' <br>' +
` 注意2: 報告先が ${ANSMisc} の場合、このプレビューには表示されませんが「他X月X日」のヘッダーは必要に応じて自動挿入されます` +
' </p>' +
' </div>' +
' <div id="anr-preview-body" style="display: none; font-size: 1.1em; padding-top: 1em; border-top: 1px solid silver;">' +
' <div id="anr-preview-text" style="border: 1px solid silver; padding: 0.2em 0.5em; background: white;">' +
// previewHtml
' </div>' +
' <div id="anr-preview-summary" style="margin-top: 0.8em; border: 1px solid silver; padding: 0.2em 0.5em; background: white;">' +
// summaryHtml
' </div>' +
' </div>' +
'</div>';
 
// Show previewUpdate dialog
$for ('body'let i = 1; i < Infinity; i++).append(previewDiv); { // Loop through all inputs
 
$('.anr-preview-dialog').dialog({
'height':if 'auto',($(`#anr-user${i}-input`).length === 0) { // if selector is not found
'width': $('#content').width() * 0.8,
'modal': true, break; // exit for
'buttons': [{
} else { // 'text':if '閉じる',selector is found
 
'click': function(){
inputVal = $(this`#anr-user${i}-input`).val().dialogtrim2('close');
$bsLinkDiv = $(`#anr-user${i}-blockstatus-div`);
$bsLink = $(`#anr-user${i}-blockstatus`);
 
$bsLinkDiv.css('display', 'none'); // Temporarily hide the div
if (isInArray(inputVal, blocked)) {
$bsLink.attr('href', mw.util.getUrl('特別:投稿記録/' + inputVal));
$bsLinkDiv.css('display', 'block');
}
}],
'open': function(){
 
// CSS}
dialogCSS();}
 
} else // Convert text on the dialog to html{
new mw.Api().get({
'action': 'parse',
'text': ep.textToSubmit,
'summary': ep.editSummary,
'contentmodel': 'wikitext',
'prop': 'text',
'disableeditsection': true,
'formatversion': 2
}).then(function(res){
 
// Update message on the if (res && res.parse) {dialog
msgEditing =
toggleLoadingSpinner('remove') +
`<p style="color: MediumSeaGreen">ブロック済みの利用者は検出されませんでした</p>`;
$('.anr-editing').append(msgEditing);
 
let previewHtml = res.parse.text;}
return let rep = new RegExp('API', 'g')blocked;
let summaryHtml = res.parse.parsedsummary.replace(rep, ep.pageToEdit);
$('#anr-preview-text').append(previewHtml);
$('#anr-preview-summary').append(summaryHtml);
$('.autocomment a').css('color', 'gray'); // Change color of section spec in summary
$('.anr-preview-dialog a').attr('target', '_blank'); // Open all links on a new tab
$('#anr-preview-body').css('display', 'block');
$('#anr-preview-loading').css('display', 'none');
$('#anr-preview-warning').css('display', 'inline');
 
}

} else {/**
* Function to check duplicate reports
$('#anr-preview-loading').text('プレビューの読み込みに失敗しました').css('color', 'red');
* @returns {{wikitext: string, reportees: Array}} wikitext === null if sections aren't found, wikitext === setTimeout(function(){''
* if there's no duplicate, wikitext === SECTIONTEXT to fetch preview from if there's any. If $('.anr-preview-dialog').dialog('close');SECTIONTEXT
* is returned, reportees === [reportee1, reportee2...], without logids that can be converted to }, 3000);usernames.
}*/
async function preeditDuplicateReportQuery() {
// Update message on the dialog
msgEditing =
`<p>重複報告情報を取得しています${toggleLoadingSpinner('add')}</p>`;
$('.anr-editing').append(msgEditing);
// Get sections and the whole wikitext of the page to which to report
async function getWikitextAndSectionInfo(){
return new Promise(function(resolve) {
new mw.Api().get({
'action': 'parse',
'page': ep.pageToEdit, // May need to change this parameter for debugging
'prop': 'wikitext|sections',
'formatversion': '2'
}).then(function(res){
resolve({
'sections': res.parse.sections,
'wikitext': res.parse.wikitext
});
});
});
}
}},const {parsed = await getWikitextAndSectionInfo();
let sections = parsed.sections; // Array of objects
let wikitext = parsed.wikitext; // String
let sectiontitles = [];
let sectionheaders = ['']; // Array of equal-enclosed section headers (e.g. == SECTION ==)
// Note: the top section has no header, thus arr[0] = ''
 
// 報告Get buttonsection titles and their corresponding equal-enclosed wikitext
'text':for '報告',(let i = 0; i < sections.length; i++) {
'click': function() {
 
// CheckThe iftranscluded the'新規依頼' necessarysections fieldson WP:AN/S are filledduplicate andnames, gethence editshouldn't be included in the informationarray
letif ep(sections[i].index.indexOf('T') === editPrep(-1); { // If the section is not loaded from another page
if (ep.rqFieldsEmpty) {
alert('必須項目が入力・選択されていません'); // Show error and cancel the edit
return;
}
 
sectiontitles.push(sections[i].line); // VariablesGet forsection edittitles
let $dialog = $(this);
let width = $dialog.width switch(sections[i].level); { // Get equal-enclosed section headers
let msgEditing = case '2':
' <div class sectionheaders.push('="anr-editing">= ' + sections[i].line + ' ==');
' <p>最新版を取得しています</p>' + break;
' </div> case '3';:
let msgDone = ''; // Message to show when edit attempt is donesectionheaders.push('=== ' + sections[i].line + ' ===');
let wikiPagename = ep.pageToEdit + '#' + ep.sectionToEdit; // The wiki pagename for linkbreak;
let editFailed = false; // Boolean value to passcase to function when edit attempt is done'4':
sectionheaders.push('==== ' + sections[i].line + ' ====');
break;
case '5':
sectionheaders.push('===== ' + sections[i].line + ' =====');
break;
}
 
// Change dialog content}
$dialog.find('form').css('display', 'none'); // Hide dialog content}
$dialog.dialog('option', 'width', width);
// The sections in $dialog.dialog({'buttons':which []to }); //search Hidefor theduplicate buttonreports
let $dialog.append(msgEditing)tarSections;
const tarSectionsI = [
getSectionI(true),
getSectionI(false),
'不適切な利用者名',
'公開アカウント',
'公開プロキシ・ゾンビマシン・ボット・不特定多数',
'犯罪行為またはその疑いのある投稿'
];
const tarSectionsS = [
'著作権侵害・犯罪予告',
'名誉毀損・なりすまし・個人情報',
'妨害編集・いたずら',
'その他',
ep.sectionToEdit
];
const tarSections3RR = ['3RR'];
const tarSectionsSubpagedLTA = ['新規依頼'];
 
switch(ep.pageToEdit) // For debugging{
//ep.pageToEditcase = '利用者ANI:Dragoniez/test';
//ep.editSummary = 'Test edit viatarSections mediawiki= API'tarSectionsI;
break;
case ANS:
tarSections = tarSectionsS;
break;
case AN3RR:
tarSections = tarSections3RR;
break;
case Iccic:
case ISECHIKA:
case KAGE:
case KIYOSHIMA:
case SHINJU:
tarSections = tarSectionsSubpagedLTA;
break;
default: // For debugging, corresponding to the sections on [[User:Dragoniez/test]]
tarSections = tarSectionsS;
}
 
// FunctionCheck to getif the latest revision of thetarget administrator'ssections noticeboardexist
if (!arrayIsInArray(tarSections, async function getLastestRevision(sectiontitles)) {
sectionNotFound();
return {'wikitext': null};
}
 
// Separate the whole text into an array returnof new Promise(function(resolve, reject) {sections
let sectionsPiped = sectiontitles.join('|').replaceAll2('(', '\\(', ')', '\\)', '.', '\\.');
let regex = new mw.ApiRegExp().get`={2,5}\\s*(?:${sectionsPiped})\\s*={2,5}`, 'g');
let sectionContent = wikitext.split(regex); // Array of the content of each section, without section 'action': 'query',headers
'titles': ep.pageToEdit,
// Re-add to sectionContent the '== TITLE ==' header that's been removed by the split() 'prop': 'revisions',above
for (let i = 0; i < sectionContent.length; i++) 'curtimestamp': true,{
sectionContent[i] = sectionheaders[i] + 'formatversion': 2sectionContent[i];
}).done(function(res){
 
// Remove irrelevant sections from the array of the content of each section (sectionContent)
if (res && res.query && res.query.pages) { // If the latest revision is successfully retrieved
sectionsPiped = if tarSections.join(res'|').query.pages[0].missingreplaceAll2('(', !=='\\(', true')', {'\\)', //'.', If the page exists'\\.');
regex = new RegExp(`={2,5}\\s*(?:${sectionsPiped})\\s*={2,5}`, 'g');
for (let i = sectionContent.length -1; i >= 0; i--) {
if (sectionContent[i].search(regex) === -1) {
sectionContent.splice(i, 1);
}
}
console.log('The contents of each section:');
console.log(sectionContent);
 
// Get all the reportees in the inputs, and if user, try to get // Get the details of the latest revisionlogids
let baseTSreportees = res.query.pages[0].revisions[0].timestamp;
let curTS = res.curtimestamplogid;
for (let i = 0; i < ep.users.length; i++) { // Loop through all the usernames typed into the inputs
 
let user = // Update messageep.users[i];
let type = msgEditing =ep.types[i];
' <p style="color: MediumSeaGreen">取得に成功しました</p>' +
' <p>セクション番号を取得しています</p>';
$('.anr-editing').append(msgEditing);
 
if (type === 'UNL' || type === 'User2') resolve({
'baseTS': baseTS,
'curTS': curTS
});
 
if (!isInArray(user, } elsereportees)) { // If thenot pagealready doesn'tin the existarray
 
if (Logids[user] !== undefined) { // If the code already knows the msgDonelogid =for the user
'<p style="color: MediumVioletRed">エラー: 報告先のページが存在しません</p>' + manualEdit();
$('.anr-editing').append(msgDone);
$dialog.dialog('option', 'width', width);
editFailed = true;
editDone($dialog, editFailed, wikiPagename);
resolve(undefined);
 
reportees.push(user, Logids[user]); // Push }the username and the logid into the array
 
} else { // If the code doesn't know a logid for the user
 
}logid else= {await getLogid(user); // IfTry to fetch one revisionfrom retrievalthe failsAPI
if (logid !== queryFailed(undefined); { // If a valid logid is returned
resolve(undefined)Logids[user] = logid;
Logids[logid] = user;
reportees.push(user, logid); // Push the username and the logid into the array
}
}
 
});
});
}
 
//} Functionelse toif get(type the=== section number from the section title'logid') {
async function getSectionNumber() {
 
return// newuser Promise(function(resolve= numeral, reject)Logids[user] = {username
if (Logids[user] !== undefined) { // If the logid can be converted to a username
let sectionsAPI = {};
new mw.Api().get({
'action': 'parse',
'page': ep.pageToEdit,
'formatversion': 2
}).done(function(res){
 
if (res && res.parse &&!isInArray(Logids[user], res.parse.sectionsreportees)) { // If the sectioncorresponding listusername is successfullynot in the array retrieved
reportees.push(Logids[user]); // Push the username into the array
}
if (!isInArray(user, reportees)) { // If the logid is not in the array
reportees.push(user); // Push the logid into the array
}
 
} else { // If the logid cannot be converted to a // Get section numbers from section titlesusername
for (let i = 0; i < Object.keys(res.parse.sections).length; i++) {
sectionsAPI[res.parse.sections[i].line] = res.parse.sections[i].index;
}
let sectionNum = sectionsAPI[ep.sectionToEdit];
if (sectionNum === undefined) { // If section title in the dropdown is not found
 
if (!isInArray(user, reportees)) { // ShowIf the detailslogid is not ofin the errorarray
reportees.push(user); // Push the logid into the msgDone = array
'<p style="color: MediumVioletRed">取得に失敗しました</p>' +}
'<p>指定されたセクションが見つかりませんでした</p>' +
'<br>' +
'<p>考えられる原因:</p>' +
`<p>1. 編集先のページの節構成が変更された</p>` +
`<p>2. 通信に失敗した</p>` +
`<p>3. スクリプトのバグ</p>` +
manualEdit();
$('.anr-editing').append(msgDone);
 
$dialog.dialog('option', 'width', width);}
editFailed = true;
editDone($dialog, editFailed, wikiPagename);
resolve(undefined);
 
} else { // If section titleother inthan thet=UNL, dropdownt=User2, isand foundt=logid
 
if (!isInArray(user, reportees)) { // If not already in the // Update messagearray
reportees.push(user); // Push the username into the msgEditing =array
' <p style="color: MediumSeaGreen">取得に成功しました</p>' +}
' <p>最新版のテキストを取得しています</p>';
$('.anr-editing').append(msgEditing);
 
resolve(sectionNum);}
 
logid = undefined; // Reset before the next }iteration
}
 
} else { // If the section list retrieval fails
// Extract UserAN templates and find duplicate queryFailed();reports
let templates = resolve(undefined)[];
let dupTemplates = [];
let duplicateFound = false;
for (let i = sectionContent.length -1; i >= 0; i--) { // Loop through all the relevant section texts
/* Extract UserAN templates from the section text
* This returns an array of the occurrences of UserAN, e.g. [{{UserAN|t=UNL|ウィキ助}}, ...] */
templates = findTemplates(sectionContent[i], 'useran');
if (templates.length !== 0) { // If the section text contains at least one UserAN
for (let j = templates.length -1; j >= 0; j--) { // Loop through all the occurences of UserAN
if (stringContainsElementInArray(templates[j], reportees)) { // If there's a duplciate report
if (!isInArray(templates[j], dupTemplates)) {
dupTemplates.push(templates[j]); // List the occurence as a duplicate
}
}) duplicateFound = true;
});
}
if (!duplicateFound) { // Remove the section text from the array if it doesn't involve duplicate reports
sectionContent.splice(i, 1);
}
} else { // If the section text has no UserAN
sectionContent.splice(i, 1); // Remove the section text from the array
}
duplicateFound = false; // Reset
}
console.log('Templates that involve potential duplicate reports:');
console.log(dupTemplates);
console.log('Section contents that involve the templates:');
console.log(sectionContent);
 
// Function to get the text to replace with the currentReturn text inand theupdate sectiondialog
if (sectionContent.length === 0) async{ function// getTextToReplace(sectionNum)If {there's no duplicate report
 
// Update message on returnthe new Promise(function(resolve, reject) {dialog
msgEditing =
`<p style="color: MediumSeaGreen">重複報告は検出されませんでした${toggleLoadingSpinner('remove')}</p>`;
$('.anr-editing').append(msgEditing);
 
// Return an empty string
return {'wikitext': ''};
 
} else { // If there're duplicate reports
 
// Update message on the dialog
msgEditing =
`<p style="color: MediumVioletRed">重複報告の可能性があります${toggleLoadingSpinner('remove')}</p>`;
$('.anr-editing').append(msgEditing);
 
// Highlight all the duplciate UserAN occurences
sectionContent = sectionContent.join(''); // Merge the separate sections
for (let i = 0; i < dupTemplates.length; i++) {
sectionContent = sectionContent.replaceAll2(dupTemplates[i], '<span style="background-color: #FEC493">' + dupTemplates[i] + '</span>');
}
// Get rid of logids that can be converted to usernames from the array 'reportees'
for (let i = reportees.length -1; i >= 0; i--) {
if (String(reportees[i]).match(/^\d+$/) !== null && Logids[reportees[i]] !== undefined) {
reportees.splice(i, 1);
}
}
// GetReturn thewikitext textto offetch thepreview revisionfrom
return new mw.Api().get({
'actionwikitext': 'parse'sectionContent,
'pagereportees': ep.pageToEdit,reportees
'section': sectionNum,};
'prop': 'wikitext',
'formatversion': 2
}).done(function(res){
 
if (res && res.parse) {}
}
 
// Function to get the latest revision of the administrator's // Update messagenoticeboard
async function getLastestRevision() msgEditing ={
' <p style="color: MediumSeaGreen">取得に成功しました</p>' +
' <p>報告を試みています</p>';
$('.anr-editing').append(msgEditing);
 
return new Promise(function(resolve, reject) // Get the whole text to append{
let wikitextObtained = res.parse.wikitext;
let wholeTextToSubmit;
const delimiter = '<!-- ◆';
const miscHeader = `{{bgcolor|#eee|{{Visible anchor|他${today()}}}|div}}`;
 
msgEditing if (ep.reportToANS) { // If the target is WP:AN/S=
`<p>最新版を取得しています${toggleLoadingSpinner('add')}</p>`;
$('.anr-editing').append(msgEditing);
new mw.Api().get({
'action': 'query',
'titles': ep.pageToEdit,
'prop': 'revisions',
'curtimestamp': true,
'formatversion': 2
}).done(function(res){
 
if (res && res.query && res.query.pages) { // Add div ifIf the targetlatest sectionrevision is 'その他' but lacks div for the currentsuccessfully dateretrieved
if (epres.sectionToEditquery.pages[0].missing =!== 'その他'true) &&{ wikitextObtained.indexOf(miscHeader)// ===If -1)the {page exists
ep.textToSubmit = '; ' + miscHeader + '\n\n' + ep.textToSubmit;
}
 
// Get the timestamps of the latest revision // Insert text intoand the rightAPI placequery
let baseTS = res.query.pages[0].revisions[0].timestamp; // The TS of letthe wikitextSplitlatest = wikitextObtained.split(delimiter);revision
let curTS = res.curtimestamp; // The TS of if (wikitextSplit.length ===the 3)API {query
 
// Update message on the wholeTextToSubmit = dialog
msgEditing wikitextSplit[0] + delimiter + trimA(wikitextSplit[1]) + '\n\n' +=
' <p style="color: ep.textToSubmit + '\n\nMediumSeaGreen">取得に成功しました</p>' + delimiter + wikitextSplit[2];
` resolve<p>セクション番号を取得しています${toggleLoadingSpinner(wholeTextToSubmit'move')}</p>`;
$('.anr-editing').append(msgEditing);
 
} else { // IfReturn sectionthe structuretimestamps hasas beenan changedobject
resolve({
'baseTS': baseTS,
'curTS': curTS
});
 
} else { // ShowIf errorthe andpage quit thedoesn't procedureexist
msgDone =
'<p style="color: MediumVioletRed">報告に失敗しました</p>' +
'<p>セクション構造が改変されているため、' +
`<a href="${mw.util.getUrl('User talk:Dragoniez/AN Reporter')}" target="_blank">開発者</a>` +
'に連絡をお願いします</p>' +
manualEdit();
$('.anr-editing').append(msgDone);
 
msgDone = $dialog.dialog('option', 'width', width);
toggleLoadingSpinner('remove') editFailed = true;+
'<p style="color: MediumVioletRed">エラー: 報告先のページが存在しません</p>' + editDone($dialog, editFailed, wikiPagename);
resolvemanualEdit(undefined);
$('.anr-editing').append(msgDone);
editFailed = true;
editDone($dialog, editFailed, wikiPagename);
resolve();
 
}
 
} else { // If therevision targetretrieval is WP:AN/I or WP:AN/3RRfails
queryFailed();
resolve();
}
 
wholeTextToSubmit = trimA(wikitextObtained}) + '\n\n' + ep.textToSubmit;
resolve(wholeTextToSubmit});
}
 
// Function to get the section number from the section title }
async function getSectionNumber() {
return new Promise(function(resolve, reject) {
new mw.Api().get({
'action': 'parse',
'page': ep.pageToEdit,
'formatversion': 2
}).done(function(res){
 
if (res && res.parse && res.parse.sections) { // If the section list is successfully retrieved
 
// Get the titles of all sections and their section numbers
let sectionsAPI = {};
for (let i = 0; i < Object.keys(res.parse.sections).length; i++) {
sectionsAPI[res.parse.sections[i].line] = res.parse.sections[i].index;
}
// Return a section number if the section is found, undefined if not
let sectionNum = sectionsAPI[ep.sectionToEdit];
if (sectionNum === undefined) { // If section title in the dropdown is not found
 
// Show the details of the error
sectionNotFound();
resolve();
 
} else { // If section title in the dropdown is found
 
// Update message
msgEditing =
' <p style="color: MediumSeaGreen">取得に成功しました</p>' +
` <p>最新版のテキストを取得しています${toggleLoadingSpinner('move')}</p>`;
$('.anr-editing').append(msgEditing);
 
resolve(sectionNum);
 
}
 
} else { // If the section list retrieval fails
queryFailed();
resolve();
}
 
});
 
});
}
 
// Function to get the text to replace with the current text in the section
async function getTextToReplace(sectionNum) {
return new Promise(function(resolve, reject) {
// Get the text of the latest revision
new mw.Api().get({
'action': 'parse',
'page': ep.pageToEdit,
'section': sectionNum,
'prop': 'wikitext',
'formatversion': 2
}).done(function(res){
 
if (res && res.parse) {
 
// Update message
msgEditing =
' <p style="color: MediumSeaGreen">取得に成功しました</p>' +
` <p>報告を試みています${toggleLoadingSpinner('move')}</p>`;
$('.anr-editing').append(msgEditing);
 
// Get the whole text to append
let wikitextObtained = res.parse.wikitext;
let wholeTextToSubmit;
const delimiter = '<!-- ◆';
const miscHeader = `{{bgcolor|#eee|{{Visible anchor|他${today()}}}|div}}`;
 
if (ep.reportToANS) { // If the target is WP:AN/S
 
}// elseAdd {div //if the target section is 'その他' but lacks div Iffor wikitextthe retrievalcurrent failsdate
if (ep.sectionToEdit === 'その他' queryFailed&& wikitextObtained.indexOf(miscHeader); === -1) {
resolve(undefined)ep.textToSubmit = '; ' + miscHeader + '\n\n' + ep.textToSubmit;
}
 
}); // Insert text into the right place
} let wikitextSplit = wikitextObtained.split(delimiter);
} if (wikitextSplit.length === 3) {
 
// Function to edit the page wholeTextToSubmit =
function edit(sectionNum, text, baseTS, curTS) { wikitextSplit[0] + delimiter + wikitextSplit[1].trim2() + '\n\n' +
ep.textToSubmit + '\n\n' + delimiter + wikitextSplit[2];
$.ajax resolve({wholeTextToSubmit);
'url': mw.util.wikiScript('api'),
'data': {
'format': 'json',
'action': 'edit',
'title': ep.pageToEdit,
'section': sectionNum,
'text': text,
'summary': ep.editSummary,
'basetimestamp': baseTS,
'starttimestamp': curTS,
'token': mw.user.tokens.get('csrfToken'),
'curtimestamp': true
},
'dataType': 'json',
'type': 'POST',
success: function(res) {
// If the edit was successful
if (res && res.edit && res.edit.result == 'Success') {
setTimeout(async function(){
let diffNum = await getDiffNum(res.curtimestamp); // Get diff number
// Show message
$('.anr-editing').append(`<p style="color: MediumSeaGreen">報告が完了しました</p>`);
$dialog.dialog('option', 'width', width);
editDone($dialog, editFailed, wikiPagename, diffNum);
return;
 
} else { // },If the structure of the section has been 0);changed
 
// IfShow theerror editand quit the failedprocedure
} else if (res && res.error) {msgDone =
toggleLoadingSpinner('remove') +
// Show the details of the error
msgDone =
'<p style="color: MediumVioletRed">報告に失敗しました</p>' +
'<brp>セクション構造が改変されているため、' +
'`<p>詳細a href="${mw.util.getUrl('User talk:Dragoniez/AN Reporter')}" target="_blank">開発者</pa>'` +
`<p>${res.error.info}'に連絡をお願いします</p>`' +
manualEdit();
$('.anr-editing').append(msgDone);
 
$dialog.dialog('option', 'width', width);
editFailed = true;
editDone($dialog, editFailed, wikiPagename);
returnresolve();
 
// If unknown error occurs}
} else {
 
} else { // If the target is WP:AN//I Showor messageWP:AN/3RR
msgDone =
'<p style="color: MediumVioletRed">不明なエラーが発生しました</p>' + manualEdit();
$('.anr-editing').append(msgDone);
 
wholeTextToSubmit = $dialogwikitextObtained.dialogtrim2('option',) + 'width\n\n', width)+ ep.textToSubmit;
editFailed = trueresolve(wholeTextToSubmit);
editDone($dialog, editFailed, wikiPagename);
return;
}
 
}
 
});
} else { // If wikitext retrieval fails
queryFailed();
resolve();
}
 
});
 
});
}
 
// Function to edit the page
function edit(sectionNum, text, baseTS, curTS) {
$.ajax({
'url': mw.util.wikiScript('api'),
'data': {
'format': 'json',
'action': 'edit',
'title': ep.pageToEdit,
'section': sectionNum,
'text': text,
'summary': ep.editSummary,
'basetimestamp': baseTS,
'starttimestamp': curTS,
'token': mw.user.tokens.get('csrfToken'), // May comment this out for debugging
'curtimestamp': true
},
'dataType': 'json',
'type': 'POST',
success: function(res) {
} // If the edit was successful
if (res && res.edit && res.edit.result == 'Success') {
setTimeout(async function(){
const diffNum = await getDiffNum(res.curtimestamp); // Get diff number
// Show message
toggleLoadingSpinner('remove');
$('.anr-editing').append(`<p style="color: MediumSeaGreen">報告が完了しました</p>`);
editDone($dialog, editFailed, wikiPagename, diffNum);
return;
 
// Function to execute report }, 0);
async function reportUser() {
 
let// revIf =the awaitedit getLastestRevision();failed
let} baseTS,else if (res && res.error) { curTS;
if (rev === undefined) {
// Show the details of the error
msgDone =
toggleLoadingSpinner('remove') +
'<p style="color: MediumVioletRed">報告に失敗しました</p>' +
'<br>' +
'<p>詳細:</p>' +
`<p>${res.error.info}</p>` +
manualEdit();
$('.anr-editing').append(msgDone);
 
editFailed = true;
editDone($dialog, editFailed, wikiPagename);
return;
 
// If unknown error occurs
} else {
baseTS = rev.baseTS;
curTS = rev.curTS;
}
 
let sectionNum = await getSectionNumber();// Show message
if (sectionNum === undefined) {msgDone =
return;toggleLoadingSpinner('remove') +
} '<p style="color: MediumVioletRed">不明なエラーが発生しました</p>' +
manualEdit();
$('.anr-editing').append(msgDone);
 
let text = await getTextToReplace(sectionNum)editFailed = true;
if editDone(text$dialog, ===editFailed, undefinedwikiPagename) {;
return;
 
}
 
edit(sectionNum, text, baseTS, curTS);}
});
}
 
// Function to execute } report
async function reportUsers() {
 
// Check the block // Functionstatus toof showthe messagereportees whenif editthe attemptcheckbox is donechecked
let blocked = function queryFailed() {[];
if (checkBlockStatusBeforeEdit) msgDone = {
blocked = await preeditBlockStatusQuery(); '<p// style="color:Query MediumVioletRed">取得に失敗しました</p>who's + manualEdit();blocked
$('.anr-editing').append(msgDone);}
$dialog.dialog('option', 'width', width);
editFailed = true;
editDone($dialog, editFailed, wikiPagename);
}
 
if (blocked.length !== 0) { // FunctionIf toany generateof the html for the manul editreportees helperis tabblocked
function manualEdit() {
let meHtml =
'<br>' +
'<p>手動編集用:</p>' +
`<textarea disabled rows="4" style="width: 100%">${ep.textToSubmit}</textarea>` +
'<br>' +
'<p>要約:</p>' +
`<textarea disabled rows="2" style="width: 100%">${ep.editSummary.replace(scriptAd, '')}</textarea>`;
return meHtml;
}
 
// ReportUpdate thedialog user(s)buttons
reportUser$dialog.dialog();{
'buttons': [{
 
} 'text': '続行',
}] 'click': function(){
$(this).dialog({'buttons': [] });
reportUsersSecondProcedure();
}
 
// ********** EVENT HANDLERS AND FUNCTIONS ********** }, {
 
function editPrep() { 'text': '戻る',
let rqFieldsEmpty = false; 'click': function(){
$('.anr-modal-dialog form').css('display', 'block');
$('.anr-editing').remove();
$dialog.dialog({
'buttons': [{
'text': 'プレビュー',
'click': previewBtn
}, {
'text': '報告',
'click': reportBtn
}]
});
}
 
}, {
 
'text': '中止',
'click': function(){
$(this).dialog('close');
}
 
}]
});
 
} else { // If no one is blocked
 
reportUsersSecondProcedure();
 
// Check if at least one username is given and get users to report (and their UserAN types)
let users = [];
let types = [];
for (let i = 1; i < Infinity; i++) { // Loop through all inputs
if ($(`#anr-user${i}-input`).length === 0) { // if selector is not found
break; // exit for
} else { // if selector is found
if (trimA($(`#anr-user${i}-input`).val()) !== '') { // if input is not empty
users.push(trimA($(`#anr-user${i}-input`).val())); // Push the username into the array
types.push($(`#anr-user${i}-select`).children('option').filter(':selected').text()); // Push the UserAN type into the array
}
}
}
 
//async Getfunction thereportUsersSecondProcedure() name of the section to edit{
let pageToEdit = $('#anr-target-options').children('option').filter(':selected').text();
let sectionToEdit = '選択してください';
let ANSOptSelected = $('#anr-section-options-s').find('option').filter(':selected').text();
let reportToANS = false;
 
if (pageToEdit === ANI) { // IfCheck WP:AN/Iduplicate isreports selected asif the targetcheckbox page tois editchecked
let dr;
if (checkDuplicateReportsBeforeEdit) {
dr = await preeditDuplicateReportQuery();
}
 
sectionToEdit = $switch('#anr-section-options-i')dr.children('option'wikitext).filter(':selected').text(); {
case null: // Sections aren't found
return;
case undefined: // checkDuplicateReportsBeforeEdit === false
case '': // No duplicate report found
reportUsersFinalProcedure();
return;
default: // Possible duplicate reports present
 
} else if (pageToEdit === ANS) { // If WP:AN/S is selected as the target// pageUpdate todialog editbuttons
$dialog.dialog({
'buttons': [{
 
reportToANS = true; 'text': '確認',
if (ANSOptSelected === 'Iccic系click': function(Iccic)') {
pageToEdit = Iccic previewDuplicateReports(dr.wikitext, dr.reportees);
sectionToEdit = '新規依頼'; }
 
} else if (ANSOptSelected === 'いせちか系 (ISECHIKA)') {
pageToEdit = ISECHIKA; }, {
 
sectionToEdit = '新規依頼';
} else if (ANSOptSelected === '影武者系(KAGE)text'): {'続行',
pageToEdit = KAGE; 'click': function(){
sectionToEdit = $(this).dialog({'新規依頼buttons': [] });
} else if (ANSOptSelected === '清島達郎系 reportUsersFinalProcedure(清島、KIYOSHIMA)') {;
pageToEdit = KIYOSHIMA; }
 
sectionToEdit = '新規依頼';
} else if (ANSOptSelected === '真珠王子系(SHINJU)') }, {
 
pageToEdit = SHINJU;
sectionToEdit = 'text': '新規依頼戻る';,
'click': function(){
$('.anr-modal-dialog form').css('display', 'block');
$('.anr-editing').remove();
$dialog.dialog({
'buttons': [{
'text': 'プレビュー',
'click': previewBtn
}, {
'text': '報告',
'click': reportBtn
}]
});
}
 
}, {
 
'text': '中止',
'click': function(){
$(this).dialog('close');
}
 
}]
});
 
}
 
}
 
async function reportUsersFinalProcedure() {
const rev = await getLastestRevision();
if (rev === undefined) {
return;
} else {
sectionToEditvar baseTS = ANSOptSelectedrev.baseTS;
var curTS = rev.curTS;
}
 
} else if (pageToEdit ===const AN3RR)sectionNum {= //await If WP:AN/3RR is selected as the target page to editgetSectionNumber();
if (sectionNum === undefined) {
return;
}
 
sectionToEditconst text = '3RR'await getTextToReplace(sectionNum);
if (text === undefined) {
return;
}
 
edit(sectionNum, text, baseTS, curTS);
 
}
 
if ( // Check if necessary fields are** filled
* Function to preview duplicate reports on a new dialog
pageToEdit === '選択してください' || // The page dropdown's remained 選択してください
* @param {String} wikitext The wikitext to convert to html and preview
sectionToEdit === '選択してください' || // The section dropdown's remained 選択してください
* @param {Array} reportees The array of reportees, logids should be converted to usernames if possible beforehand
trimA($('#anr-reason-text').val()) === '' || // No reason is given
users.length === 0 *// No username is given
function previewDuplicateReports(wikitext, reportees) {
rqFieldsEmpty = true;
// Show logids in parentheses
for (let i = 0; i < reportees.length; i++) {
if (Logids[reportees[i]]) { // If the code knows the logid for a user
reportees[i] += ' (' + Logids[reportees[i]] + ')'; // Show the logid in parentheses
}
}
 
// Create dialog
let duplicateReportPreviewDiv =
'<div class="anr-drpreview-dialog" title="AN Reporter Duplicate Report Preview" style="max-height: 80vh;">' +
' <div id="anr-drpreview-header" style="padding: 0.5em;">' +
' <p id="anr-drpreview-loading">' +
` 読み込み中${toggleLoadingSpinner('add')}` +
' </p>' +
' <p id="anr-drpreview-userlist" style="display: none; font-size: larger">' +
' <span style="font-weight: bold">入力された利用者名:</span>' +
' <br>' +
reportees.join(', ') +
' </p>' +
' </div>' +
' <div id="anr-drpreview-body" style="display: none; font-size: 1.1em; padding: 0.5em; border: 1px solid silver; background-color: white;">' +
// Added when the dialog is opened
' </div>' +
'</div>';
$('body').append(duplicateReportPreviewDiv);
 
// Show preview dialog
$('.anr-drpreview-dialog').dialog({
'height': 'auto',
'width': $('#content').width() * 0.8,
'modal': true,
'position': { my: 'center', at: 'top', of: window },
'open': async function(){
 
// CSS
dialogCSS();
 
// Convert the wikitext to an html form
const wikitextInHtml = await convertWikitextToHtml(wikitext, '');
if (wikitextInHtml) {
$('#anr-drpreview-body').append(wikitextInHtml.htmltext);
$('.anr-drpreview-dialog a').attr('target', '_blank'); // Open all links on a new tab
$('#anr-drpreview-body').css('display', 'block');
$('#anr-drpreview-loading').remove();
$('#anr-drpreview-userlist').css('display', 'inline');
 
} else {
$('#anr-drpreview-loading').text('読み込みに失敗しました').css('color', 'MediumVioletRed');
setTimeout(function(){
$('.anr-drpreview-dialog').dialog('close');
}, 10000);
}
},
'buttons': [{
'text': '閉じる',
'click': function(){
$(this).dialog('close');
}
}]
});
 
}
 
// UserANFunction templateto andshow themessage reasonwhen ofedit theattempt reportis done
constfunction UserANqueryFailed() = '{{UserAN|t=TYPE|USER}}';
let reason msgDone = trimA($('#anr-reason-text').val());
toggleLoadingSpinner('remove') +
if (reason.substring(reason.length - 4) !== '~~~~') { // If reason doesn't contain signature, add one
reason'<p style="color: reasonMediumVioletRed">取得に失敗しました</p>' + '--~~~~';
manualEdit();
$('.anr-editing').append(msgDone);
editFailed = true;
editDone($dialog, editFailed, wikiPagename);
}
 
// GetFunction to generate the html for the manual edit summaryhelper tab
constfunction editSummarySectionmanualEdit() = '/*' + sectionToEdit + '*/';{
let meHtml =
'<br>' +
'<p>手動編集用:</p>' +
`<textarea disabled rows="4" style="width: 100%">${ep.textToSubmit}</textarea>` +
'<br>' +
'<p>要約:</p>' +
`<textarea disabled rows="2" style="width: 100%">${ep.editSummary.replace(scriptAd, '')}</textarea>`;
return meHtml;
}
 
// Function to show error message if sections that must be there are not found
let editSummary =
trimAfunction sectionNotFound($('#anr-summary-text').val()) === '' ? {
editSummarySection + genEditSummary().replace(' - ', '') + scriptAd:msgDone =
editSummarySection + trimA($ toggleLoadingSpinner('#anr-summary-textremove').val()) + scriptAd;
'<p style="color: MediumVioletRed">取得に失敗しました</p>' +
'<p>指定されたセクションが見つかりませんでした</p>' +
'<br>' +
'<p>考えられる原因:</p>' +
`<p>1. 編集先のページの節構成が変更された</p>` +
`<p>2. 通信に失敗した</p>` +
`<p>3. スクリプトのバグ</p>` +
manualEdit();
$('.anr-editing').append(msgDone);
 
// Get text to addeditFailed to= the pagetrue;
let textToSubmit = '' editDone($dialog, editFailed, wikiPagename);
if (users.length < 2) { // If user to report is just one
textToSubmit = '\* ' + UserAN.replace('TYPE', types[0]).replace('USER', users[0]) + ' - ' + reason;
} else { // If two or more
for (let i = 0; i < users.length; i++) {
textToSubmit += '\* ' + UserAN.replace('TYPE', types[i]).replace('USER', users[i]) + '\n';
}
textToSubmit += ': ' + reason;
}
 
// ReturnReport valuesthe user(s)
return {reportUsers();
 
'pageToEdit': pageToEdit,
'sectionToEdit': sectionToEdit,}
 
'reportToANS': reportToANS,
/** 'rqFieldsEmpty': rqFieldsEmpty,
* Function to extract templates from 'editSummary': editSummary,wikitext
* @param {String} text The text in 'textToSubmit':which textToSubmitto search for templates
* @param {String} templateName [Optional] Specify the template name (case-insensitive)
* @returns {Array} An array of the extracted templates
*/
function findTemplates(text, templateName) {
 
// Split the text with '{{', the head delimiter of templates
const textSplit = text.split('{{');
let templates = [];
/* Explanation
* If the text to parse is "{{UserAN|t=none|{{Logid|123456789|{{User|EXAMPLE}}|s=}}}} - {{UserAN|USER}} is the same.",
* textSplit = ['', 'UserAN|t=none|', 'Logid|123456789|', 'User|EXAMPLE}}|s=}}}} - ', 'UserAN|USER}} is the same.']
*/
if (textSplit.length === 0) { // If the text has no tempalte in it
return templates; // Return an empty array
} else { // If the text has some templates in it
 
for (let i = 1; i < textSplit.length; i++) { // Loop through all elements (but arr[0]) in the split array
let TLCloseCnt = (textSplit[i].match(/\}\}/g) || []).length; // Get the number of '}}' in the split segment
let temp = ''; // Temporary escape hatch
switch(true) {
case TLCloseCnt === 0: // If the split segment doesn't have any '}}'
// Do nothing
break;
case TLCloseCnt === 1: // If the split segment itself is the whole of a template
temp = '{{' + textSplit[i].split('}}')[0] + '}}';
if (!isInArray(temp, templates)) {
templates.push(temp);
}
break;
/* Explanation
* If textSplit[3] ( = 'User|EXAMPLE}}|s=}}}} - '), .split('}}') returns
* ['User|EXAMPLE', '|s=', '', ' - ']. Thus '{{' + splitArr[0] +'}}' returns '{{User|EXAMPLE}}'.
*/
case TLCloseCnt > 1: // If templates are nested
for (let j = 0; j < TLCloseCnt; j++) { // Loop through all the nests
if (j === 0) { // The innermost template
temp = '{{' + textSplit[i].split('}}')[j] + '}}'; // Same as when TLCloseCnt === 1
if (!isInArray(temp, templates)) {
templates.push(temp);
}
} else { // Nesting templates
temp = '{{' + textSplit[i - j] + temp + textSplit[i].split('}}')[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.
*/
}
}
break;
default:
// Do nothing
}
}
//console.log('Templates in the section:');
//console.log(templates);
// 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].search(templateRegExp) === -1) { // If the array element doesn't contain the template name
templates.splice(i, 1); // Remove the element
}
}
}
 
//console.log('UserAN occurrences in the section:');
//console.log(templates);
return templates;
}
}
 
// Function to change the CSS of the dialog**
* Function to add/remove/move a loading spinner
function dialogCSS() {
* @param {string} action - 'add', 'remove', or 'move'
$('.ui-dialog-content, .ui-dialog-buttonpane, .ui-corner-all, .ui-draggable, .ui-resizable').css('background', '#FFF0E4');
$('.ui-button').css({*/
function toggleLoadingSpinner(action) {
'color': 'black',
 
'background-color': 'white'
});const img = '<img ' +
'class="anr-loading-spinner" ' +
$('.ui-dialog-titlebar, .ui-dialog-titlebar-close').attr('style', 'background: #FEC493 !important;');
'src="https://upload.wikimedia.org/wikipedia/commons/4/42/Loading.gif" ' +
$('.ui-dialog').css('font-size', fSize);
'style=' +
'vertical-align: middle; ' +
'max-height: 100%; ' +
'border: 0;" ' +
'/>';
 
switch(action) {
case 'add':
return img;
case 'remove':
$('.anr-loading-spinner').remove();
return '';
case 'move':
$('.anr-loading-spinner').remove();
return img;
}
 
}
 
950 ⟶ 1,905行目:
'click': function(){
window.open(mw.util.getUrl('特別:差分/' + diffNum), '_blank');
}
};
btns.push(diffBtn);
992 ⟶ 1,947行目:
// Show the button(s) on the dialog
$dialog.dialog({
'position': { my: 'center', at: 'top+20%', of: window },
'buttons': btns
});
1,016 ⟶ 1,971行目:
 
type = $(`#anr-user${i}-select`).children('option').filter(':selected').text(); // UserAN type specified in the dropdown
reportee = trimA($(`#anr-user${i}-input`).val().trim2(); // input value
 
if (reportee !== '') { // Skip if the input value is a null string
1,032 ⟶ 1,987行目:
case 'diff':
contribs = `[[特別:差分/${reportee}|差分/${reportee}]]の投稿者`;
break;
default:
contribs = reportee;
1,064 ⟶ 2,019行目:
 
// Reset dialog when closed
$(document).onoff('dialogclose', '.anr-modal-dialog, .anr-preview-dialog', function(.anr-drpreview-dialog') {
.on('dialogclose', '.anr-modal-dialog, .anr-preview-dialog, .anr-drpreview-dialog', function() {
$(this).remove();
});
 
// Dynamically change the content of the section dropdown depending on the value selected in '報告先'
$(document).off('change', '#anr-target-options').on('change', '#anr-target-options', function(){
letconst selectedTar = $(this).children('option').filter(':selected').text();
switch(selectedTar) {
case ANI:
$('.anr-section-div').empty();
$('.anr-section-div').append(sectionsI);
$('#anr-section-options-i-date').text(getSectionI(false));
$('#anr-section-options-i').css({'width': $(this).width()});
$('.anr-section-div').css('display', 'block');
$('.anr-target-apagelink-div').css('display', 'block');
$('#anr-target-apagelink').attr('href', mw.util.getUrl(ANI));
break;
case ANS:
$('.anr-section-div').empty();
$('.anr-section-div').append(sectionsS);
$('#anr-section-options-s').select2({'width': $(this).width()});
//$('#select2-anr-section-options-s-container').attr('style', rlsCSS);
$('.anr-section-div').css('display', 'block');
$('.anr-target-apagelink-div').css('display', 'block');
$('#anr-target-apagelink').attr('href', mw.util.getUrl(ANS));
break;
case AN3RR:
$('.anr-section-div').empty();
$('.anr-section-div').css('display', 'none');
$('.anr-target-apagelink-div').css('display', 'block');
$('#anr-target-apagelink').attr('href', mw.util.getUrl(AN3RR));
break;
}
1,098 ⟶ 2,056行目:
 
// Add section name to the '報告先' link when section is specified
$(document).onoff('change', '#anr-section-options-i, #anr-section-options-s', function(){
.on('change', '#anr-section-options-i, #anr-section-options-s', function(){
let tarSection = '';
1,109 ⟶ 2,068行目:
if ($(this).find('option').filter(':selected').text() !== '選択してください') {
tarSection = '#' + $(this).find('option').filter(':selected').text();
$('#anr-target-apagelink').attr('href', mw.util.getUrl(tarPage + tarSection));
}
 
});
 
// Dynamically changeWhen the displayselection ofis thechanged form depending onin the UserANtype typedropdown
$(document).off('change','.anr-user-div select').on('change','.anr-user-div select', function(e){
 
letconst selectID = '#' + e.target.id; // #anr-userX-select
letconst valSelected = $(selectID).children('option').filter(':selected').text(); // Selected type
letconst checkboxDivIDinputID = selectID.replace('select', 'checkbox-divinput'); // ID of div containing <#anr-userX-input type="checkbox"> tag
letconst checkboxIDvalInput = selectID$(inputID).replaceval().trim2('select', 'checkbox'); // IDThe ofinput checkboxvalue
letconst aDivIDcheckboxDivID = selectID.replace('select', 'acheckbox-div'); // ID of #anr-userX-checkbox-div containing <a> tag
letconst aIDcheckboxID = selectID.replace('select', 'acheckbox'); // ID of a#anr-userX-checkbox
letconst valInputidlinkDivID = trimA($(selectID.replace('select', 'inputidlink-div')).val()); // The input value#anr-userX-idlink-div
const idlinkID = selectID.replace('select', 'idlink'); // #anr-userX-idlink
switch(valSelected) {
case 'UNL':
case 'User2':
$(checkboxDivID).css('display', 'block');
toggleBlockStatusLink(inputID, false, false);
break;
case 'IP2':
toggleBlockStatusLink(inputID, false, false);
break;
case 'logid':
$(checkboxDivID).css('display', 'block');
$(checkboxID).prop('checked', true);
$(idlinkDivID).css('display', 'block');
$(idlinkID).attr('href', mw.util.getUrl('Special:redirect/logid/' + valInput)).text('特別:転送/logid/' + valInput);
toggleBlockStatusLink(inputID, true, true);
break;
case 'diff':
$(checkboxDivID).css('display', 'none');
$(idlinkDivID).css('display', 'block');
$(idlinkID).attr('href', mw.util.getUrl('Special:diff/' + valInput)).text('特別:差分/' + valInput);
toggleBlockStatusLink(inputID, true, false);
break;
default:
$(checkboxDivID).css('display', 'none');
$(idlinkDivID).css('display', 'none');
toggleBlockStatusLink(inputID, true, false);
}
 
if (valSelected === 'UNL' || valSelected === 'User2' ) { // if type=UNL or User2
 
$(checkboxDivID).css('display', 'block');
 
} else if (valSelected === 'logid' ) { // if type=logid
$(checkboxDivID).css('display', 'block');
$(checkboxID).prop('checked', true);
$(aDivID).css('display', 'block');
$(aID).attr('href', mw.util.getUrl('Special:redirect/logid/' + valInput)).text('特別:転送/logid/' + valInput);
 
} else if (valSelected === 'diff' ) { // if type=diff
 
$(checkboxDivID).css('display', 'none');
$(aDivID).css('display', 'block');
$(aID).attr('href', mw.util.getUrl('Special:diff/' + valInput)).text('特別:差分/' + valInput);
 
} else { // if type=none
$(checkboxDivID).css('display', 'none');
$(aDivID).css('display', 'none');
}
});
 
// When username is typed in, change dropdown options for UserAN types
$(document).off('input', '.anr-user-div :text').on('input', '.anr-user-div :text', function(e){
 
letconst inputID = '#' + e.target.id; // #anr-user1userX-input (<input>)
updateTypeDropdown(inputID);
let selectID = '#' + e.target.id.replace('input', 'select'); // #anr-user1-select (<select>)
typeDropdown(inputID, selectID);
resetDropdown(inputID, selectID);
 
});
// When 'hide username' is clicked, get logid, change dropdown options, show href and so on
$(document).off('change', '.anr-user-div :checkbox').on('change', '.anr-user-div :checkbox', function(e){
let objLogid = {};
$(document).on('change', '.anr-user-div :checkbox', function(e){
const checkboxID = '#' + e.target.id; // #anr-userX-checkbox
 
letconst checkboxIDselectID = checkboxID.replace('#checkbox', + e.target.id'select'); // #anr-user1userX-checkboxselect
letconst selectIDinputID = checkboxID.replace('checkbox', 'selectinput'); // #anr-user1userX-selectinput
letconst inputIDinputVal = checkboxID$(inputID).replaceval().trim2('checkbox', 'input'); // #anr-user1-input
letconst inputValidlinkID = trimA($(inputID)checkboxID.valreplace()'checkbox', 'idlink'); // #anr-userX-idlink
letconst aIDidlinkDivID = checkboxID.replace('checkbox', 'aidlink-div'); // #anr-userX-idlink-div
let aDivID = checkboxID.replace('checkbox', 'a-div');
 
if ($(checkboxID).is(':checked')) { // if the checkbox is checked
1,181 ⟶ 2,143行目:
$(selectID).children('.anr-opt-diff').prop('hidden', false);
$(selectID).children('.anr-opt-none').prop('hidden', false);
$(aDivIDidlinkDivID).css('display', 'block');
$(aIDidlinkID).attr('href', mw.util.getUrl('Special:redirect/logid/' + logid)).text('特別:転送/logid/' + logid);
} toggleBlockStatusLink(inputID, true, true);
}
let logid;
if (objLogidLogids[inputVal] !== undefined) {
$(inputID).val(objLogidLogids[inputVal]); // if the object knows the logid for the user, retrieve the data
updateDropdown(objLogidLogids[inputVal]);
} else {
// if the object doesn't know the logid for the user, ask the API
setTimeout(async function logidApi(){
// Get logid from the API
let logid = await getLogid(inputVal);
 
setTimeout(function(){ // CheckDeliberately setting thelag obtainedto logidprevent bugs
if (logid === undefined) { // If undefined is returned, reject the checking of the checkbox
// Check the obtained logid
alert('エラー\n\n取得可能なlogidが存在しません。Logidを手動で入力するか、type=diff または none を使用してください');
$if (checkboxIDlogid === undefined).prop('checked' { // If undefined is returned, false);reject the checking of the checkbox
alert('エラー\n\n取得可能なlogidが存在しません。Logidを手動で入力するか、type=diff または none を使用してください');
return;
} else { // If a valid logid is returned$(checkboxID).prop('checked', update type dropdownfalse);
updateDropdown(logid) return;
} else { // If a valid logid is returned
 
// Set the logid to the input
$(inputID).val(logid);
// Push username and logid into object if it doesn't have them
if (objLogidLogids[inputVal] === undefined) {
objLogid Logids[inputVal] = logid;
}
if (objLogidLogids[logid] === undefined) {
objLogid Logids[logid] = inputVal;
}
 
}, 0); // Update type dropdown
updateDropdown(logid);
}
 
}, 100);
}
logidApi();
}
1,225 ⟶ 2,193行目:
} else { // if the checkbox is unchecked
if (objLogidLogids[inputVal] !== undefined) {
$(inputID).val(objLogidLogids[inputVal]); // if the object knows the username for the logid, retrieve the data
$(selectID).children('.anr-opt-UNL').prop('hidden', false).prop('selected', true);
$(selectID).children('.anr-opt-User2').prop('hidden', false);
1,234 ⟶ 2,202行目:
$(selectID).children('.anr-opt-diff').prop('hidden', true);
$(selectID).children('.anr-opt-none').prop('hidden', false);
$(aDivIDidlinkDivID).css('display', 'none');
toggleBlockStatusLink(inputID, false, false);
} else {
1,261 ⟶ 2,230行目:
 
// When buttons are moused on and off
$(document).onoff({'mouseover mouseleave', '.anr-modal-dialog form button')
.on({
'mouseover': function(e) {
e.target.style.borderColor = '#999999';
1,269 ⟶ 2,239行目:
}
}, '.anr-modal-dialog form button');
 
// Copy VIP name
$(document).on('click', '.anr-viplist-btn', function() {
let vipSelectVal = $('#anr-viplist-select').find('option').filter(':selected').text().trim();
let vipLink = '[[WP:VIP#' + vipSelectVal + ']]';
if (vipSelectVal !== '[[Wikipedia:進行中の荒らし行為]]を検索') {
copyToClipboard(vipLink);
} else {
alert('ドロップダウンの値が選択されていません');
}
});
 
// Function to copy a string to the clipboard
function copyToClipboard(str) {
try { // This should handle browser incompatibility
let $temp = $('<input>');
$('body').append($temp); // Create a temporarily hidden text field
$temp.val(str).select(); // Copy the text string into the field and select the text
document.execCommand('copy'); // Copy it to the clipboard
$temp.remove(); // Remove the text field
}
catch (err) {
alert('ご利用のブラウザはこの機能に対応していません');
console.log(err);
}
}
 
// When the summary checkbox is (un)checked
$(document).off('change', '#anr-summary-checkbox').on('change', '#anr-summary-checkbox', function(){
 
let $textarea = $('#anr-summary-text');
1,309 ⟶ 2,253行目:
$textarea.css('display','none').val('');
}
});
 
// When 'check block status before edit' is (un)checked
});
$('#anr-blockstatus-checkbox').change(function(){
 
if ($(this).is(':checked')) { // Box is checked
checkBlockStatusBeforeEdit = true;
} else { // Box is unchecked
checkBlockStatusBeforeEdit = false;
}
 
});
 
// When 'check dpulicate reports before edit' is (un)checked
$('#anr-duplicatereport-checkbox').change(function(){
 
if ($(this).is(':checked')) { // Box is checked
checkDuplicateReportsBeforeEdit = true;
} else { // Box is unchecked
checkDuplicateReportsBeforeEdit = false;
}
 
});
 
}); // addPortletLink
 
// Function to get the last day of the month
1,318 ⟶ 2,284行目:
}
 
//**
* Function to get the current date and the section name to which to report
* @param {Boolean} last - if true, returns the name of the last section
function getSectionI(){
* @returns {String} - section name
*/
function getSectionI(last){
 
let d = new Date();
letif curSection;(last) {
let subtract = 5;
if (d.getDate() === 1 || d.getDate() === 2) {
subtract = 3;
} else if (d.getDate() === 31) {
subtract = 6;
}
d.setDate(d.getDate() - subtract);
}
let sectionName;
 
switch(true) {
case (1 <= d.getDate() && d.getDate() <= 5):
curSectionsectionName = `${d.getFullYear()}年${d.getMonth()+1}月1日 - 5日新規報告`;
break;
case (6 <= d.getDate() && d.getDate() <= 10):
curSectionsectionName = `${d.getFullYear()}年${d.getMonth()+1}月6日 - 10日新規報告`;
break;
case (11 <= d.getDate() && d.getDate() <= 15):
curSectionsectionName = `${d.getFullYear()}年${d.getMonth()+1}月11日 - 15日新規報告`;
break;
case (16 <= d.getDate() && d.getDate() <= 20):
curSectionsectionName = `${d.getFullYear()}年${d.getMonth()+1}月16日 - 20日新規報告`;
break;
case (21 <= d.getDate() && d.getDate() <= 25):
curSectionsectionName = `${d.getFullYear()}年${d.getMonth()+1}月21日 - 25日新規報告`;
break;
case (26 <= d.getDate() && d.getDate() <= lastDay(d.getFullYear(), d.getMonth())):
curSectionsectionName = `${d.getFullYear()}年${d.getMonth()+1}月26日 - ${lastDay(d.getFullYear(), d.getMonth())}日新規報告`;
break;
default:
undefined;
}
return curSectionsectionName;
}
 
1,355 ⟶ 2,336行目:
// Function to check if a user exists locally
async function userExists(username) {
return new Promise(function(resolve, reject) {
new mw.Api().get({
'action': 'query',
'list': 'users',
'ususers': username,
'formatversion': 2
}).done(function(res){
if (res.query.users[0].userid !== undefined) { // If user exists
1,372 ⟶ 2,353行目:
 
// Function to manipulate dropdown options for UserAN types (also maniputes show/hide of checkbox)
let typeDropdownTimeoutupdateTypeDropdownTimeout;
function typeDropdownupdateTypeDropdown(inputID, selectID, setNone) {
 
// Optional parameter: if false, the function doesn't select 'none' when random numbers or strings are typed into the input
if (setNone === undefined) {
setNone = true;
}
let tarVal = trimA($(inputID).val().trim2(); // The value typed into the input
let checkboxDivIDselectID = selectIDinputID.replace('selectinput', 'checkbox-divselect'); // #anr-userX-select
let checkboxIDcheckboxDivID = selectIDinputID.replace('selectinput', 'checkbox-div'); // #anr-userX-checkbox-div
let aDivIDcheckboxID = selectIDinputID.replace('selectinput', 'a-divcheckbox'); // #anr-userX-checkbox
let idlinkDivID = inputID.replace('input', 'idlink-div'); // #anr-userX-idlink-div
 
clearTimeout(typeDropdownTimeoutupdateTypeDropdownTimeout); // Run the async function only once when there's been no input change for 0.35 seconds
typeDropdownTimeoutupdateTypeDropdownTimeout = setTimeout(async function(){
 
if (tarVal === '') { // if the field is empty
 
$(selectID).prop('disabled', true).children('.anr-opt-none').prop('selected', true); // disableDisable dropdown and select 'none'
$(checkboxDivID).css('display', 'none'); // hideHide 'hide username' checkbox
$(checkboxID).prop('checked', false); // uncheckUncheck the checkbox
$(idlinkDivID).css('display', 'none'); // Hide logid/diff link
 
toggleBlockStatusLink(inputID, true, false);
} else { // if the field is filled
 
1,402 ⟶ 2,381行目:
$(selectID).children('.anr-opt-UNL').prop('hidden', true);
$(selectID).children('.anr-opt-User2').prop('hidden', true);
$(selectID).children('.anr-opt-IP2').prop({'hidden',: false).prop(, 'selected',: true});
$(selectID).children('.anr-opt-logid').prop('hidden', true);
$(selectID).children('.anr-opt-diff').prop('hidden', true);
1,408 ⟶ 2,387行目:
$(checkboxDivID).css('display', 'none'); // hide 'hide username' checkbox
$(checkboxID).prop('checked', false); // uncheck the checkbox
$(aDivIDidlinkDivID).css('display', 'none');
toggleBlockStatusLink(inputID, false, false);
 
} else if (await userExists(tarVal)) { // if user
 
$(selectID).children('.anr-opt-UNL').prop({'hidden',: false).prop(, 'selected',: true});
$(selectID).children('.anr-opt-User2').prop('hidden', false);
$(selectID).children('.anr-opt-IP2').prop('hidden', true);
1,420 ⟶ 2,400行目:
$(checkboxDivID).css('display', 'block'); // show 'hide username' checkbox
$(checkboxID).prop('checked', false); // uncheck the checkbox
$(aDivIDidlinkDivID).css('display', 'none');
toggleBlockStatusLink(inputID, false, false);
 
} else { // if something else (like random numbers or strings)
1,429 ⟶ 2,410行目:
$(selectID).children('.anr-opt-logid').prop('hidden', false);
$(selectID).children('.anr-opt-diff').prop('hidden', false);
if $(setNoneselectID) .children('.anr-opt-none').prop({'hidden': false, 'selected': true});
$(selectID).children('.anr-opt-none').prop('hidden', false).prop('selected', true);
} else {
$(selectID).children('.anr-opt-none').prop('hidden', false);
}
$(checkboxDivID).css('display', 'none'); // hide 'hide username' checkbox
$toggleBlockStatusLink(checkboxID).prop('checked'inputID, true, false); // uncheck the checkbox
$(aDivID).css('display', 'none');
 
}
1,445 ⟶ 2,421行目:
}
 
/**
// Function to reset dropdown value to 'none' if input is blanked, and hide unnecessary things
* Function to show/hide 'This user has blocks' links
function resetDropdown(inputID, selectID) {
* @param {String} inputID - the ID of the input
* @param {Boolean} forceHide - if true, hide the block status link without API requests
* @param {Boolean} convertLogid - if true, try to convert a logid to a username
*/
async function toggleBlockStatusLink(inputID, forceHide, convertLogid) {
 
let username = $(inputID).val().trim2(); // The value in the input
let $bsLinkDiv = $(inputID.replace('input', 'blockstatus-div')); // #anr-userX-blockstatus-div
let $bsLink = $(inputID.replace('input', 'blockstatus')); // #anr-userX-blockstatus
 
if (forceHide && convertLogid) {
if (Logids[username] !== undefined) { // If the object knows who that logid is for
username = Logids[username]; // Convert the logid to the username and continue to API requests
} else { // If the object doesn't know who that logid is for
$bsLinkDiv.css('display', 'none'); // Hide the link div and exit function
return;
}
 
} else if (forceHide) { // If forceHide is true, basically just hide the bsLink without API requests
 
$bsLinkDiv.css('display', 'none'); // Hide the link div
return;
 
let checkboxDivID = selectID.replace('select', 'checkbox-div'); // ID of div containing <input type="checkbox"> tag
let aDivID = selectID.replace('select', 'a-div'); // ID of div containing <a> tag
if (trimA($(inputID).val()) === '') {
$(selectID).children('.anr-opt-none').prop('selected', true);
$(checkboxDivID).css('display', 'none');
$(aDivID).css('display', 'none');
}
// Check the block status of the user, and if blocked, update the bsLink, or else, hide the link
let blocked = await getBlocked([username]);
if (blocked.length !== 0) { // If the user typed into the input is blocked
 
$bsLink.attr('href', mw.util.getUrl('特別:投稿記録/' + username)); // Update the link
$bsLinkDiv.css('display', 'block'); // Show the link div
 
} else {
 
$bsLinkDiv.css('display', 'none'); // Hide the link div
 
}
 
return;
}
 
// Function to get an array of blocked users & IPs from an array of random users & IPs
async function getBlocked(namesArr) {
 
let users = [];
let ips = [];
let blocked = [];
 
// Sort names to users and IPs
for (i = 0; i < namesArr.length; i++) {
if (mw.util.isIPAddress(namesArr[i], true)) { // Push IPs into the array
ips.push(namesArr[i]);
} else { // Push users into the array
users.push(namesArr[i]);
}
}
 
// Check who's blocked
if (users.length !== 0 && ips.length !== 0) { // If namesArr contains both users and IPs
blocked = blocked.concat(await getBlockedUsers(users), await getBlockedIps(ips));
} else if (users.length !== 0) { // If namesArr only contains users
blocked = blocked.concat(await getBlockedUsers(users));
} else if (ips.length !== 0) { // If namesArr only contains IPs
blocked = blocked.concat(await getBlockedIps(ips));
} else {
return blocked; // [], empty array
}
 
// Sort the blocked in the original order
for (i = namesArr.length -1; i >= 0; i--) {
if (!isInArray(namesArr[i], blocked)) { // If not blocked
namesArr.splice(i, 1); // Remove the name from the array
}
}
 
return namesArr;
 
}
 
// Function to get an array of blocked users from an array of random users
async function getBlockedUsers(usersArr) {
 
let blockedArr = [];
 
// API query
return new Promise(function(resolve, reject) {
new mw.Api().get({
'action': 'query',
'list': 'blocks',
'bklimit': usersArr.length,
'bkusers': usersArr.join('|'),
'bkprop': 'user',
'formatversion': 2
}).done(function(res){
 
let blockstatusApi = res.query.blocks;
 
if (blockstatusApi.length === 0) { // If none of the users is blocked
 
resolve(blockedArr); // Return []
} else { // If there are one or more blocked users
 
for (let i = 0; i < blockstatusApi.length; i++) {
blockedArr.push(blockstatusApi[i].user); // Push blocked users into the array
}
resolve(blockedArr); // Return e.g. [user1, user2...]
}
 
});
});
}
 
// Function to get an array of blocked IPs from an array of random IPs
async function getBlockedIps(ipsArr) {
let blockedArr = [];
let blocked;
for (let i = 0; i < ipsArr.length; i++) {
blocked = await ipIsBlocked(ipsArr[i]);
if (blocked) {
blockedArr.push(ipsArr[i]);
}
if (i === ipsArr.length -1) {
return blockedArr;
}
}
}
 
// Function to check if a given IP is blocked (true if the IP is blocked and false if not)
async function ipIsBlocked(ip) {
return new Promise(function(resolve, reject) {
new mw.Api().get({
'action': 'query',
'list': 'blocks',
'bklimit': 1,
'bkip': ip, // This parameter doesn't take multiple, pipe-separeted arguments, unlike the param 'bkusers'
'bkprop': 'user', // Get the blocked IP: Could be a range; Currently this value is not used in the function
'formatversion': 2
}).done(function(res){
if (res.query.blocks.length !== 0) { // If the IP is blocked
 
resolve(true);
} else { // If the IP is NOT blocked
 
resolve(false);
}
 
});
 
});
}
 
1,463 ⟶ 2,587行目:
return new Promise(function(resolve, reject) {
new mw.Api().get({
'action': 'query',
'list': 'logevents',
'leuser': username,
'ledir': 'newer',
'lelimit': 1,
'formatversion': 2
}).done(function(res){
if (res.query.logevents.length === 0) { // If empty array is returned (=if no logevent exists)
resolve(undefined);
} else {
resolve(res.query.logevents[0].logid);
1,483 ⟶ 2,607行目:
return new Promise(function(resolve, reject) {
new mw.Api().get({
'action': 'query',
'list': 'allrevisions',
'arvprop': 'ids|timestamp',
'arvlimit': 5,
'arvuser': mw.config.get('wgUserName'),
'arvstart': curtimestamp,
'arvdir': 'newer',
'formatversion': 2
}).done(function(res){
if (res && res.query && res.query.allrevisions) {
1,499 ⟶ 2,623行目:
}
if (i === revArr.length -1) {
resolve(undefined);
}
}
1,505 ⟶ 2,629行目:
});
});
}
 
// Function to trim U+200E space
function trimA(str) {
return str.replace(/\u200e/g, '').trim();
}
} // if (userIsInGruoup)
}
 
/**
// Function to check if an element is in an array
* Function to check if an element is in an array
* @param {String} el
* @param {Array} arr
* @returns {Boolean}
*/
function isInArray (el, arr) {
if (arr.indexOf(el) !== -1) {
1,521 ⟶ 2,645行目:
return false;
}
}
/**
* Function to check if elements of an array are all contained in another array
* @param {Array} arr1
* @param {Array} arr2
* @returns {Boolean}
*/
function arrayIsInArray(arr1, arr2) {
for (let i = 0; i < arr1.length; i++) {
if (!isInArray(arr1[i], arr2)) {
return false;
}
}
return true;
}
 
/**
// Function to check what user group the current user belongs to
* Function to check what user group the CURRENT USER belongs to (thus it doesn't take a username parameter)
* @param {String} group - a group name such as 'autoconfirmed' and 'sysop'
* @returns {Boolean}
*/
function userIsInGroup(group) {
if (isInArray(group, mw.config.get('wgUserGroups'))) {
1,529 ⟶ 2,672行目:
} else {
return false;
}
}
 
/**
* Function to check if a string contains a substring that is an element of an array
* @param {String} str
* @param {Array} arr
* @returns {Boolean}
*/
function stringContainsElementInArray(str, arr) {
for (let i = 0; i < arr.length; i++) {
if (str.indexOf(arr[i]) !== -1) {
return true;
}
}
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];
}
}