User:Mr.Z-man/refToolbar.js
Appearance
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 user script seems to have a documentation page at User:Mr.Z-man/refToolbar. |
var numforms = 0;
function fancyButton(image, JSfunction, title) {
button = document.createElement('a');
button.href = JSfunction;
button.title = title;
buttonimage = document.createElement('img');
buttonimage.src = image;
buttonimage.alt = title;
button.appendChild(buttonimage);
document.getElementById('toolbar').appendChild(button);
}
function refbuttons() {
if (mwCustomEditButtons && document.getElementById('toolbar')) {
fancyButton("/media/wikipedia/commons/9/91/Button_cite_web.png", "javascript:citeWeb()", "Web citation");
fancyButton("/media/wikipedia/commons/2/2c/Button_cite_news.png", "javascript:citeNews()", "News citation");
fancyButton("/media/wikipedia/commons/e/ef/Button_cite_book.png", "javascript:citeBook()", "Book citation");
}
}
function getTime() {
var time = new Date();
var curday = time.getDate();
var curmonth = time.getMonth()+1;
var nowyear = time.getYear()+1900;
var nowday = curday.toString();
if (curday <10) { nowday = "0"+nowday;}
var nowmonth = curmonth.toString();
if (curmonth <10) { nowmonth = "0"+nowmonth;}3
newtime = nowyear + '-' + nowmonth + '-' + nowday
return (newtime);
}
function citeWeb() {
citeNewsWeb("cite web");
}
function citeNews() {
citeNewsWeb("cite news");
}
function citeNewsWeb(templatename) {
if (numforms != 0) {
document.getElementById('citediv'+numforms).style.display = 'none';
}
template = templatename;
newtime = getTime();
numforms++;
form = '<div id=\"citediv'+numforms+'\" style= \"margin: 0 0 1em; padding: .5em 1em; vertical-align: middle; border: solid #aaaaaa 1px\"><form id=\"citeform'+numforms+'\">'+
'<table>'+
'<tr><td width=\"100\"><label for=\"url\"> URL: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"url\"></td>'+
'<td width=\"100\"><label for=\"title\"> Title: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"title\"></td></tr>'+
'<tr><td width=\"100\"><label for=\"last\"> Last name: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"last\"></td>'+
'<td width=\"100\"><label for=\"first\"> First name: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"first\"></td></tr>'+
'<tr><td width=\"100\"><label for=\"coauthors\"> Coauthors: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"coauthors\"></td>'+
'<td width=\"100\"><label for=\"date\"> Publication date: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"date\"></td></tr>'+
'<tr><td width=\"100\"><label for=\"work\"> Work: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"work\"></td>'+
'<td width=\"100\"><label for=\"publisher\"> Publisher: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"publisher\"></td></tr>'+
'<tr><td width=\"100\"><label for=\"pages\"> Pages: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"pages\"></td>'+
'<td width=\"100\"><label for=\"language\"> Language: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"language\"></td></tr>'+
'<tr><td width=\"100\"><label for=\"date\"> Date: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"date\"></td>'+
'<td width=\"100\"><label for=\"accessdate\"> Access date: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"accessdate\" value=\"'+ newtime +'\"></td></tr>'+
'<input type=\"button\" value=\"Add citation\" onClick=\"addcites(template)\">'+
'</table>'+
'</form></div>';
document.getElementById('wikiPreview').innerHTML += form;
}
function citeBook() {
if (numforms != 0) {
document.getElementById('citediv'+numforms).style.display = 'none';
}
template = "cite book";
numforms++;
form = '<div id=\"citediv'+numforms+'\" style= \"margin: 0 0 1em; padding: .5em 1em; vertical-align: middle; border: solid #aaaaaa 1px\"><form id=\"citeform'+numforms+'\">'+
'<table>'+
'<tr><td width=\"100\"><label for=\"last\"> Last name: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"last\"></td>'+
'<td width=\"100\"><label for=\"first\"> First name: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"first\"></td></tr>'+
'<tr><td width=\"100\"><label for=\"coauthors\"> Coauthors: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"coauthors\"></td>'+
'<td width=\"100\"><label for=\"others\"> Others: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"others\"></td></tr>'+
'<tr><td width=\"100\"><label for=\"title\"> Title: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"title\"></td>'+
'<td width=\"100\"><label for=\"editor\"> Editor: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"editor\"></td></tr>'+
'<tr><td width=\"100\"><label for=\"publisher\"> Publisher: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"publisher\"></td>'+
'<td width=\"100\"><label for=\"location\"> Location: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"Location\"></td></tr>'+
'<tr><td width=\"100\"><label for=\"date\"> Publication date: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"date\"></td>'+
'<td width=\"100\"><label for=\"edition\"> Edition: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"edition\"></td></tr>'+
'<tr><td width=\"100\"><label for=\"series\"> Series: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"series\"></td>'+
'<td width=\"100\"><label for=\"volume\"> Volume: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"volume\"></td></tr>'+
'<tr><td width=\"100\"><label for=\"pages\"> Pages: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"pages\"></td>'+
'<td width=\"100\"><label for=\"chapter\"> Chapter: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"chapter\"></td></tr>'+
'<tr><td width=\"100\"><label for=\"isbn\"> ISBN: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"isbn\"></td>'+
'<td width=\"100\"><label for=\"oclc\"> OCLC: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"oclc\"></td></tr>'+
'<tr><td width=\"100\"><label for=\"url\"> URL: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"url\"></td>'+
'<td width=\"100\"><label for=\"accessdate\"> Access date: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"accessdate\"></td></tr>'+
'<tr><td width=\"100\"><label for=\"language\"> Language: </label></td>'+
'<td width=\"500\"><input type=\"text\" style=\"width:100%\" id=\"language\"></td></tr>'+
'<input type=\"button\" value=\"Add citation\" onClick=\"addcites(template)\">'+
'</table>'+
'</form></div>';
document.getElementById('wikiPreview').innerHTML += form;
}
function addcites(template) {
cites = document.getElementById('citeform'+numforms).getElementsByTagName('input');
var insert = "<ref>{{" + template;
for (var i=0; i<cites.length-1; i++) {
if (cites[i].value != '') {
insert += "|" + cites[i].id + "=" + cites[i].value;
}
}
insert += "}}</ref>";
insertTags(insert, '', '');
document.getElementById('citediv'+numforms).style.display = 'none';
}
hookEvent("load", refbuttons);