0

I'm trying to borrow the JavaScript from http://readable.tastefulwords.com/.

Instead of making it a bookmarklet, I wanted to turn the script into an extension. I DO NOT know a lot of Java, only enough to execute certain things. I figure it'll be easy, just borrow a tutorial Chrome extension template and put the script in somewhere.

Well, about 3 hours of researching and testing, I'm stuck. I can get other simple scripts to run EXCEPT the one from that site.

I have done some searching around and I even used the script design from this one post (last answer on that post): Run javascript with click on popup.html icon in Chrome extension

I managed to set up the prompt.js, and the code looks like this:

function promptBox()
  {
    _readableOptions=
    {
      'text_font':'quote(Palatino Linotype), Palatino, quote(Book Antigua), Georgia, serif','text_font_monospace':'quote(Courier New), Courier, monospace','text_font_header':'quote(Times New Roman), Times, serif','text_size':'18px','text_line_height':'1.5','box_width':'30em','color_text':'#282828','color_background':'#F5F5F5','color_links':'#0000FF','text_align':'normal','base':'blueprint','custom_css':''
    };
    if(document.getElementsByTagName('body').length>0);
    else
    {
      return;
    }    
    if(window.$readable)
    {
      if(window.$readable.bookmarkletTimer)
        {
          return;
        }
    }
    else
    {
      window.$readable={};
    }
    window.$readable.bookmarkletTimer=true;
    window.$readable.options=_readableOptions;
    if(window.$readable.bookmarkletClicked)
    {
      window.$readable.bookmarkletClicked();
      return;
    }
    _readableScript=document.createElement('script');
    _readableScript.setAttribute
      (
        'src','http://readable-static.tastefulwords.com/target.js?rand='+encodeURIComponent(Math.random())
      );
      document.getElementsByTagName('body')[0].appendChild(_readableScript);
   }

chrome.extension.onClicked.addListener(promptBox());

I just need that last script to work and I am sure it can make the article I want to read "readable".

4

1 回答 1

0

请注意,您的 if (document...) 语句保证什么都不做,这意味着 promptBox() 函数的其余部分是死代码。

if (something)
  ;
else {
  return;
}
于 2013-04-23T16:29:36.623 回答