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

削除された内容 追加された内容
m Dragoniez がページ「利用者:Dragoniez/Vandal Reporter.js」を「利用者:Dragoniez/AN Reporter.js」に移動しました
m v1.4 - 名称変更に伴う軽微な修正
1行目:
/*************************************
* VandalAN Reporter (VRANR)
* Author: Dragoniez
* Version: 1.3 beta4
**************************************/
//<nowiki>
 
15行目:
 
// Add VR tab
$(mw.util.addPortletLink('p-cactions', '#', '報告', 'ca-vranr', '管理者伝言板に利用者を報告', null, '#ca-move'))
.click(function(e){
 
37行目:
// Sections on WP:AN/I
var sectionsI =
` <label for="vranr-section-options-i" style="${labelCSS}">節</label>` +
` <select id="vranr-section-options-i">` +
` <option selected disabled hidden>選択してください</option>` +
` <option>${getSectionI()}</option>` +
49行目:
// Sections on WP:AN/S
var sectionsS =
` <label for="vranr-section-option-s" style="${labelCSS}">名称</label>` +
` <input id ="vranr-section-input" list="vranr-section-options-s" style="width: calc(100% - 10ch);">` +
` <datalist id="vranr-section-options-s">` +
` <optgroup label="系列が立てられていないもの">` +
` <option>著作権侵害・犯罪予告</option>` +
177行目:
// Username input
var userHtml =
// <div class="vranr-user-div">
` <div id="vranr-user1-input-div">` +
` <label id="vranr-user1-label" for="vranr-user1-input" style="${labelCSS}">利用者</label>` +
` <input id="vranr-user1-input" style="width: 31ch;">` +
` <select disabled id="vranr-user1-select">` +
` <option class="vranr-opt-UNL">UNL</option>` +
` <option class="vranr-opt-User2">User2</option>` +
` <option class="vranr-opt-IP2">IP2</option>` +
` <option class="vranr-opt-logid">logid</option>` +
` <option class="vranr-opt-diff">diff</option>` +
` <option selected class="vranr-opt-none">none</option>` +
` </select>` +
` </div>` +
` <div id="vranr-user1-checkbox-div" style="display: none;">` +
` <label class="vranr-emptylabel" style="${labelCSS}"></label>` +
` <input type="checkbox" id="vranr-user1-checkbox">` +
` <label id="vranr-user1-checkbox-hide" for="vranr-user1-checkbox">利用者名を隠す</label>` +
` </div>` +
` <div id="vranr-user1-a-div" style="display: none;">` +
` <label id="vranr-user1-label" for="vranr-user1-a" style="${labelCSS}"></label>` +
` <a id="vranr-user1-a" href="" target="_blank"></a>` +
` </div>`;
// </div>
203行目:
// The whole html contour
var modalHtml =
// <div class="vranr-modal-dialog" title="VandalAN Reporter">
` <div class="vranr-modal-header">` +
` <h2>利用者を報告</h2>` +
` </div>` +
` <div class="vranr-modal-body" >` +
` <form>` +
` <div class="vranr-target-div" style="${marginCSS}">` +
` <label for="vranr-target-options" style="${labelCSS}">報告先</label>` +
` <select id="vranr-target-options">` +
` <option selected disabled hidden>選択してください</option>` +
` <option>${ANI}</option>` +
217行目:
` <option>${AN3RR}</option>` +
` </select>` +
` <div class="vranr-target-a-div" style="display: none;">` +
` <label class="vranr-emptylabel" for="vranr-target-a" style="${labelCSS}"></label>` +
` <a id="vranr-target-a" href="" target="_blank">報告先を確認</a>` +
` </div>` +
` </div>` +
` <div class="vranr-section-div" style="${marginCSS} display: none;">` +
// sectionsX +
` </div>` +
` <div class="vranr-user-div" style="${marginCSS}">` +
userHtml +
` <div class="vranr-btn-div">` +
` <button type="button" class="vranr-addBtn">追加</button>` +
` </div>` +
` </div>` +
` <div class="vranr-reason-div" style="${marginCSS}">` +
` <label for="vranr-reason-text" style="${labelCSS}">理由</label>` +
` <textarea id="vranr-reason-text" rows="8" style="width: 100%"></textarea>` +
` </div>` +
` <div class="vranr-summary-div" style="${marginCSS}">` +
` <input id="vranr-summary-checkbox" type="checkbox">` +
` <label for="vranr-summary-checkbox">要約を指定</label>` +
` <textarea id="vranr-summary-text" rows="3" style="width: 100%; display: none;"></textarea>` +
` </div>` +
` </form>` +
245行目:
 
// Add the frame div to the page
$('body').append($('<div class="vranr-modal-dialog" title="VandalAN Reporter" style="max-height: 80vh;"/>'));
 
// Create html elements inside the div
$('.vranr-modal-dialog').html(modalHtml);
 
// Show dialog
$('.vranr-modal-dialog').dialog({
'minHeight': 50,
'minWidth': 300,
264行目:
username = '';
}
$('#vranr-user1-input').val(username);
typeDropdown('#vranr-user1-input', '#vranr-user1-select');
if (username === mw.config.get('wgRelevantUserName') && !mw.util.isIPAddress(username, true)) {
$('#vranr-user1-checkbox-div').css('display', 'block'); // Show 'hide username' if the name obtained is a user's
}
 
281行目:
var types = [];
for (let i = 1; i < Infinity; i++) { // Loop through all inputs
if ($(`#vranr-user${i}-input`).length === 0) { // if selector is not found
break; // exit for
} else { // if selector is found
if (trimA($(`#vranr-user${i}-input`).val()) !== '') { // if input is not empty
users.push(trimA($(`#vranr-user${i}-input`).val())); // Push the username into the array
types.push($(`#vranr-user${i}-select`).children('option').filter(':selected').text()); // Push the UserAN type into the array
}
}
292行目:
 
// Get the name of the section to edit
var pageToEdit = $('#vranr-target-options').children('option').filter(':selected').text();
var sectionToEdit;
if (pageToEdit === ANI) {
sectionToEdit = $('#vranr-section-options-i').children('option').filter(':selected').text();
} else if (pageToEdit === ANS) {
sectionToEdit = $('#vranr-section-input').val();
} else if (pageToEdit === AN3RR) {
sectionToEdit = '3RR';
305行目:
pageToEdit === '選択してください' || // The page dropdown's remained 選択してください
sectionToEdit === undefined || // The section dropdown's remained 選択してください
trimA($('#vranr-reason-text').val()) === '' || // No reason is given
users.length === 0 // No username is given
) {
318行目:
$dialog.dialog('option', 'width', width);
$dialog.dialog({'buttons': [] }); // Hide the button
$dialog.append($('<p class="vranr-editing">報告中...</p>'));
// Get UserAN information
const UserAN = '{{UserAN|t=TYPE|USER}}';
var reason = trimA($('#vranr-reason-text').val());
const scriptAd = ' ([[User:Dragoniez/VandalAN Reporter|VandalAN Reporter]])';
const editSummarySection = '/*' + sectionToEdit + '*/';
 
var editSummary =
trimA($('#vranr-summary-text').val()) === '' ?
genEditSummary() + scriptAd:
trimA($('#vranr-summary-text').val()) + scriptAd;
 
// If reason doesn't contain signature, add one
366行目:
 
// Show the details of the error
$('.vranr-editing').remove();
msgDone =
426行目:
if(result && result.edit && result.edit.result == 'Success') {
 
$('.vranr-editing').remove();
$dialog.append($(`<p>報告が完了しました</p>`));
$dialog.dialog('option', 'width', width);
435行目:
// Show the details of the error
$('.vranr-editing').remove();
msgDone =
460行目:
 
// Show message
$('.vranr-editing').remove();
msgDone =
482行目:
} else { // If the page doesn't exist
 
$('.vranr-editing').remove();
msgDone =
504行目:
} else { // If page info retrieval fails
$('.vranr-editing').remove();
msgDone =
531行目:
 
// Reset dialog when closed
$('.vranr-modal-dialog').on('dialogclose', function() {
$(this).remove();
});
 
// Dynamically change the content of the section dropdown depending the value selected in '報告先'
$(document).on('change', '#vranr-target-options', function(){
var selectedTar = $(this).children('option').filter(':selected').text();
switch(selectedTar) {
case ANI:
$('.vranr-section-div').empty();
$('.vranr-section-div').append(sectionsI);
$('.vranr-section-div').css('display', 'block');
$('.vranr-target-a-div').css('display', 'block');
$('#vranr-target-a').attr('href', url + ANI);
break;
case ANS:
$('.vranr-section-div').empty();
$('.vranr-section-div').append(sectionsS);
$('.vranr-section-div').css('display', 'block');
$('.vranr-target-a-div').css('display', 'block');
$('#vranr-target-a').attr('href', url + ANS);
break;
case AN3RR:
$('.vranr-section-div').empty();
$('.vranr-section-div').css('display', 'none');
$('.vranr-target-a-div').css('display', 'block');
$('#vranr-target-a').attr('href', url + AN3RR);
break;
}
563行目:
 
// Dynamically change the display of the form depending on the UserAN type
$(document).on('change','.vranr-user-div select', function(e){
 
var selectID = '#' + e.target.id;
599行目:
 
// When username is typed in, change dropdown options for UserAN types
$(document).on('input', '.vranr-user-div :text', function(e){
 
var inputID = '#' + e.target.id; // #vranr-user1-input (<input>)
var selectID = '#' + e.target.id.replace('input', 'select'); // #vranr-user1-select (<select>)
typeDropdown(inputID, selectID);
resetDropdown(inputID, selectID);
610行目:
// When 'hide username' is clicked, get logid, change dropdown options, show href and so on
var objLogid = {};
$(document).on('change', '.vranr-user-div :checkbox', function(e){
 
var checkboxID = '#' + e.target.id; // #vranr-user1-checkbox
var selectID = checkboxID.replace('checkbox', 'select'); // #vranr-user1-select
var inputID = checkboxID.replace('checkbox', 'input'); // #vranr-user1-input
var inputVal = trimA($(inputID).val());
var aID = checkboxID.replace('checkbox', 'a');
623行目:
// Function to update type dropdown
var updateDropdown = function(logid) {
$(selectID).children('.vranr-opt-UNL').prop('hidden', true);
$(selectID).children('.vranr-opt-User2').prop('hidden', true);
$(selectID).children('.vranr-opt-IP2').prop('hidden', true);
$(selectID).children('.vranr-opt-logid').prop('hidden', false).prop('selected', true);
$(selectID).children('.vranr-opt-diff').prop('hidden', false);
$(selectID).children('.vranr-opt-none').prop('hidden', false);
$(aDivID).css('display', 'block');
$(aID).attr('href', url + 'Special:redirect/logid/' + logid).text('特別:転送/logid/' + logid);
679行目:
$(inputID).val(objLogid[inputVal]); // if the object knows the username for the logid, retrieve the data
$(selectID).children('.vranr-opt-UNL').prop('hidden', false).prop('selected', true);
$(selectID).children('.vranr-opt-User2').prop('hidden', false);
$(selectID).children('.vranr-opt-IP2').prop('hidden', true);
$(selectID).children('.vranr-opt-logid').prop('hidden', true);
$(selectID).children('.vranr-opt-diff').prop('hidden', true);
$(selectID).children('.vranr-opt-none').prop('hidden', false);
$(aDivID).css('display', 'none');
701行目:
// When the 'add' button is hit, add another input layer
var userCnt = 1;
$('.vranr-addBtn').click(function(){
 
userCnt++;
userHtml = userHtml.replaceAll(`${userCnt-1}-`, `${userCnt}-`); // 1 → 2, 2 → 3 and so forth
$('.vranr-btn-div').before(userHtml);
$(`#vranr-user${userCnt}-input-div`).css('margin-top', '0.2em');
 
});
 
// When the summary checkbox is (un)checked
$('#vranr-summary-checkbox').change(function(){
 
var $textarea = $('#vranr-summary-text');
 
if ($(this).is(':checked')) { // Box is checked
766行目:
while (inputRemains) {
 
if ($(`#vranr-user${i}-input`).length === 0) { // if selector doesn't exist
inputRemains = false; // No inputs remain to be checked
} else {
 
type = $(`#vranr-user${i}-select`).children('option').filter(':selected').text(); // UserAN type specified in the dropdown
reportee = trimA($(`#vranr-user${i}-input`).val()); // input value
 
if (reportee !== '') { // Skip if the input value is a null string
902行目:
if (mw.util.isIPAddress(tarVal, true)) { // if IP
 
$(selectID).children('.vranr-opt-UNL').prop('hidden', true);
$(selectID).children('.vranr-opt-User2').prop('hidden', true);
$(selectID).children('.vranr-opt-IP2').prop('hidden', false).prop('selected', true);
$(selectID).children('.vranr-opt-logid').prop('hidden', true);
$(selectID).children('.vranr-opt-diff').prop('hidden', true);
$(selectID).children('.vranr-opt-none').prop('hidden', false);
$(checkboxDivID).css('display', 'none'); // hide 'hide username' checkbox
$(checkboxID).prop('checked', false); // uncheck the checkbox
913行目:
} else if (await userExists(tarVal)) { // if user
 
$(selectID).children('.vranr-opt-UNL').prop('hidden', false).prop('selected', true);
$(selectID).children('.vranr-opt-User2').prop('hidden', false);
$(selectID).children('.vranr-opt-IP2').prop('hidden', true);
$(selectID).children('.vranr-opt-logid').prop('hidden', true);
$(selectID).children('.vranr-opt-diff').prop('hidden', true);
$(selectID).children('.vranr-opt-none').prop('hidden', false);
$(checkboxDivID).css('display', 'block'); // show 'hide username' checkbox
$(checkboxID).prop('checked', false); // uncheck the checkbox
924行目:
} else { // if something else (like random numbers or strings)
 
$(selectID).children('.vranr-opt-UNL').prop('hidden', true);
$(selectID).children('.vranr-opt-User2').prop('hidden', true);
$(selectID).children('.vranr-opt-IP2').prop('hidden', true);
$(selectID).children('.vranr-opt-logid').prop('hidden', false);
$(selectID).children('.vranr-opt-diff').prop('hidden', false);
if (setNone) {
$(selectID).children('.vranr-opt-none').prop('hidden', false).prop('selected', true);
} else {
$(selectID).children('.vranr-opt-none').prop('hidden', false);
}
$(checkboxDivID).css('display', 'none'); // hide 'hide username' checkbox
951行目:
if (trimA($(inputID).val()) === '') {
$(selectID).children('.vranr-opt-none').prop('selected', true);
$(checkboxDivID).css('display', 'none');
$(aDivID).css('display', 'none');