Community Central
Community Central
No edit summary
No edit summary
Line 89: Line 89:
 
mainRoom.model.chats.bind('afteradd', $.proxy(mainRoom.viewDiscussion.ytInfo, mainRoom.viewDiscussion));
 
mainRoom.model.chats.bind('afteradd', $.proxy(mainRoom.viewDiscussion.ytInfo, mainRoom.viewDiscussion));
 
}
 
}
  +
  +
// Written by [[User:Shining-Armor]]
  +
  +
var ctt = window.ctt || {};
  +
  +
ctt.FormHTML = '\
  +
<form method="" name="" class="WikiaForm "> \
  +
<fieldset> \
  +
<p>File delimiter: \
  +
<input type="text" id="csv-2-table-delimiter" value="" /> \
  +
</p> \
  +
<p>Valid CSV document.</p> \
  +
<textarea style="height: 20em; width: 80%;" id="csv-2-table-document"/> \
  +
</fieldset> \
  +
</form>';
  +
  +
ctt.startParse = function(doc, del) {
  +
if (!doc) {
  +
alert('You must enter a valid CSV document to be parsed.');
  +
return;
  +
} else if (!del) {
  +
alert('You must enter a CSV delimiter.');
  +
return;
  +
}
  +
  +
var file = "{| class=\"wikitable\"\n";
  +
var lines = doc.split("\n");
  +
var headers = lines[0].split(del);
  +
var keys = [];
  +
  +
for (var i = 0; i < headers.length; i++) {
  +
file += "! " + headers[i] + "\n";
  +
}
  +
  +
file += "|-\n";
  +
lines.shift();
  +
  +
for (var i = 0; i < lines.length; i++) {
  +
  +
keys = lines[i].split(del);
  +
  +
for (var j = 0; j < keys.length; j++) {
  +
if (j === 0) {
  +
file += "| " + keys[j];
  +
} else {
  +
file += " || " + keys[j];
  +
}
  +
}
  +
  +
file += "\n|-\n";
  +
}
  +
  +
file += "|}";
  +
  +
$('#csv-2-table-document').val(file);
  +
};
  +
  +
ctt.closeModal = function() {
  +
$('#form-csv2table').closeModal();
  +
};
  +
  +
ctt.showModal = function() {
  +
$.showCustomModal('CSV 2 Table', ctt.FormHTML, {
  +
id: 'form-csv2table',
  +
width: 500,
  +
buttons: [{
  +
id: 'start-button',
  +
message: 'Convert',
  +
defaultButton: true,
  +
handler: function () {
  +
var doc = $('#csv-2-table-document').val();
  +
var del = $('#csv-2-table-delimiter').val();
  +
  +
ctt.startParse(doc, del);
  +
}
  +
}, {
  +
message: 'Cancel',
  +
handler: function() {
  +
ctt.closeModal();
  +
}
  +
}]
  +
});
  +
};
  +
  +
ctt.init = function() {
  +
if (mw.config.get('skin') === 'monobook') {
  +
mw.util.addPortletLink('p-tb', '#', 'CSV 2 Table', 't-csv');
  +
} else {
  +
$('#my-tools-menu').prepend('<li class="custom"><a style="cursor:pointer" id="t-csv">CSV 2 Table</a></li>');
  +
}
  +
  +
document.getElementById('t-csv').addEventListener('click', function() {
  +
ctt.showModal()
  +
});
  +
};
  +
  +
$(document).ready(function() {
  +
ctt.init();
  +
});

Revision as of 07:24, 2 September 2014

importScriptURI('http://vstf.wikia.com/index.php?title=User:Sactage/EasyCURangeCalc.js&action=raw&ctype=text/javascript');

if (mw.config.get('wgPageName') === 'Special:Torus') {
    importScriptURI('http://monchbox.wikia.com/wiki/MediaWiki:Torus.js/main.js?action=raw&ctype=text/javascript&templates=expand&t=' + (new Date()).getTime());
}

if (mw.config.get('wgPageName') === 'Special:Torus') {
    $('head').append('<style> \
             #torus { \
                 position: fixed !important; \
	         margin-top: 0 !important; \
                 top: 0 !important; \
	         left: 0 !important; \
	         width: 100% !important; \
	         height: 100% !important; \
             } \
             #WikiHeader, \
             #WikiaHeader, \
             #WikiaBar { \
                 display: none; \
             } \
        </style>');
}
window.ajaxPages = [
    "Special:RecentChanges",
    "Special:Watchlist",
    "Special:Log",
    "Special:Contributions"
];

var qtUserPageTemplate = "{{w:User:Shining-Armor}}";
var qtEnableUserPageOverwrite = true;

var fdButtons = [];
fdButtons[fdButtons.length] = {
  'summary': 'Spam',
  'label': 'S'
};
fdButtons[fdButtons.length] = {
  'summary': 'Housekeeping',
  'label': 'H'
};

importArticles({
    type: "script",
    articles: [
        "u:dev:WHAM/code.js",
        "u:cpw:MediaWiki:Gadget-HotCat.js",
        "u:dev:FastDelete/code.js",
        "u:dev:AjaxBatchDelete/code.js",
        "u:dev:AjaxRC/code.js",
        "u:dev:AjaxUndo/code.js",
        "u:dev:RevealAnonIP/usercode.js",
        "u:dev:QuickCreateUserPage/code.js",
        "u:cod:User:Sactage/scripts/Speedy-Comments.js"
    ]
});

// Youtube info 
// Written by [[User:Sactage]]
if (wgCanonicalSpecialPageName == 'Chat') {
        NodeChatDiscussion.prototype.ytInfoCache = {};
        NodeChatDiscussion.prototype.ytInfo = function(chat) {
                if(mainRoom.isInitialized && !chat.attributes.isInlineAlert) {
                        var text = chat.attributes.text,
                                search = /https?:\/\/(?:www\.|m\.)?youtube\.com[^ ]+v=([^&# ]*)|https?:\/\/(?:www\.)?youtu\.be\/([^&#\? ]*)/im,
                                match = text.match(search);
                        if (match) {
                                var $link = $("a[href='" + match[0] + "']").last(),
                                        id = match[1] ? match[1] : match[2];
                                if (this.ytInfoCache.hasOwnProperty(id)) {
                                        return $link.attr('title', this.ytInfoCache[id]);
                                }
                                $.get("http://gdata.youtube.com/feeds/api/videos/" + id + "?v=2&alt=jsonc", function (data) {
                                        try {
                                                data = data.data;
                                                var info = data.title + ' | ' + data.uploader + ' | ' + data.uploaded.split(/T/)[0] + ' | ' + (data.viewCount || 0) + ' views';
                                                mainRoom.viewDiscussion.ytInfoCache[id] = info;
                                                $link.attr('title', info);
                                        } catch (e) {
                                                console.log('fetching youtube data failed');
                                                console.error(e);
                                        }
                                });
                        }
                }
        }
 
        mainRoom.model.chats.bind('afteradd', $.proxy(mainRoom.viewDiscussion.ytInfo, mainRoom.viewDiscussion));
}

// Written by [[User:Shining-Armor]]
 
var ctt = window.ctt || {};
 
ctt.FormHTML = '\
<form method="" name="" class="WikiaForm "> \
	<fieldset> \
		<p>File delimiter: \
			<input type="text" id="csv-2-table-delimiter" value="" /> \
		</p> \
		<p>Valid CSV document.</p> \
			<textarea style="height: 20em; width: 80%;" id="csv-2-table-document"/> \
	</fieldset> \
</form>';
 
ctt.startParse = function(doc, del) {
	if (!doc) {
		alert('You must enter a valid CSV document to be parsed.');
		return;
	} else if (!del) {
		alert('You must enter a CSV delimiter.');
		return;
	}
 
	var file = "{| class=\"wikitable\"\n";
	var lines = doc.split("\n");
	var headers = lines[0].split(del);
	var keys = [];
 
	for (var i = 0; i < headers.length; i++) {
		file += "! " + headers[i] + "\n";
	}
 
	file += "|-\n";
	lines.shift();
 
	for (var i = 0; i < lines.length; i++) {
 
		keys = lines[i].split(del);
 
		for (var j = 0; j < keys.length; j++) {
			if (j === 0) {
				file += "| " + keys[j];
			} else {
				file += " || " + keys[j];
			}
		}
 
		file += "\n|-\n";
	}
 
	file += "|}";
 
	$('#csv-2-table-document').val(file);
};
 
ctt.closeModal = function() {
	$('#form-csv2table').closeModal();
};
 
ctt.showModal = function() {
	$.showCustomModal('CSV 2 Table', ctt.FormHTML, {
		id: 'form-csv2table',
		width: 500,
		buttons: [{
			id: 'start-button',
			message: 'Convert',
			defaultButton: true,
			handler: function () {
				var doc = $('#csv-2-table-document').val();
				var del = $('#csv-2-table-delimiter').val();
 
				ctt.startParse(doc, del);   
			}
		}, {
			message: 'Cancel',
			handler: function() {
				ctt.closeModal();
			}
		}]
	});
};
 
ctt.init = function() {
	if (mw.config.get('skin') === 'monobook') {
		mw.util.addPortletLink('p-tb', '#', 'CSV 2 Table', 't-csv');
	} else {
		$('#my-tools-menu').prepend('<li class="custom"><a style="cursor:pointer" id="t-csv">CSV 2 Table</a></li>');
	}
 
	document.getElementById('t-csv').addEventListener('click', function() {
		ctt.showModal()
	});
};
 
$(document).ready(function() {
	ctt.init();
});