LoginSignup
3
3

More than 5 years have passed since last update.

Group Sessionの予定をGoogle カレンダーにCSVインポートできる形でコピーするブックマークレット

Posted at

Group Sessionの予定を、Google カレンダーに入力したい

javascriptでGroupSessionページ内を読み取って、Googleカレンダーに、CSVインポートできる形でコピーできるようにした

動作確認

IE/Chrome
FireFoxはdocument.writeできなくてあきらめた、、

使い方

  1. ブックマークレットに登録
  2. GroupSessionでスケジュールの月画面を開く
  3. ブックマークレットをクリックして実行
  4. IEと、Chromeで動作が異なります
    IE:クリップボードにデータがコピーされます
    Chrome:ポップアップがあがり、そこでCtrl+Cでコピーすることで、クリップボードにデータがコピーされます

  5. 適当なエディタに貼り付け、拡張子をcsvとして保存します

  6. Googleカレンダーの右側、他のカレンダーの▽をクリックし、インポートします

制限

終日の予定は取り込めません(うまく日付がとれない)
月以外だったら、等のエラーハンドリング一切ありません

ブックマークレット

うまい共有方法がわからず、、ブックマークの編集にて、下の内容を貼り付けてみてください

js
javascript:(function(){var r = window.clipboardData?"\r\n":"\\r\\n";var datere = new RegExp("[0-9]{8}");var descre = new RegExp("^%E5%86%85%E5%AE%B9:(.+)");var csvdata = "Subject,Start Date,Start Time,End Date,End Time,Description" + r;body.$("a[id^='tooltips_sch']").each(function(){var $timefont = body.$(this).children().children("font");if($timefont.text()){var time, sub, datebase, date, desc;sub = body.$(this).clone().children("span:not(.sc_link_g)").children().remove().end().text().trim();datebase = datere.exec(body.$(this).attr("onclick"))[0];date = datebase.substr(0,4) + "/" + datebase.substr(4,2) + "/" + datebase.slice(-2);time = $timefont.text().trim();desc = descre.test(this.tooltipText)?descre.exec(this.tooltipText)[1]:"";csvdata += sub + "," + date + "," + time.split("-")[0] + "," + date +"," + time.split("-")[1] +"," +desc + r;}});if(window.clipboardData){window.clipboardData.setData("Text", csvdata);}else{var w=444;var h=100;var l=Number((window.screen.width-w)/2);var t=Number((window.screen.height-h)/2);nwin = window.open("", "gscalenderexporter", "width="+w+" height="+h+", left="+l+", top="+t);nwin.document.write("<HTML><HEAD>");nwin.document.write("<TITLE>gscalenderexporter</TITLE>");nwin.document.write("<script>document.oncopy=function(event){event.preventDefault();event.clipboardData.setData('text', '" + csvdata +"');window.close();};</script>");nwin.document.write("</HEAD><BODY style='background-color: #34495E;'>");nwin.document.write("<span style='color: white;font-size: 15px;font-weight: bold;'>[Ctrl%EF%BC%8BC]%E3%81%99%E3%82%8B%E3%81%A8%E3%80%81%E3%82%AF%E3%83%AA%E3%83%83%E3%83%97%E3%83%9C%E3%83%BC%E3%83%89%E3%81%AB%E3%83%87%E3%83%BC%E3%82%BF%E3%81%8C%E3%82%B3%E3%83%94%E3%83%BC%E3%81%95%E3%82%8C%E3%81%BE%E3%81%99%E3%80%82</span>");nwin.document.write("</BODY></HTML>");nwin.document.close();nwin.focus();}})();

ソース

var r = window.clipboardData?"\r\n":"\\r\\n";
var datere = new RegExp("[0-9]{8}");
var descre = new RegExp("^内容:(.+)");
var csvdata = "Subject,Start Date,Start Time,End Date,End Time,Description" + r;
body.$("a[id^='tooltips_sch']").each(
    function(){
        var $timefont = body.$(this).children().children("font");
        if($timefont.text()){
            var time, sub, datebase, date, desc;
            sub = body.$(this).clone().children("span:not(.sc_link_g)").children().remove().end().text().trim();
            datebase = datere.exec(body.$(this).attr("onclick"))[0];
            date = datebase.substr(0,4) + "/" + datebase.substr(4,2) + "/" + datebase.slice(-2);
            time = $timefont.text().trim();
            desc = descre.test(this.tooltipText)?descre.exec(this.tooltipText)[1]:"";
            csvdata += sub + "," + date + "," + time.split("-")[0] + "," + date +"," + time.split("-")[1] +"," +desc + r;
        }
    }
);
if(window.clipboardData){
    window.clipboardData.setData("Text", csvdata);
}else{
    var w=444;
    var h=100;
    var l=Number((window.screen.width-w)/2);
    var t=Number((window.screen.height-h)/2);
    nwin = window.open("", "gscalenderexporter", "width="+w+" height="+h+", left="+l+", top="+t);
    nwin.document.write("<HTML><HEAD>");
    nwin.document.write("<TITLE>gscalenderexporter</TITLE>");
    nwin.document.write("<script>document.oncopy=function(event){event.preventDefault();event.clipboardData.setData('text', '" + csvdata +"');window.close();};</script>");
    nwin.document.write("</HEAD><BODY style='background-color: #34495E;'>");
    nwin.document.write("<span style='color: white;font-size: 15px;font-weight: bold;'>[Ctrl+C]すると、クリップボードにデータがコピーされます。</span>");
    nwin.document.write("</BODY></HTML>");
    nwin.document.close();
    nwin.focus();
}

直したいこと

  • FireFox対応
  • 終日予定への対応
  • ラベル色の反映(なにか頭につける?)
  • 一覧画面への対応
  • コピーの挙動(Flash使わなくてはむり?)
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3