簡體   English   中英

Chrome擴展程序的簡單JavaScript執行

[英]Simple javascript execution for Chrome Extension

我正在嘗試從http://read.tastefulwords.com/借用JavaScript。

我不想將其變成書簽,而是希望將腳本轉換為擴展名。 我不太了解Java,只夠執行某些事情。 我認為這很容易,只需借用Chrome擴展教程模板並將腳本放在某個地方即可。

好吧,大約3個小時的研究和測試,我陷入了困境。 我可以從該站點獲取其他簡單腳本來運行該腳本。

我做了一些搜索,甚至使用了這篇文章的腳本設計(該文章的最后答案): 單擊Chrome擴展程序中的popup.html圖標,運行javascript

我設法設置了hint.js,代碼如下所示:

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());

我只需要最后一個腳本即可工作,並且我確信它可以使我要閱讀的文章“可讀”。

請注意,您的if(document ...)語句肯定不會執行任何操作,這意味着hintBox()函數的其余部分為無效代碼。

if (something)
  ;
else {
  return;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM