2009年9月30日水曜日

ATNDのイベントをGoogle Clendarに登録するGreasemonkeyスクリプト b

探せばもうありそうな気もするけど、ほしいなと思ったので書いてみた。

インストール


Firefox アドオンのGreasemonkeyがすでに導入済みならば、
ここをクリックして、スクリプトをインストールできます。

ソース


最終更新:2009/10/05 01:04
ボタンが表示されない場合があるのを修正しました。
やっつけ仕事。
// ==UserScript==
// @name atnd2gcal
// @version 1.3
// @namespace http://tbl.jp
// @description author: takabow
// @include http://atnd.org/events/*
// ==/UserScript==

(function() {
var xpathTitle = "id('main_title')/h1";
var xpathMemberList1 = "//div[@class='side_member_num']"
var xpathMemberList2 = "id('member_list')";
var xpathDate= "id('events_show_contents')/div/dl[1]/dd/abbr/@title";
var xpathPlace= "id('events_show_contents')/div/dl[3]/dd[@class='location']";
var title = document.evaluate(xpathTitle ,document,null,7,null).snapshotItem(0).firstChild.data;
var eventDiv = document.evaluate(xpathMemberList1 ,document,null,7,null);
if(!eventDiv.snapshotItem(0)) {
eventDiv = document.evaluate(xpathMemberList2 ,document,null,7,null);
}
var abbr1 = document.evaluate(xpathDate ,document,null,7,null);
var abbr2 = document.evaluate(xpathPlace ,document,null,7,null);
var startDate = abbr1.snapshotItem(0).firstChild.data;
var endDate = startDate;
if(abbr1.snapshotItem(1)) {
endDate = abbr1.snapshotItem(1).firstChild.data;
}
var place = abbr2.snapshotItem(0);
var place1 = place.firstChild.data;
if(place.childNodes[1]) {
place1 += place.childNodes[1].firstChild.data;
}
var gcalURL = document.createElement('a');
var gcalp = document.createElement('p');
var gcalImg = document.createElement('img');
gcalImg.src = 'http://www.google.com/calendar/images/ext/gc_button2_ja.gif';
gcalImg.alt = "このイベントをGoogle Calendarに登録";
gcalURL.href = 'http://www.google.com/calendar/event?action=TEMPLATE&dates=' + startDate + "/" + endDate + '&location=' + encodeURIComponent(place1) + '&text=' + encodeURIComponent(title) + '&details=' + document.URL;
gcalURL.appendChild(gcalImg);
gcalp.appendChild(gcalURL);
eventDiv.snapshotItem(0).appendChild(gcalp);
})();