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

削除された内容 追加された内容
v1.8 logid関連のバグ修正・仕様変更
v2.0: WP:AN/Sへの報告に対応
2行目:
* AN Reporter (ANR)
* Author: Dragoniez
* Version: 12.80
*************************************/
//<nowiki>
 
// Run the script only after Select2, jQuery UI, and the DOM are loaded
$.when(
$.getScript('https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js'),
230 ⟶ 231行目:
` <option selected disabled hidden>選択してください</option>` +
` <option>${ANI}</option>` +
//` <option>${ANS}</option>` +
` <option>${AN3RR}</option>` +
` </select>` +
310 ⟶ 311行目:
var pageToEdit = $('#anr-target-options').children('option').filter(':selected').text();
var sectionToEdit = '選択してください';
ifvar (pageToEditANSOptSelected === ANI$('#anr-section-options-s') {.find('option').filter(':selected').text();
var reportToANS = false;
 
if (pageToEdit === ANI) { // If WP:AN/I is selected as the target page to edit
 
sectionToEdit = $('#anr-section-options-i').children('option').filter(':selected').text();
 
} else if (pageToEdit === ANS) {
} else if sectionToEdit(pageToEdit === $('#anr-section-options-s'ANS).children('option').filter(' { // If WP:AN/S is selected').text(); as the target page to edit
 
} else if (pageToEdit === AN3RR) {
reportToANS = true;
if (ANSOptSelected === 'Iccic系 (Iccic)') {
pageToEdit = Iccic;
sectionToEdit = '新規依頼';
} else if (ANSOptSelected === 'いせちか系 (ISECHIKA)') {
pageToEdit = ISECHIKA;
sectionToEdit = '新規依頼';
} else if (ANSOptSelected === '影武者系(KAGE)') {
pageToEdit = KAGE;
sectionToEdit = '新規依頼';
} else if (ANSOptSelected === '清島達郎系 (清島、KIYOSHIMA)') {
pageToEdit = KIYOSHIMA;
sectionToEdit = '新規依頼';
} else if (ANSOptSelected === '真珠王子系(SHINJU)') {
pageToEdit = SHINJU;
sectionToEdit = '新規依頼';
} else {
sectionToEdit = ANSOptSelected;
}
 
} else if (pageToEdit === AN3RR) { // If WP:AN/3RR is selected as the target page to edit
 
sectionToEdit = '3RR';
 
}
 
333 ⟶ 361行目:
var msgEditing =
' <div class="anr-editing">' +
' <p>セクション情報最新版を取得しています</p>' +
' </div>';
$dialog.find('form').css('display', 'none'); // Hide dialog content
340 ⟶ 368行目:
$dialog.append($(msgEditing));
// Get UserAN informationtemplate and the reason of the report
const UserAN = '{{UserAN|t=TYPE|USER}}';
var reason = trimA($('#anr-reason-text').val());
if (reason.substring(reason.length - 4) !== '~~~~') { // If reason doesn't contain signature, add one
reason = reason + '--~~~~';
}
 
// Get edit summary
const scriptAd = ' ([[User:Dragoniez/AN Reporter|AN Reporter]])';
const editSummarySection = '/*' + sectionToEdit + '*/';
348 ⟶ 381行目:
var editSummary =
trimA($('#anr-summary-text').val()) === '' ?
editSummarySection + genEditSummary() + scriptAd:
editSummarySection + 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
368 ⟶ 396行目:
 
// For debugging
//pageToEdit = 'User:Dragoniez/testtest2';
//editSummary = 'Test edit via mediawiki API';
 
// Get the wiki pagename for link
var wikiPagename = pageToEdit + '#' + sectionToEdit;
 
// Get sectionthe numberslatest revision
var sectionsAPI = {};
var msgDone = ''; // Message to show when edit attempt is done
new mw.Api().get({
action: 'parsequery',
pagetitles: pageToEdit,
prop: 'revisions',
curtimestamp: true,
formatversion: 2
}).done(function(responseres1){
 
if (res1 && res1.query && res1.query.pages) { // GetIf the sectionlatest numbersrevision fromis sectionsuccessfully titlesretrieved
for (let i = 0; iif < Object.keys(responseres1.parsequery.sections)pages[0].length;missing i++!== true) { // If the page exists
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
 
// ShowGet the details of the errorlatest revision
msgDone var baseTS = res1.query.pages[0].revisions[0].timestamp;
var curTS = res1.curtimestamp;
'<p style="color: MediumVioletRed">報告に失敗しました (指定されたセクションが見つかりませんでした)</p>' +
'<br>' +
'<p>ページ名:</p>' +
`<a href="${mw.util.getUrl(wikiPagename)}" target="_blank">${wikiPagename}</a>` +
'<br><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); // Update message
editDone($dialog); msgEditing =
' <p style="color: MediumSeaGreen">取得に成功しました</p>' +
' <p>セクション番号を取得しています</p>';
$('.anr-editing').append($(msgEditing));
 
} else { // IfGet section is found, proceednumbers
var sectionsAPI = {};
var msgDone = ''; // Message to show when edit attempt is done
new mw.Api().get({
action: 'parse',
page: pageToEdit,
formatversion: 2
}).done(function(res2){
 
if (res2 && res2.parse && res2.parse.sections) { // UpdateIf the section list is successfully messageretrieved
var msgEditing2 =
' <p style="color: MediumSeaGreen">取得に成功しました</p>' +
' <p>報告を試みています</p>';
$('.anr-editing').append($(msgEditing2));
 
// Get thesection numbers from latestsection revisiontitles
new mw.Api().get({ for (let i = 0; i < Object.keys(res2.parse.sections).length; i++) {
action: 'query', sectionsAPI[res2.parse.sections[i].line] = res2.parse.sections[i].index;
titles: pageToEdit, }
prop: 'revisions',
formatversion: 2 var sectionNum = sectionsAPI[sectionToEdit];
}).done(function if (ressectionNum === undefined) { // If section title in the dropdown is not found
 
if (res && res.query && res.query.pages) { // IfShow pagethe infodetails isof successfullythe retrievederror
if (res.query.pages[0].missing !== true) { // If the pagemsgDone = exists
'<p style="color: MediumVioletRed">取得に失敗しました</p>' +
'<p>指定されたセクションが見つかりませんでした</p>' +
'<br>' +
'<p>ページ名:</p>' +
`<a href="${mw.util.getUrl(wikiPagename)}" target="_blank">${wikiPagename}</a>` +
'<br><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));
 
// Get the details of$dialog.dialog('option', the'width', latest revisionwidth);
var latestRv = res.query.pages[0].revisions[0] editDone($dialog);
 
} else { // EditIf section title in the pagedropdown is found
 
$.ajax({
url:// mw.util.wikiScript('api'),Update message
data:msgEditing {=
' <p formatstyle="color: MediumSeaGreen">取得に成功しました</p>'json', +
' action: 'edit<p>最新版のテキストを取得しています</p>',;
title: pageToEdit,$('.anr-editing').append($(msgEditing));
 
// Get the text of the revision
new mw.Api().get({
action: 'parse',
page: pageToEdit,
section: sectionNum,
summaryprop: editSummarySection + editSummary'wikitext',
basetimestampformatversion: latestRv.timestamp,2
curtimestamp: true,}).done(function(res3){
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') {
 
if (res3 && $('res3.anr-editing'parse).append($(`<p style="color: MediumSeaGreen">報告が完了しました</p>`));{
$dialog.dialog('option', 'width', width);
editDone($dialog);
 
// If the edit failed// Update message
} else if(result && result.error) {msgEditing =
' <p style="color: MediumSeaGreen">取得に成功しました</p>' +
//' Show the details of the error<p>報告を試みています</p>';
msgDone = $('.anr-editing').append($(msgEditing));
'<p style="color: MediumVioletRed">報告に失敗しました</p>' +
'<br>' +
'<p>ページ名:</p>' +
`<a href="${mw.util.getUrl(wikiPagename)}" target="_blank">${wikiPagename}</a>` +
'<br><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',Get width);the whole text to append
editDone($dialog)var wikitextObtained = res3.parse.wikitext;
var wholeTextToSubmit;
const delimiter = '<!-- ◆';
const miscHeader = `{{bgcolor|#eee|{{Visible anchor|他${today()}}}|div}}`;
 
if (reportToANS) { // If unknownthe errortarget occursis WP:AN/S
} else {
 
// ShowAdd div if the target section is 'その他' but lacks div for the current messagedate
msgDone if (sectionToEdit === 'その他' && wikitextObtained.indexOf(miscHeader) === -1) {
'<p style textToSubmit ="color: MediumVioletRed">不明なエラーが発生しました</p>'; ' + miscHeader + '\n\n' + textToSubmit
'<br>' + }
'<p>ページ名:</p>' +
`<a href="${mw.util.getUrl(wikiPagename)}" target="_blank">${wikiPagename}</a>` +
'<br><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); // Insert text into the right place
editDone var wikitextSplit = wikitextObtained.split($dialogdelimiter);
if (wikitextSplit.length === 3) {
}
 
} wholeTextToSubmit =
} wikitextSplit[0] + delimiter + trimA(wikitextSplit[1]); + '\n\n' +
textToSubmit + '\n\n' + delimiter + wikitextSplit[2];
 
} else { // If thesection structure pagehas doesn'tbeen existchanged
 
msgDone = // Show error and quit the procedure
'<p style="color: MediumVioletRed">エラー: 編集先のページが存在しません</p>' + msgDone =
'<brp style="color: MediumVioletRed">報告に失敗しました</p>' +
'<p>ページ名:</p>セクション構造が改変されているため、' +
`<a href="${mw.util.getUrl(wikiPagename'User talk:Dragoniez/AN Reporter')}" target="_blank">${wikiPagename}開発者</a>` +
'に連絡をお願いします<br><br/p>' +
'<p>手動編集用:</pbr>' +
`<textarea disabled rows="5" style="width: 100%" '<p>${textToSubmit}ページ名:</textareap>`' +
' `<bra href="${mw.util.getUrl(wikiPagename)}" target="_blank">'${wikiPagename}</a>` +
'<pbr>要約:</pbr>' +
`<textarea disabled rows="2" style="width: 100%">${editSummary.replace(scriptAd, '')}<p>手動編集用:</textareap>`;' +
`<textarea disabled rows="5" style="width: 100%">$('.anr-editing').append($(msgDone));{textToSubmit}</textarea>` +
'<br>' +
$dialog.dialog('option', 'width<p>要約:</p>', width);+
editDone( `<textarea disabled rows="2" style="width: 100%">$dialog{editSummary.replace(scriptAd, '')}</textarea>`;
$('.anr-editing').append($(msgDone));
 
$dialog.dialog('option', 'width', width);
editDone($dialog);
return;
 
}
 
} else { // If the target is WP:AN/I or WP:AN/3RR
 
wholeTextToSubmit = trimA(wikitextObtained) + '\n\n' + textToSubmit;
 
}
// Edit the page
$.ajax({
url: mw.util.wikiScript('api'),
data: {
format: 'json',
action: 'edit',
title: pageToEdit,
section: sectionNum,
summary: editSummary,
basetimestamp: baseTS,
starttimestamp: curTS,
text: wholeTextToSubmit,
token: mw.user.tokens.get('csrfToken')
},
dataType: 'json',
type: 'POST',
success: function(res4) {
// If the edit was successful
if (res4 && res4.edit && res4.edit.result == 'Success') {
 
$('.anr-editing').append($(`<p style="color: MediumSeaGreen">報告が完了しました</p>`));
$dialog.dialog('option', 'width', width);
editDone($dialog);
 
// If the edit failed
} else if (res4 && res4.error) {
// Show the details of the error
msgDone =
'<p style="color: MediumVioletRed">報告に失敗しました</p>' +
'<br>' +
'<p>ページ名:</p>' +
`<a href="${mw.util.getUrl(wikiPagename)}" target="_blank">${wikiPagename}</a>` +
'<br><br>' +
'<p>詳細:</p>' +
`<p>${res4.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>' +
`<a href="${mw.util.getUrl(wikiPagename)}" target="_blank">${wikiPagename}</a>` +
'<br><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 wikitext retrieval fails
queryFailed();
}
 
});
}
 
} else { // If the section list retrieval fails
queryFailed();
}
 
} else { // If page info retrieval fails);
msgDone =
'<p style="color: MediumVioletRed">ページ情報の取得に失敗しました</p>' +
'<br>' +
'<p>ページ名:</p>' +
`<a href="${mw.util.getUrl(wikiPagename)}" target="_blank">${wikiPagename}</a>` +
'<br><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>' +
`<a href="${mw.util.getUrl(wikiPagename)}" target="_blank">${wikiPagename}</a>` +
'<br><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 revision retrieval fails
queryFailed();
}
 
});
 
}
// Function to show message when edit attempt is done
function queryFailed() {
msgDone =
'<p style="color: MediumVioletRed">取得に失敗しました</p>' +
'<br>' +
'<p>ページ名:</p>' +
`<a href="${mw.util.getUrl(wikiPagename)}" target="_blank">${wikiPagename}</a>` +
'<br><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);
}
}
 
}]
 
684 ⟶ 808行目:
}
var logid;
console.log('objLogid[inputVal]:' + objLogid[inputVal]);
if (objLogid[inputVal] !== undefined) {
724 ⟶ 847行目:
} else { // if the checkbox is unchecked
console.log('objLogid[inputVal]:' + objLogid[inputVal]);
if (objLogid[inputVal] !== undefined) {
904 ⟶ 1,025行目:
}
return curSection;
}
 
// Function to get today's date
function today() {
var d = new Date();
return d.getMonth()+1 + '月' + d.getDate() + '日';
}