Howrse smiley:3

old smileys

当前为 2015-08-26 提交的版本,查看 最新版本

// ==UserScript==
// @name         Howrse smiley:3
// @namespace    http://your.homepage/
// @version      0.551
// @description  old smileys
// @author       Xavier
// @include      gaia.equideow.com/*
// @include      ouranos.equideow.com/*
// @include 	 wwww.howrse.de/*
// @include      wwww.howrse.com/*
// @grant        none
// ==/UserScript==

var input;

function main(){
	var inter = setInterval(function(){var ret; ret = modifying(); if (ret == 1){clearInterval(inter);}},5000);
}

function modifying(){
	console.log("Starting");
	if(document.getElementById("messagesPmBody") != null) input = document.getElementById("messagesPmBody");
	else if(document.getElementById("actionPmBody") != null) input = document.getElementById("actionPmBody");
	else if(document.getElementById("createMessageMessage") !== null) input = document.getElementById("createMessageMessage");
	else if(document.getElementById("discussion") != null) input = document.getElementById("discussion");
	else if(document.getElementById("reponse") != null) input = document.getElementById("reponse");
	else return 0;
	input.onkeypress=myFunc;
	return 1;
}

function myFunc(){
	var possibleSmiley, match, i, myregex, text, place, smiley;
	i = 0;
	console.log("Changing to smiley");
	possibleSmiley = ["(xd)","(o_O)","(bis)","(grr)","(zzz)","(D8)","(omg)","(ninja)","(8D)","(snif)","(lol)","(8P)","(euh)","(up)","(bad)","(8)","(ker)","(bg)","(8)","(h)","(blink)"];
	myregex = /\(\w{1,5}\)/g;
	text = input.value;
	match = text.match(myregex);
	if (match != null){
		console.log(match);
		for (i=0;i<match.length;i++){
			console.log(i);
			console.log(match[i]);
			if(possibleSmiley.indexOf(match[i]) != -1){
				console.log("is in list");
				smiley = match[i].substr(1,match[i].length-2);
				smiley = "[img]http://smileys.alwaysdata.net/smileys/" + smiley + ".png[/img]";
				place = myregex.exec(text);
				console.log(place);
				text = text.substr(0,place.index) + smiley + text.substr(place.index+1 + match[i].length-1, text.length-1);
			}
		}
	}
	input.value = text;
}

main();