User:Ghren/satg.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
//Written by Abelmoschus Esculentus
//Date: 12 January 2019
//Copied from [[User:Abelmoschus Esculentus/SATG.js]
//<nowiki>
function screen2(number) {
var source = ["placeholder"], ind = ["placeholder"], ind_just = ["placeholder"], rel = ["placeholder"], rel_just = ["placeholder"], sig = ["placeholder"], sig_just = ["placeholder"], pri = ["placeholder"], pri_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);
});
$('.SATG-selectp').each(function () {
pri.push(this.value);
});
$('.SATG-justp').each(function () {
pri_just.push(this.value);
});
var output = "{{ source assess table2 |\n";
for (var i = 1; i <= number; i++) {
output += "{{ source assess2\n";
output += "| number = " + [i] + "\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 += "| pri = " + pri[i] + "\n";
output += "| pri_just = " + pri_just[i] + "\n";
output += "}}\n";
}
output += "}}";
$("#SATG-interface-content").css({
"min-height": "7em",
"width" : "875px",
"height" : "400px",
"overflow-y": "hidden"
});
$("#SATG-interface-content").empty();
$("#SATG-interface-content").text('生成中');
$('.SATG-tip').remove();
$("#SATG-interface-content").empty();
$("#SATG-interface-content").append(
$('<button>').attr('id','SATG-copy').text('複制'),
$('<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(' 已復制!');
});
}
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('返回')
);
$("#SATG-interface-footer").prepend(
$('<small>').attr('class','SATG-tip').text('**只能選擇「是」、「不是」、「部份」、「未知」。'),
$('<br>').attr('class','SATG-tip')
);
$('#SATG-back').click(function () {
$('#SATG-back').remove();
$("#SATG-interface-content").css({
"min-height": "7em",
"width" : "875px",
"height" : "400px",
"overflow-y": "scroll"
});
screen0();
});
/*var arr = [
{val : 1, text: '是'},
{val : 2, text: '不是'},
{val : 3, text: '部份'},
{val : 4, text: '未知'},
{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('來源'+i+': '),
$('<input>').attr({'type':'text','class':'SATG-source'})
),
$('<div>').css('margin-bottom','0.5em').append(
$('<label>').text('獨立? '),
$('<select>').attr('class','SATG-selecti')
.append($("<option>").attr('value','y').text('是'))
.append($("<option>").attr('value','n').text('不是'))
.append($("<option>").attr('value','-').text('部份'))
.append($("<option>").attr('value','?').text('未知'))
.append($("<option>").attr({'value':'','selected':'true'}).text('None')),
$('<label>').text(' **描述: '),
$('<input>').attr({'type':'text','class':'SATG-justi'})
),
$('<div>').css('margin-bottom','0.5em').append(
$('<label>').text('可靠? '),
$('<select>').attr('class','SATG-selectr')
.append($("<option>").attr('value','y').text('是'))
.append($("<option>").attr('value','n').text('不是'))
.append($("<option>").attr('value','-').text('部份'))
.append($("<option>").attr('value','?').text('未知'))
.append($("<option>").attr({'value':'','selected':'true'}).text('None')),
$('<label>').text(' **描述: '),
$('<input>').attr({'type':'text','class':'SATG-justr'})
),
$('<div>').css('margin-bottom','0.5em').append(
$('<label>').text('第二手? '),
$('<select>').attr('class','SATG-selectp')
.append($("<option>").attr('value','y').text('是'))
.append($("<option>").attr('value','n').text('不是'))
.append($("<option>").attr('value','-').text('部份'))
.append($("<option>").attr('value','?').text('未知'))
.append($("<option>").attr({'value':'','selected':'true'}).text('None')),
$('<label>').text(' **描述: '),
$('<input>').attr({'type':'text','class':'SATG-justp'})
),
$('<div>').css('margin-bottom','0.5em').append(
$('<label>').attr('id','SATG-labels-'+i).text('有效介紹? '),
$('<select>').attr('class','SATG-selects')
.append($("<option>").attr('value','y').text('是'))
.append($("<option>").attr('value','n').text('不是'))
.append($("<option>").attr('value','-').text('部份'))
.append($("<option>").attr('value','?').text('未知'))
.append($("<option>").attr({'value':'','selected':'true'}).text('None')),
$('<label>').text(' **描述: '),
$('<input>').attr({'type':'text','class':'SATG-justs'})
)
);
}
$("#SATG-interface-content").append(
$('<button>').attr('id','SATG-generate').text('生成!')
);
$('#SATG-generate').click(function() {
screen2(number);
});
}
function satg_init() {
mw.util.addPortletLink('p-tb', 'javascript:void(0)', '來源表格生成器', '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": "2px 20px",
"border": "1px solid #888",
"width": "80%",
"max-width": "60em",
"font-size": "90%"
});
$("#SATG-interface-content").css({
"min-height": "7em",
"width" : "875px",
"height" : "400px",
"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("來源分析表格生成器");
$("#SATG-interface-content").append(
$('<div>').css('margin-bottom','0.5em').append(
$('<label>').attr({'for':'SATG-userinput-label', 'id':'SATG-userinput-label'}).text('你想生成多少來源?'),
$('<input>').attr({'type':'number', 'name':'SATG-userinput','id':'SATG-userinput','min':'1','max':'100','value':'1'}) //set limits
),
$('<div>').css('margin-bottom','0.5em').append(
$('<button>').attr({'name':'SATG-userinput-button', 'id':'SATG-userinput-button'}).text('加載')
)
);
$("#SATG-interface-footer").append(
$('<button>').attr('id', 'SATG-cancel').text('關閉')
);
$('#SATG-cancel').click(function() {
$('#SATG-modal').remove();
});
$('#SATG-userinput-button').click(function() {
var temp = $('#SATG-userinput').val();
if (temp > 100 || temp < 1) {
alert('Invalid value');
}
else {
$('#SATG-interface-content').empty();
$('#SATG-interface-content').text('生成表格中...');
screen1(temp);
}
});
};
mw.loader.using(['mediawiki.util'], function() {
satg_init();
});
//</nowiki>