// ==UserScript== // @name Flickr Rich Edit // @description Adds a simple rich edit interface (Bold, Italic, Blockquote, Link) to any comment textarea on flickr. // @namespace http://www.rhyley.org/gm/ // @include http://*flickr.com/* // @exclude http://*flickr.com/messages_write.gne* // ==/UserScript== unsafeWindow.tagIt = function (tagOpen,tagClose,i) { // most of this bit is from http://placenamehere.com/photographica/js_textareas.html var ta = unsafeWindow.textArray[i]; var st = ta.scrollTop; if (ta.selectionStart | ta.selectionStart == 0) { // Mozzzzzzila relies on builds post bug #88049 // work around Mozilla Bug #190382 if (ta.selectionEnd > ta.value.length) { ta.selectionEnd = ta.value.length; } // decide where to add it and then add it var firstPos = ta.selectionStart; var secondPos = ta.selectionEnd+tagOpen.length; // cause we're inserting one at a time ta.value=ta.value.slice(0,firstPos)+tagOpen+ta.value.slice(firstPos); ta.value=ta.value.slice(0,secondPos)+tagClose+ta.value.slice(secondPos); // reset selection & focus... after the first tag and before the second ta.selectionStart = firstPos+tagOpen.length; ta.selectionEnd = secondPos; //ta.focus(); ta.scrollTop=st; } } unsafeWindow.linkIt = function (i) { var myLink = prompt("Enter URL:","http://"); if (myLink != null) { unsafeWindow.tagIt('','', i); } } textareas = document.evaluate("//textarea",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null); unsafeWindow.textArray = new Array(); for (i=0; i