それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

EmEditorとXmlHttpの活用

EmEditorのマクロでXmlHttpがつかえてどうなんだ?と思って。http:// xxx で色が変わるリンク先のソースを取得するEmEditorのマクロ書いてみた。


XMLソースファイルを表示できません」とIEに怒られたときに使うと便利かも。

以下ソース

/****
* @name Emeditor マクロ
* @desciption カーソル位置のリンクURLのコンテンツを取得し、新規タブの中に入れる。
* @modified 06/11/10
* @author takuya
* @finename viewSrcInNewTab.jsee 
*/
function XmlHttpRequest(){
  this.context = null;//static
  this.xmlhttp = function(){//static
    var obj = new ActiveXObject("Microsoft.XMLHTTP");
    return obj;
  }
  this.request = function(url){
    var req = this.xmlhttp();
    req.open("GET", url, false );
    req.send(null);
    this.context = req.responseText;
  }
}
document.selection.copyLink();
text = Window.clipboardData.getData("Text");
if(text.indexOf("http://") == 0) {
  var client = new XmlHttpRequest();
  client.request(text);
  var html = client.context;
  if(html.length > 0){
    editor.newFile();
      document.ConfigName = "HTML";
      document.write(html);
  }
}

もうちょっと改良したいね。相対パス解決とか。Xml/Html/JS/CSS判定とか、画像だったらビューアで開くとか。