old smileys
当前为
// ==UserScript==
// @name Howrse smiley:3
// @namespace http://your.homepage/
// @version 0.6
// @description old smileys
// @author Xavier
// @include gaia.equideow.com/*
/// @include http://gaia.equideow.com/*
// @include http://ouranos.equideow.com/*
// @include http://wwww.howrse.de/*
// @include http://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, cursor;
i = 0;
console.log("Changing to smiley");
cursor = input.selectionStart;
possibleSmiley = ["(xd)","(o_O)","(bis)","(grr)","(zzz)","(D8)","(omg)","(ninja)","(8D)","(snif)","(lol)","(8P)","(euh)","(up)","(bad)","(8)","(ker)","(bg)","(8)","(h)","(blink)","(ski)","(mur)","(mmm)","(smoke)","(yeah)"];
myregex = /\(\w{1,5}\)/g;
smiley = ""
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);
cursor -= (smiley.length+2)
smiley = "[img]http://smileys.alwaysdata.net/smileys/" + smiley + ".gif[/img]";
cursor += smiley.length;
place = myregex.exec(text);
text = text.substr(0,place.index) + smiley + text.substr(place.index+1 + match[i].length-1, text.length-1);
}
}
}
input.value = text;
input.selectionStart = cursor
input.selectionEnd = cursor
}
main();