Blah i just tested it (i didnt test i before
) and document.getSelection() dosnt work quite right with textarea's (seems when the textarea looses focus it "hides" its selected text untill it refocus's)
so here the code that defintly works (i tested it
) , i also changed it a bit because doInsert seems to mess up sometimes (shows undefined
)
code:
function insertHyperlink() {
var urltitle = false;
var text;
var start = document.input.message.selectionStart;
var end = document.input.message.selectionEnd;
if(start!=end){
var string = document.input.message.value;
var startString = string.substr(0,start);
var endString = string.substr(end,string.length);
text = string.substr(start,end -start)
}
var url = text;
if(!url){
var url = prompt("Please enter the URL of the website.", "http://");
urltitle = prompt("If you wish to, you may also insert a title to be shown instead of the URL.", "");
if(urltitle){
doInsert("[url="+url+"]"+urltitle+"[/url]");
}else{
doInsert("[url]"+url+"[/url]");
}
return;
}else if(!url.match(/http:\/\//)){
var url = prompt("Please enter the URL of the website.", "http://");
urltitle = text;
}else{
url = text;
}
if(url) {
if(urltitle) {
document.input.message.value = startString + "[url="+url+"]"+urltitle+"[/url]" + endString
} else {
document.input.message.value = startString + "[url]"+url+"[/url]" + endString
}
} else {
alert("Error!\n\nYou did not enter a URL for the website. Please try again.");
}
}
and ja if you want to test install..
http://darktempler.be/gscript/msgplusforumurldifferent.user.js