それマグで!

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

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

ソース表示のマクロを改良。

HTMLを編集中にリンク先を表示して、ソースをEmEditorで表示するのが面倒。流行のXmlHttpがEmEditorに新しい息吹を吹き込めばいいな。

「リンク先をEmEditorで開く」マクロ。「リンク先を表示」の代わりに使えばいいやと思った。

/**************
* @description カーソル位置のURLをEmEditorで開く。
*(XmlHttp版)
* http://www.livedoor.com/ のように
* URLにカーソルがある時,このマクロを実行すると、
* そのコンテンツを新規タブで開きます。
* ソース表示が出来ない場合に有効かもしれません。
* HTMLを編集時にリンクしたCSS や JS の中身確認に便利です
* 注意)EUC文字コードの処理が正しくできません。
* @lastmodified 2006/11/28
* @author takuya_1st
* @name viewSrcInNewTab.jsee
* @version 1.0 alpha
*/


function XmlHttpRequest(){
  this.context = null;//static
  this.timeID  = null;
  this.xmlhttp = function(){//static
    var obj = new ActiveXObject("Microsoft.XMLHTTP");
    this.timeID = "";
    return obj;
  }
  this.request = function(url){
    var req = this.xmlhttp();
    req.open("GET", url, false );
    req.send(null);
    this.context = req.responseText;
    this.typeName( req.getResponseHeader("Content-Type") );
    this.status  = req.status;
  }
  this.typeName = function ( str ){
  //text/htmlから、HTMLを、text/plainからTEXTを返す
    this.responseMajorType = str.split("/")[0];
    this.responseSubtype   = str.split("/")[1];
  }
}
document.selection.copyLink();
text = Window.clipboardData.getData("Text");
if(text.indexOf("http://") == 0) {
  var client = new XmlHttpRequest();
  client.request(text);
  if( client.status >= 200 && client.status < 400 ){
    if( client.responseMajorType == "text" ){
      editor.newFile();
      document.write(client.context);
      document.selection.StartOfDocument();
      switch( client.responseSubtype ){
        case("vbscript"):
          document.ConfigName = "VBScript";break;
        case("javascript"):
          document.ConfigName = "JavaScript";break;
        case("css"):
          document.ConfigName = "CSS";break;
        case("sgml"):
        case("xml"):
          document.ConfigName = "XML";break;
        case("html"):
          document.ConfigName = "TEXT";break;
        case("plain"):
        default: document.ConfigName = "TEXT";
      }
    }
  }
}

とりあえず、今のところ、わかっている問題点。

  1. EUC-JPのサイトが化け化けになる。
  2. XmlHttpのタイムアウト処理がない。

文字化けは近いうちに何とかします。。