MediaWiki:Chat.js

来自Don't Starve Wiki
跳转到导航 跳转到搜索

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:Ctrl-F5
var chatags = { images: true, videos: true };

importArticles({
    type: 'script',
    articles: [
        'u:dev:MediaWiki:ChatOptions/code.js',
        'u:dev:MediaWiki:ChatAnnouncements/code.js',
        'u:shining-armor:MediaWiki:ChatTags/code.js',
    ]
});


//##############################################################################################//
// Chat topic

// Credit: Runescape Wiki

// Description: Remember to escape single quotes in the topic using \' to prevent this from breaking.
//##############################################################################################//
 
var chatTopic = 'Welcome to the Dont Starve Wiki chat. Rules and more information can be found <a href="/wiki/Project:Rules" target="_blank" title="Project:Rules"><br /><u>here</u></a>. FAQs <a href="/wiki/Help:Chat" target="_blank" title="Chat FAQ"><u>here</u></a>. Emotes list <a href="/wiki/MediaWiki:Emoticons" target="_blank" title="Emojis"><u>here</u></a>';
 
$(function() {
	$('#ChatHeader .public.wordmark').prepend('<div class="chattopic" style="text-align:center; position:absolute; width:60%; z-index:0; font-size: 13px; color:#3A3A3A; font-weight:bold; line-height:1.6; margin-left:110px;">'+chatTopic+'</div>')
	.find('a').attr('style','position:relative;text-decoration:underline;');
})
$('#ChatHeader .public.wordmark div:not(:first-child)').remove();
 
//##############################################################################################//
// END Chat topic
//##############################################################################################//


//############################################################################//
// Spam protection

// Credit: Joeytje50 and COD wiki

// Description: Change these variables to modify the leniency of the script
//############################################################################//
 
var maxLimit = 6; // limit for sent lines
var maxLength = 1250; // limit for how long a line can be (in chars)
var limitTimeout = 2000; // timeout for the sent lines limiter
 
var rate = 0;
function ratelimit(e) {
	if (rate > maxLimit) {
		this.disabled = true;//disabling input in case they press ESC before the redirect is complete
		e.preventDefault();
		mainRoom.sendMessage({which : 13, shiftKey : false, preventDefault : function() {} })
		document.location.href = wgServer+"/wiki/Project:Chat/Ratelimit_triggered";
		return false;
	}
	if (this.value.length>=maxLength || this.value.split('\n').length>=6) {
		var val = this.value.substring(0,maxLength).split('\n');
		val = val[0]+'\n'+val[1]+'\n'+val[2]+'\n'+val[3]+'\n'+val[4];//remove all lines after the 5th line.
		this.value = val;
		if (e.type == 'keypress') {
			e.preventDefault();
			return false;
		}
	}
	if (e.type == 'keypress' && e.which == 13 && !e.shiftKey && this.value != '') {
		rate += 1;
		setTimeout(function() {
			if (rate > 0) { rate -= 1 }
		},limitTimeout);
	}
}
$('[name="message"]').keyup(ratelimit).keypress(ratelimit).keydown(ratelimit);
 
//############################################################################//
// END Spam protection
//############################################################################//