Username-completion

Tab cycles through users starting with characters

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name           Username-completion
// @namespace      tag://kongregate
// @description    Tab cycles through users starting with characters
// @include        http://www.kongregate.com/games/*
// @author         Ventero
// @date           03.01.2012
// @version        1.5
// require        http://kong.ventero.de/updates/49872.js
// ==/UserScript==

// Written by Ventero (http://www.kongregate.com/accounts/Ventero) 05/23/09
// Thanks to kaedenn for the idea of adding a colon if the username is the first word in the message
// Copyright (c) 2009-2012 Ventero, licensed under MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php

var s = document.createElement("script");
s.textContent = "(" +
function init_nameCompletion(){
	if(typeof ChatDialogue === "undefined" ||
	   ChatDialogue.prototype.oldKeyPressTab) return;

	var isChrome = (navigator.appVersion.indexOf("Chrome") >= 0);
	if(isChrome) {
		ChatDialogue.prototype.initialize =
		ChatDialogue.prototype.initialize.wrap(function(old, p, i, h, u){
			old(p, i, h, u);
			var self = this;
			this._input_node.observe("keydown", function(event) {
				if(event.keyCode != 9 || event.ctrlKey || event.altKey || event.metaKey) return;
				self.onKeyPress(event);
			});
		})
	}

	ChatDialogue.prototype.oldKeyPressTab = ChatDialogue.prototype.onKeyPress;
	ChatDialogue.prototype.tabcnt = 0;
	ChatDialogue.prototype.done = 1;
	ChatDialogue.prototype.onKeyPress = function(a){
		if (a.keyCode != 9 || a.ctrlKey){
			this.tabcnt = 0;
			this.done = 1;
			this.oldKeyPressTab(a);
			return;
		}

		var node = (this._input_node.wrappedJSObject || this._input_node);
		if (this.tabcnt == 0 && this.done == 1){
			var inputText = node.getValue(),
			    spaceAtCaret = inputText.substr(0, node.selectionStart).lastIndexOf(' ');
			this._caretPos = node.selectionStart;
			this._start = inputText.substr(0,spaceAtCaret);
			if(this._start) this._start+=" ";

			this._currentWord = inputText.substring(spaceAtCaret+1, this._caretPos);
			this._rest = inputText.substr(this._caretPos);
		}
		this.done = 0;

		var userArray = this._holodeck.chatWindow().activeRoom()._users_list,
		    possibleMatches = [],
		    z = node.getValue();
		if (z.match(/\s+$/)) z=z.replace(/\s+$/, '')

		for (var i=0;i<userArray.length;i++){
			if(userArray[i].username.toLowerCase().indexOf(this._currentWord.toLowerCase())==0){
				possibleMatches.push(userArray[i].username);
			}
		}

		if (this.tabcnt < possibleMatches.length){
			node.setValue(this._start + possibleMatches[this.tabcnt] + (this._start?" ":": ") + this._rest);
			node.selectionStart = this._caretPos + possibleMatches[this.tabcnt].length - this._currentWord.length+(this._start?1:2);
			node.selectionEnd = node.selectionStart;
			this.tabcnt+=1;
		} else {
			node.setValue(this._start + this._currentWord + this._rest);
			node.selectionStart = this._caretPos;
			node.selectionEnd = this._caretPos;
			this.tabcnt = 0
		}
		if(a.stop) a.stop();
		if(a.preventDefault) a.preventDefault();
	}
} + ")();";

window.setTimeout(function(){
	document.body.appendChild(s);
	document.body.removeChild(s);
}, 0);