User:YFdyh000/SATG.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
//Written by Abelmoschus Esculentus
//Date: 12 January 2019
//Edited on [[:zh:User:YFdyh000/SATG.js]]
//<nowiki>
function screen2(number) {
var source = ["placeholder"], ind = ["placeholder"], ind_just = ["placeholder"], rel = ["placeholder"], rel_just = ["placeholder"], sig = ["placeholder"], sig_just = ["placeholder"];
$('.SATG-source').each(function () {
source.push(this.value);
});
$('.SATG-selecti').each(function () {
ind.push(this.value);
});
$('.SATG-justi').each(function () {
ind_just.push(this.value);
});
$('.SATG-selectr').each(function () {
rel.push(this.value);
});
$('.SATG-justr').each(function () {
rel_just.push(this.value);
});
$('.SATG-selects').each(function () {
sig.push(this.value);
});
$('.SATG-justs').each(function () {
sig_just.push(this.value);
});
var output = "{{ source assess table\n";
output += "| user=" + mw.config.get("wgUserName") + "\n";
output += "<!-- | startopen=Yes -->";
output += "\n|";
for (var i = 1; i <= number; i++) {
output += "{{ source assess\n";
output += "| source = " + source[i] + "\n";
output += "| ind = " + ind[i] + "\n";
output += "| ind_just = " + ind_just[i] + "\n";
output += "| rel = " + rel[i] + "\n";
output += "| rel_just = " + rel_just[i] + "\n";
output += "| sig = " + sig[i] + "\n";
output += "| sig_just = " + sig_just[i] + "\n";
output += "}}\n";
}
output += "}}";
$("#SATG-interface-content").css({
"min-height": "7em",
"overflow-y": "hidden"
});
$("#SATG-interface-content").empty();
$("#SATG-interface-content").text('Generating...');
$('.SATG-tip').remove();
$("#SATG-interface-content").empty();
$("#SATG-interface-content").append(
$('<button>').attr('id','SATG-copy').text('Copy'),
$('<label>').attr('id','SATG-copied').text(''),
$('<textarea>').css({'resize':'none'}).attr({'id':'SATG-output','readonly':'true','rows':'20','cols':'35'}).text(output)
);
$('#SATG-copy').click(function() {
var copy = document.getElementById("SATG-output");
copy.select();
document.execCommand("copy");
$('#SATG-copied').text(' Copied to your clipboard!');
});
}
function screen1(number) {
if ($("#SATG-interface-content").text() == "Loading form...") {
$("#SATG-interface-content").empty();
}
$("#SATG-interface-footer").append(
$('<button>').attr('id', 'SATG-back').css('margin-left','1em').text('Back')
);
$("#SATG-interface-footer").prepend(
$('<small>').attr('class','SATG-tip').text('**Only available for options "Yes", "No", "Partially" and "Unknown"'),
$('<br>').attr('class','SATG-tip')
);
$('#SATG-back').click(function () {
if (confirm('Are you sure to return to the main screen? This will clear existing data.')){
$('#SATG-back').remove();
screen0();
window.scrollTo(0, 0);
}
});
/*var arr = [
{val : 1, text: 'Yes'},
{val : 2, text: 'No'},
{val : 3, text: 'Partially'},
{val : 4, text: 'Unknown'},
{val : 5, text: 'None'}
];*/
for (var i = 1; i <= number; i++) {
if (i != 1) {
$("#SATG-interface-content").append('<hr>');
}
$("#SATG-interface-content").append(
$('<div>').css('margin-bottom','0.5em').append(
$('<label>').text('Source '+i+': '),
$('<input>').attr({'type':'text','class':'SATG-source'})
),
$('<div>').css('margin-bottom','0.5em').append(
$('<label>').text('Independent? '),
$('<select>').attr('class','SATG-selecti')
.append($("<option>").attr('value','y').text('Yes'))
.append($("<option>").attr('value','n').text('No'))
.append($("<option>").attr('value','-').text('Partially'))
.append($("<option>").attr('value','?').text('Unknown'))
.append($("<option>").attr({'value':'','selected':'true'}).text('None')),
$('<label>').text(' **Justification: '),
$('<input>').attr({'type':'text','class':'SATG-justi'})
),
$('<div>').css('margin-bottom','0.5em').append(
$('<label>').text('Reliable? '),
$('<select>').attr('class','SATG-selectr')
.append($("<option>").attr('value','y').text('Yes'))
.append($("<option>").attr('value','n').text('No'))
.append($("<option>").attr('value','-').text('Partially'))
.append($("<option>").attr('value','?').text('Unknown'))
.append($("<option>").attr({'value':'','selected':'true'}).text('None')),
$('<label>').text(' **Justification: '),
$('<input>').attr({'type':'text','class':'SATG-justr'})
),
$('<div>').css('margin-bottom','0.5em').append(
$('<label>').attr('id','SATG-labels-'+i).text('Significant coverage? '),
$('<select>').attr('class','SATG-selects')
.append($("<option>").attr('value','y').text('Yes'))
.append($("<option>").attr('value','n').text('No'))
.append($("<option>").attr('value','-').text('Partially'))
.append($("<option>").attr('value','?').text('Unknown'))
.append($("<option>").attr({'value':'','selected':'true'}).text('None')),
$('<label>').text(' **Justification: '),
$('<input>').attr({'type':'text','class':'SATG-justs'})
)
);
}
$("#SATG-interface-content").append(
$('<button>').attr('id','SATG-generate').text('Generate!')
);
$('#SATG-interface-content>div').css('display','flex');
$('#SATG-interface-content>div>input').css('flex','2');
$('#SATG-interface-content>div>label').css({"margin-left": "3px","margin-right": "5px"});
$('#SATG-generate').click(function() {
screen2(number);
});
}
function satg_init() {
mw.util.addPortletLink('p-tb', 'javascript:void(0)', 'SA Table Generator', 'aca-satg', null, null);
$('#aca-satg').on('click', function() {
$('body').prepend('<div id="SATG-modal">'+
'<div id="SATG-interface">'+
'<h4 id="SATG-interface-header"></h4>'+
'<hr>'+
'<div id="SATG-interface-content"></div>'+
'<hr>'+
'<div id="SATG-interface-footer"></div>'+
'</div>'+
'</div>');
$("#SATG-modal").css({
//"position": "fixed",
"z-index": "1",
"left": "0",
"top": "0",
"width": "100%",
"height": "100%",
"overflow": "hidden",
"background-color": "rgba(0,0,0,0.4)"
});
$("#SATG-interface").css({
"background-color": "#e8f0ff",
"margin": "15% auto",
"padding": "20px 20px",
"border": "1px solid #888",
"width": "80%",
"max-width": "60em",
"font-size": "90%"
});
$("#SATG-interface-content").css({
"min-height": "7em",
//"overflow-y": "scroll"
});
$("#SATG-interface-footor").css("min-height", "3em");
screen0();
});
}
var screen0 = function() {
$("#SATG-interface-header, #SATG-interface-content, #SATG-interface-footer").empty();
$("#SATG-interface-header").text("Source Assess Table Generator");
$("#SATG-interface-content").append(
$('<div>').css('margin-bottom','0.5em').append(
$('<label>').attr({'for':'SATG-userinput-label', 'id':'SATG-userinput-label'}).text('How many sources do you want to assess? '),
$('<input>').attr({'type':'number', 'name':'SATG-userinput','id':'SATG-userinput','min':'1','value':'1'})
),
$('<div>').css('margin-bottom','0.5em').append(
$('<button>').attr({'name':'SATG-userinput-button', 'id':'SATG-userinput-button'}).text('Load')
)
);
var refnum = $('.references li').length;
if (refnum > 0) {
$('#SATG-userinput').val(refnum);
}
$("#SATG-interface-footer").append(
$('<button>').attr('id', 'SATG-cancel').text('Close')
);
$('#SATG-cancel').click(function() {
if (confirm('Are you sure you want to close this dialog?')){
$('#SATG-modal').remove();
}
});
$('#SATG-userinput-button').click(function() {
var temp = $('#SATG-userinput').val();
if (temp < 1) {
alert('Invalid value');
}
else {
$('#SATG-interface-content').empty();
$('#SATG-interface-content').text('Loading form...');
screen1(temp);
}
});
};
mw.loader.using(['mediawiki.util'], function() {
satg_init();
});
//</nowiki>