Changing the parameters of a Javascript function using GreaseMonkey

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2010-06-18T05:39:20Z Indexed on 2010/06/18 5:43 UTC
Read the original article Hit count: 281

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about greasemonkey