// @Version 1.0 - Adds a "Citation bot" link to the toolbox, and a button beneath edit fields.
function addCBToToolbox() {
if (mw.config.get('wgCanonicalNamespace') !== "Special") {
var pTb = document.getElementById("p-tb");
if( !pTb ) return;
var escPageName = encodeURIComponent(mw.config.get('wgPageName'));
mw.util.addPortletLink("p-tb", "//tools.wmflabs.org/citations/process_page.php?edit=Smith609&slow=1&user="+encodeURIComponent(mw.config.get('wgUserName'))+"&page="+escPageName, 'Expand citations', '', "Expand citations and fix common formatting errors");
}
}
// Add a citation bot button
function addCitationBot() {
if (document.getElementById('wpDiff')){
var diff = document.getElementById('wpDiff');
var cbButton = document.createElement("input");
cbButton.value="Citations";
cbButton.type="submit";
originalAction=document.getElementById('editform').getAttribute('action');
cbButton.setAttribute("onmousedown", " document.getElementById('editform').setAttribute('action', 'http://tools.wmflabs.org/citations/text.php')");
cbButton.setAttribute("onkeydown", " document.getElementById('editform').setAttribute('action', 'http://tools.wmflabs.org/citations/text.php')");
diff.setAttribute("onmousedown", originalAction);
diff.setAttribute("onkeydown", originalAction);
document.getElementById('wpPreview').setAttribute("onmousedown", originalAction);
document.getElementById('wpPreview').setAttribute("onkeydown", originalAction);
document.getElementById('wpSave').setAttribute("onmousedown", originalAction);
document.getElementById('wpSave').setAttribute("onkeydown", originalAction);
diff.parentNode.insertBefore(cbButton, diff.nextSibling);
}
}
$( addCitationBot );
if( $.inArray( mw.config.get('skin'), ["myskin" , "simple" , "monobook" , "modern", "chick" , "vector" ] ) !== -1 ) {
$( addCBToToolbox );
}