Page 1 of 1
Greasemonkey, forms & selected text copy.
Posted: Thu Jan 31, 2008 1:09 pm
by JAM
I'm calling for aid because... well I'm lazy and tired of this now.
I'd like, to select text in an <textarea> and by using a greasemonkey script add the functionality that phpbb's tag-buttons.I've tried various of functions as window.getSelection().toString(); and similiar without result. Would post code, but I don't have it here.
Code: Select all
Some [color=#FF0000]text selected[/color] here
...transforms after passing through greasemonkey...
Code: Select all
[color=#FF0000]text selected[/color]
here
Re: Greasemonkey, forms & selected text copy.
Posted: Thu Jan 31, 2008 3:35 pm
by Weirdan
That should be easy:
[js] unsafeWindow.bbfontstyle('[bb]','[/bb]'); [/js]
This will work on phpbb forums (this one for example) because they provide such a function.
Here's what I quickly hacked together:
Code: Select all
var buttons = document.getElementsByClassName('button2');
var button = undefined;
for (var i = 0, l = buttons.length; i < l; i++) {
if (buttons.item(i).parentNode.id == 'format-buttons') {
button = buttons.item(i);
break;
}
}
if (button) {
['php','js','sql'].forEach(function(lang) {
var newButton = button.cloneNode(false);
newButton.value = lang;
newButton.title = 'Wrap in ' + lang + ' tags';
newButton.setAttribute('onclick', "");
newButton.addEventListener('click', function() {
unsafeWindow.bbfontstyle('[code=' + lang + ']', '[/' + 'code]');
}, false);
button.parentNode.insertBefore(newButton, null);
});
}
Re: Greasemonkey, forms & selected text copy.
Posted: Thu Jan 31, 2008 11:41 pm
by JAM
Ahhhha! Thanks for that. Will disect that later and hopefully learn something.
Re: Greasemonkey, forms & selected text copy.
Posted: Mon Feb 04, 2008 10:39 am
by JAM
getElementsByClassName Is a Firefox 3 feature tho. But nevermind, I'll mess around with it.
Re: Greasemonkey, forms & selected text copy.
Posted: Sat Feb 09, 2008 2:46 pm
by Weirdan
JAM wrote:getElementsByClassName Is a Firefox 3 feature tho. But nevermind, I'll mess around with it.
Yeah, I must have forgotten about that because I use ff3 for over a month already (and recommend it to everyone for performance reasons. Eats less memory too).