Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump.
This code will be executed when previewing this page.
This code will be executed when previewing this page.
Documentation for this user script can be added at User:MSK/SATG.
// DO NOT USE!!! NOT FUNCTIONAL RIGHT NOW
//Originally written by Abelmoschus Esculentus
//Creation date: 12 January 2019
//Copied from [[User:DannyS712/SATG.js]]
//Modified to add "Load all sources" functionality
//<nowiki>
function getArticleRefUrls() {
var urls = [];
$('ol.references > li').each(function () {
var $cite = $(this).children('span.reference-text').children('cite.citation');
var $link = $cite.children('a.external.text[rel="nofollow"]');
if ($link.length) {
urls.push($link.attr('href'));
}
});
// deduplicate
urls = urls.filter(function (url, i, arr) {
return arr.indexOf(url) === i;
});
return urls;
}
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";
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",
"width" : "875px",
"height" : "400px",
"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, urls) {
// If urls provided with nonzero length, override number
if (!urls || !urls.length) {
urls = [];
for (var j = 0; j < number; j++) {
urls.push('');
}
} else {
number = urls.length;
}
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 () {
$('#SATG-back').remove();
$("#SATG-interface-content").css({
"min-height": "7em",
"width" : "875px",
"height" : "400px",
"overflow-y": "scroll"
});
screen0();
});
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'}).val(urls[i - 1])
),
$('<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-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": "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("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','max':'100','value':'1'}) //set limits
),
$('<div>').css('margin-bottom','0.5em').append(
$('<button>').attr({'name':'SATG-userinput-button', 'id':'SATG-userinput-button'}).text('Load'),
$('<button>').attr({'id':'SATG-loadall-button'}).css('margin-left','0.5em').text('Load all sources')
)
);
$("#SATG-interface-footer").append(
$('<button>').attr('id', 'SATG-cancel').text('Close')
);
$('#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('Loading form...');
screen1(temp);
}
});
$('#SATG-loadall-button').click(function() {
var urls = getArticleRefUrls();
if (urls.length === 0) {
alert('No reference URLs found on this page.');
return;
}
$('#SATG-interface-content').empty();
$('#SATG-interface-content').text('Loading form...');
screen1(0, urls);
});
};
mw.loader.using(['mediawiki.util'], function() {
satg_init();
});
//</nowiki>