amazonの商品へのリンクを貼るのが面倒だなぁ……
と思ったので、Windows Live Writerのプラグインの作成に挑戦してみました。
すぐに手順を忘れてしまいそうなので、ざっくりと書き残しておきます。
- クラスライブラリのプロジェクトを新規作成
- Windows Live Writerをインストールしたフォルダ(僕の場合C:\Program Files\Windows Live\Writerでした)にある、WindowsLive.Writer.Api.dllを参照させる。
- Class1にContentSourceを継承させる
- CreateContent()をオーバーライド
- string contentへhtml文を挿入する。
- ビルドして出来たアセンブリを、Windows Live Writerをインストールしたフォルダの直下にあるPluginsフォルダ(僕の場合C:\Program Files\Windows Live\Writer\Pluginsでした)へコピーする。
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using WindowsLive.Writer.Api;
namespace amazonInsert
{
[WriterPlugin("{63491BAF-A37A-4167-AEE7-E261CF453F83}", "amazonリンク")]
[InsertableContentSource("amazonリンク")]
public class Class1 : ContentSource
{
public override System.Windows.Forms.DialogResult CreateContent(System.Windows.Forms.IWin32Window dialogOwner, ref string content)
{
//フォームを表示してASINを入力させる
Form1 form = new Form1();
DialogResult dr = form.ShowDialog();
if (dr == DialogResult.OK)
{
string asin = form.asin;
string id = "sakunekonikki-22";
string text = "";
//てきとーにhtml文をこしらえる
text += "<";
text += "iframe src=\"http://rcm-jp.amazon.co.jp/e/cm?t=";
text += id;
text += "&o=9&p=8&l=as1&asins=";
text += asin;
text += "&fc1=000000&IS2=1<1=_blank&";
text += "lc1=0000FF&bc1=000000&bg1=FFFFFF&f=ifr\"";
text += "style=\"width:120px;height:240px;\" ";
text += "scrolling=\"no\" marginwidth=\"0\" ";
text += "marginheight=\"0\" frameborder=\"0\">";
text += "<";
text += "/iframe>";
content = text;
}
form.Dispose();
return dr;
}
}
}
自分の作成したプラグインがちゃんと表示されて
選択するとASIN入力フォームが表示されて、
ASINを入力してOKを押すと、商品がちゃんと表示される。
僕でも簡単にプラグインを作ることが出来ましたヽ(゚∀゚)メ(゚∀゚)メ(゚∀゚)ノ