views:

136

answers:

2

There are a lot of questions here about Greasemonkey, but I didn't see anything directly related to my question.

I'm on a website that uses a text editor control, and it's really annoying that they don't allow horizontal resizing (only vertical). So if you are using a cheapo projector that only supports 1024x768, the text runs off of the screen and there's nothing you can do about it.

I looked at the page source, and found the section of code that I want Greasemonkey to modify:

<script type="text/javascript">
// TinyMCE instance type: CD_TinyMCE
tinyMCE.init({
    convert_urls : "",
    mode : "specific_textareas",
    editor_selector : "rte",
    theme : "advanced",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,
    **theme_advanced_resize_horizontal : false**,
...

I just want to change the boldfaced value to true. I tried to approach this the brute force way and replace the text this way:

function allowHorizontalResize() {
  var search_string = "theme_advanced_resize_horizontal : false";
  var replace_string = "theme_advanced_resize_horizontal : true";
  var doc_text = document.body.innerHTML;
  document.body.innerHTML = doc_text.replace( search_string, replace_string);
}

...but it doesn't work. However, I know the basic search and replace part works because I can use this script to replace text within the editor -- I just can't change the javascript code that initializes the text editor.

Can someone explain what I'm doing wrong? Is this even possible?

+1  A: 

No, the script will have already executed when you apply the function. You will have to get the text editor's element, and apply the properties manually(assuming it is an element).

A link would make me more helpful.

digitalFresh
ah, so that's why... I'll give that a try, but what is the text editor's element? I assume you're saying that I need to get all of the script elements from document.getElementsByTagName() and then modify it at that point? I can't give you a link because the site requires a login.
Dave
I guess even getting the `script` element via GM is still too late. I verified with `alert` that I was getting the javascript properly, but the text editor still appeared when I tried to set its `innerHTML` property to "". :(
Dave
to reiterate, changing the innerHTML of a script will not do anything, unless you want to rerun the entire script. I meant you have to get the element that "only resizes vertically", and apply the css that lets it horizontally resize.
digitalFresh
Well, then perhaps it's just not possible, because that property isn't something that CSS could change. It's literally a parameter to a javascript function, as shown in my original post. Bummer!
Dave
The javascript function sets a css property. If the editor uses a textarea element, you can get that element, and change the css back to `resize:both;` instead of `resize:vertical;`
digitalFresh
+2  A: 

Try the simple direct approach, first. Your Greasemonkey script could be as easy as:

GM_addStyle ("#content_tbl {width: 900px !important;}");

-- which works on a default TinyMCE window.

Altering the javascript source code is probably not going to easily work. But, the Devil is in the details.

Provide a link to the page or pastebin the complete code.

Brock Adams
there's too much confidential info in the page source to search and replace, unfortunately. However, thank you for the tip about changing the width of the editor window. That totally worked!
Dave
If this worked then you might want to consider [writing a user style](http://userstyles.org/help/coding) instead of a user script, which will effect the textbox immediately, instead of when the page finishes loading.
Erik Vold