OSDN Git Service

Ready for : Integration generator and mixi-wrapper.
authorelixirel <elixirel@users.sourceforge.jp>
Mon, 13 Jul 2009 13:39:04 +0000 (22:39 +0900)
committerelixirel <elixirel@users.sourceforge.jp>
Mon, 13 Jul 2009 13:39:04 +0000 (22:39 +0900)
.gitignore
js/lunardial/feedblog_gen.js

index 64fb2e8..8e54965 100644 (file)
@@ -1,3 +1,4 @@
 
 *.doc
-.project
\ No newline at end of file
+.project
+.tmp*
\ No newline at end of file
index 6d11670..ea150cc 100644 (file)
@@ -61,7 +61,7 @@ function applyChange(){
         entryList[editIndex].updated = getDate();
         entryList[editIndex].content = document.getElementById("entry_stdin").value.replace(/\r\n/g, "\n");
                
-               document.getElementById("logBox").options[editIndex + 1].text = entryList[editIndex].title;
+               document.getElementById("logBox").options[parseInt(editIndex) + 1].text = entryList[editIndex].title;
     }
     
     document.getElementById("stdout").value = toXml(feedInfo, entryList);
@@ -70,6 +70,62 @@ function applyChange(){
     document.getElementById("previewArea").innerHTML = entryList[editIndex].content.replace(/\n/g, "<br>");
 }
 
+
+/**
+ * mixi用に通常のHTMLを変換します
+ * @param {String} contents 日記の本文が格納されている文字列
+ */
+function mixiWrapper(contents){
+    // 置換に使用する変数
+    var target_tag;
+    var target_element;
+    
+    // ニコニコ動画のタグを置換
+    while (target_tag = contents.match(/<iframe[^>]*src=["']http:\/\/ext.nicovideo.jp\/thumb\/[A-Za-z]*\d*["'][^>]*>[^<]*<\/iframe>/i)) {
+        // src="..."の部分だけ抜き出す
+        target_element = target_tag[0].match(/src=["'][^"']*["']/i);
+        target_element = '&lt;externalvideo src=&quot;NC:' + target_element[0].replace(/src=["']http:\/\/ext.nicovideo.jp\/thumb\/|["']/ig, "") + ':D&quot;&gt;';
+        // iframeタグ全体を置換する
+        contents = contents.replace(target_tag, target_element);
+    }
+    
+    // Aタグを変換する
+    while (contents.match(/<a[^>]*>/)) {
+        // 置換対象のAタグを抽出する
+        target_tag = contents.match(/<a[^>]*>/i);
+        // href="..."の部分のみを抜き出す
+        target_element = target_tag[0].match(/href=["'][^"']*["']/i);
+        // 相対URIが検出された場合、フルに置換する
+        var baseUri = document.location.href.replace(/[^\/]+$/, '');
+        target_element = target_element[0].replace(/\.\//, baseUri).replace(/\.\.\//g, "");
+        // Aタグ全体を消去し、再度Aクローズタグの置換を行う
+        contents = contents.replace(target_tag, "");
+        contents = contents.replace(/<\/a>/i, " ( " + target_element.replace(/href=|["']/g, "") + " ) ");
+    }
+    
+    // ブロック要素のタグが存在した場合、改行をその後に挿入します。
+    // if (document.getElementById("isCoverBlockTag").checked) {
+       if (true) {
+        contents = contents.replace(/<(div|h\d|p)[^>]*>/ig, "-----------------------------------------------------------------------------\n");
+        contents = contents.replace(/(\n|)<\/(div|h\d|p)>/ig, "\n-----------------------------------------------------------------------------\n");
+    }
+    else {
+        contents = contents.replace(/<\/(div|h\d|p)>/ig, "\n");
+    }
+    
+    // 通常のタグすべてを削除する
+    contents = contents.replace(/<[^>]*>|<\/[^>]*>/ig, "");
+    
+    // 通常のタグ置換後、ニコニコ動画のタグを元に戻す
+    contents = contents.replace(/&lt;externalvideo src=&quot;NC:/g, "<externalvideo src='NC:");
+    contents = contents.replace(/:D&quot;&gt;/, ":D'>");
+    
+    // 半角を置換する
+    contents = contents.replace(/&nbsp;/g, " ");
+    
+    return contents;
+}
+
 /**
  * 選択中の記事を削除します
  * @param {int} index entryListから削除される記事のインデックス