簡單幾行JS Code實現IE郵件轉寄新浪微博

來源:互聯網
上載者:User

最近剛開通新浪圍脖,突發奇想,想做個瀏覽器外掛程式實現文字新聞等的轉寄圍脖的外掛程式。本以為應該用C++寫個外掛程式的(c#那麼大個殼有時真的讓人頭疼),但是google了一下,手氣真的不錯,搜到了,幾篇關於IE外掛程式的開發。用的Javascript,和添加註冊表就可以完全搞定。外掛程式用javascript寫那就不用多說,瀏覽器本身就支援的,不用額外安裝。添加註冊表手動可以添加,但是麻煩所以寫了一個批處理搞定。

1:添加註冊表:HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\<Menu Text> 設定預設值為html檔案路徑,添加值Contexts為)0xf3.

2:code  :  在MSDN http://msdn.microsoft.com/en-us/library/aa753589(v=VS.85).aspx中有所講解。MSDN原文:Set the default value of the key to the URL of the page that contains the script you want the context menu entry to execute. This script can obtain the parent window object, the screen where the context menu item was executed, from the menuArguments property of the external object.

大概就是說我們可以用window.external.menuArguments這個對象擷取到內部的資訊,如window,document這些常用的對象。所以我們就可以馬上開工了,三下五去二不幾分鐘就搞定(代碼很簡單就直接Code了):

複製代碼 代碼如下:
<SCRIPT LANGUAGE = "JavaScript">
var oWindow = window.external.menuArguments;
var oDocument = oWindow.document;
var oSelect = oDocument.selection;

var oSelectRange = oSelect.createRange();
var sNewText = oSelectRange.text;//.substring(0,140);

var title=sNewText.length == 0?oDocument.title:sNewText;
if (title.length>0){
oWindow.open("http://service.weibo.com/share/share.php?title="+encodeURIComponent(title)+"&url="+encodeURIComponent(oDocument.URL)+"&source="+encodeURIComponent("破

狼")+"&appkey=1027675428&sourceUrl="+encodeURIComponent(oDocument.URL));
}
</SCRIPT>


看一個效果:



缺點:在這裡只是簡單擷取的下文本值的內容,還沒有找到擷取選中html或者對象的方式,正在尋找,如果有知道的請不吝賜教。我打算是可以解析出視頻,圖片等,發送。

下載【直接點擊批處理運行,重啟IE】

參考文獻:

http://msdn.microsoft.com/en-us/library/aa753589(v=VS.85).aspx
http://blogs.msdn.com/b/oldnewthing/archive/2004/05/24/140283.aspx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.