Note: After saving, you may have to bypass your browser's cache to see the changes.
function insertAfter(referenceNode, newNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
function navboxgenerator_init() {
// create a new li node
var li = document.createElement('li');
li.innerHTML = '<a class="sidebar-item" id="aca-satg">Navbox generator</a>';
li.setAttribute('class','sidebar-link mw-list-item');
// insert a new node after the last list item
//document.getElementById('t-specialpages').after(li);
insertAfter(document.getElementById('t-specialpages'),li);
//mw.util.addPortletLink('p-tools', 'javascript:void(0)', 'Generate navbox', 'aca-navboxgenerator', 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");
$("#SATG-interface-header").text("Navbox generator output");
var table = document.getElementsByClassName("wikitable")[0];
var parser = new DOMParser();
const filter_href_exists = /(?<=\/wiki\/).*$/g;
const filter_title_doesntexist = /.+?(?= \(page does not exist\))/g;
const filter_title_doesntexist2 = RegExp('.+?(?= \\(page does not exist\\))', 'g');
var i=1;
var length = table.rows.length;
var parkname = document.getElementById('desktop-header').innerHTML;
var output = '{{Amusement park navbox\n|park = ' + parkname + '\n|coasters-present =';
for (i=1;i<length;i++){
var htmlDoc = parser.parseFromString(table.rows[i].cells[0].innerHTML, 'text/xml');
var class_ = htmlDoc.firstElementChild.getAttribute('class');
var contents = htmlDoc.firstElementChild.innerHTML;
if (class_ == 'new'){
// Page does not exist
var title = htmlDoc.firstElementChild.getAttribute('title');
//var title = filter_title_doesntexist.exec(title);
var title = title.match(filter_title_doesntexist);
if (contents == title){
console.log('* \[\[' + title + '\]\]')
output += '* \[\[' + title + '\]\]\n'
} else {
console.log('* \[\[' + title + '|'+ contents + '\]\]')
output += '* \[\[' + title + '|'+ contents + '\]\]\n'
}
}else{
var title = htmlDoc.firstElementChild.getAttribute('title');
if (contents == title){
console.log('* \[\[' + title + '\]\]')
output += '* \[\[' + title + '\]\]\n'
} else {
console.log('* \[\[' + title + '|'+ contents + '\]\]')
output += '* \[\[' + title + '|'+ contents + '\]\]\n'
}
}
}
output += '\n';
var table = document.getElementsByClassName("wikitable")[1];
var parser = new DOMParser();
var i=1;
var length = table.rows.length;
output += '|coasters-former =';
for (i=1;i<length;i++){
var htmlDoc = parser.parseFromString(table.rows[i].cells[0].innerHTML, 'text/xml');
var class_ = htmlDoc.firstElementChild.getAttribute('class');
var contents = htmlDoc.firstElementChild.innerHTML;
if (class_ == 'new'){
// Page does not exist
var title = htmlDoc.firstElementChild.getAttribute('title');
//var title = filter_title_doesntexist.exec(title);
var title = title.match(filter_title_doesntexist);
if (contents == title){
console.log('* \[\[' + title + '\]\]')
output += '* \[\[' + title + '\]\]\n'
} else {
console.log('* \[\[' + title + '|'+ contents + '\]\]')
output += '* \[\[' + title + '|'+ contents + '\]\]\n'
}
}else{
var title = htmlDoc.firstElementChild.getAttribute('title');
if (contents == title){
console.log('* \[\[' + title + '\]\]')
output += '* \[\[' + title + '\]\]\n'
} else {
console.log('* \[\[' + title + '|'+ contents + '\]\]')
output += '* \[\[' + title + '|'+ contents + '\]\]\n'
}
}
}
output += '\n';
var table = document.getElementsByClassName("wikitable")[2];
var parser = new DOMParser();
var i=1;
var length = table.rows.length;
output += '|rides-present =';
for (i=1;i<length;i++){
var htmlDoc = parser.parseFromString(table.rows[i].cells[0].innerHTML, 'text/xml');
var class_ = htmlDoc.firstElementChild.getAttribute('class');
var contents = htmlDoc.firstElementChild.innerHTML;
if (class_ == 'new'){
// Page does not exist
var title = htmlDoc.firstElementChild.getAttribute('title');
//var title = filter_title_doesntexist.exec(title);
var title = title.match(filter_title_doesntexist);
if (contents == title){
console.log('* \[\[' + title + '\]\]')
output += '* \[\[' + title + '\]\]\n'
} else {
console.log('* \[\[' + title + '|'+ contents + '\]\]')
output += '* \[\[' + title + '|'+ contents + '\]\]\n'
}
}else{
var title = htmlDoc.firstElementChild.getAttribute('title');
if (contents == title){
console.log('* \[\[' + title + '\]\]')
output += '* \[\[' + title + '\]\]\n'
} else {
console.log('* \[\[' + title + '|'+ contents + '\]\]')
output += '* \[\[' + title + '|'+ contents + '\]\]\n'
}
}
}
output += '\n';
var table = document.getElementsByClassName("wikitable")[3];
var parser = new DOMParser();
var i=1;
var length = table.rows.length;
output += '|rides-former =';
for (i=1;i<length;i++){
var htmlDoc = parser.parseFromString(table.rows[i].cells[0].innerHTML, 'text/xml');
var class_ = htmlDoc.firstElementChild.getAttribute('class');
var contents = htmlDoc.firstElementChild.innerHTML;
if (class_ == 'new'){
// Page does not exist
var title = htmlDoc.firstElementChild.getAttribute('title');
//var title = filter_title_doesntexist.exec(title);
var title = title.match(filter_title_doesntexist);
if (contents == title){
console.log('* \[\[' + title + '\]\]')
output += '* \[\[' + title + '\]\]\n'
} else {
console.log('* \[\[' + title + '|'+ contents + '\]\]')
output += '* \[\[' + title + '|'+ contents + '\]\]\n'
}
}else{
var title = htmlDoc.firstElementChild.getAttribute('title');
if (contents == title){
console.log('* \[\[' + title + '\]\]')
output += '* \[\[' + title + '\]\]\n'
} else {
console.log('* \[\[' + title + '|'+ contents + '\]\]')
output += '* \[\[' + title + '|'+ contents + '\]\]\n'
}
}
}
output +='}}<noinclude>[[Category:Amusement park navboxes]]</noinclude>';
//prompt("Output:",output)
$("#SATG-interface-content").append(
$('<div>').css('margin-bottom','0.5em').append(
$('<textarea>').attr({'rows':'20', 'id':'SATG-userinput-label'}).text(output)
)
);
$("#SATG-interface-footer").append(
$('<button>').attr('id', 'SATG-cancel').text('Close')
);
$('#SATG-cancel').click(function() {
$('#SATG-modal').remove();
});
});
};
navboxgenerator_init();