Skip to content

Instantly share code, notes, and snippets.

@xyn9
Created November 29, 2009 02:27
Show Gist options
  • Save xyn9/244765 to your computer and use it in GitHub Desktop.
Save xyn9/244765 to your computer and use it in GitHub Desktop.
// wx320k_vcs.js
//
// ==UserScript==
// @name wx320k_vcs
// @version 0.9
// @require printf.js (http://www.onicos.com/staff/iz/amuse/javascript/expert/)
// @description オプションに沿ってVCS形式のスケジュールデータを返す
// @homepage http://gist.github.com/xyn9
//
// @author xyn9 <xyn9.mail@gmail.com>
// @license (CC) Attribution Share Alike; http://creativecommons.org/licenses/by-sa/2.1/jp
// ==UserScript==
//
//
function create_vcs(_args){
//
function fmt(_dt){
var d = new Date(_dt.getTime() -(1000*60*60 *9));
return sprintf(
"%04d%02d%02dT%02d%02d%02dZ"
, d.getFullYear(),(d.getMonth()+1),d.getDate()
, d.getHours(),d.getMinutes(),d.getSeconds()
);
}
// ------------------------------------------------------------
for(var a in _args){
if(typeof _args[a] == 'string'){
_args[a] = (_args[a].replace(/\r\n/g,'\n').match(/^.+$/gm)).join(' ');
}
}
//
if(! _args.DTSTART){ _args.DTSTART = new Date(); }
//
return [
'BEGIN:VCALENDAR'
, 'VERSION:1.0'
, 'BEGIN:VEVENT'
, 'SUMMARY:'+ _args.SUMMARY
, 'CATEGORIES:PERSONAL'
, 'X-WX310K-CATEGORIES:PERSONAL'
, 'DTSTART:' + fmt(_args.DTSTART)
, 'DTEND:' + fmt(
(_args.DTEND && (_args.DTEND.getTime() > _args.DTSTART.getTime()))
? _args.DTEND : _args.DTSTART
)
, 'AALARM:' + (_args.AALARM ? fmt(_args.AALARM) : '')
, 'X-WX310K-ALARMTONE:' + (_args.ATONE ? _args.ATONE : '07')
, 'LOCATION:' + (_args.LOCATION ? _args.LOCATION : '')
, 'DESCRIPTION:' + (_args.DESCRIPTION ? _args.DESCRIPTION : '')
, 'URL:' + (_args.URL ? _args.URL : '')
, 'CLASS:PUBLIC'
, 'END:VEVENT'
, 'END:VCALENDAR'
, ''
].join('\r\n')
;
}
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment