WhatDateIs.js
by
efcl
2014-02-05 [2014/02/05 23:29:19]
Selecting date text
@@ -1,22 +1,16 @@
/*
- * @title GoogleCalendarParsingDate.js
- * @description Selecting date text to Google Calendar
+ * @title WhatDateis.js
+ * @description Selecting date text
* @include http://*
* @license MIT License
* @require https://raw.github.com/berryboy/chrono/master/chrono.min.js
*/
-(function main() {
+(function(){
var selectText = getSelectingText();
var parsingDates = chrono.parse(selectText);
var dates = buildDate(parsingDates);
- var url = buildURL({
- "text": document.title,
- "details": document.title + " ( " + window.location.href + " )",
- "dates": dates
- });
- openURL(url);
-})();
+ alert(dates);
function openURL(url) {
location.assign(url);
@@ -38,6 +32,7 @@
}
return chronoDates[0];
}
+
function buildDate(chronoDates) {
if (typeof chronoDates === "undefined" || chronoDates.length === 0) {
return;
@@ -48,30 +43,12 @@
if (startDateText && endDateText) {
return startDateText + "/" + endDateText;
} else {
- return startDateText + "/" + startDateText;
+ return startDateText;
}
}
-function format0(str, len) {
- return ('_' + Math.pow(10, len) + str).slice(-len);
-}
function formatDateString(date) {
var TDate = date.getUTCFullYear() + format0(date.getUTCMonth() + 1, 2) + format0(date.getUTCDate(), 2);
var times = format0(date.getUTCHours(), 2) + format0(date.getUTCMinutes(), 2) + format0(date.getUTCSeconds(), 2);
- return TDate + "T" + times + "Z";
-}
-function buildURL(parameters) {
- var action = parameters.action || "TEMPLATE";
- var text = parameters.text || "";
- var details = parameters.details || "";
- var dates = parameters.dates || "";
- var location = parameters.location || window.location.href;
- var url = 'http://www.google.com/calendar/event?' +
- 'action=' + action +
- '&text=' + encodeURIComponent(text) +
- '&details=' + encodeURIComponent(details) +
- '&location=' + encodeURIComponent(location) +
- '&dates=' + dates +
- '&trp=true' +
- '&sprop=website:' + window.location.href;
- return url;
+ return date.getUTCFullYear() + "年" + (date.getUTCMonth() + 1) + "月" + date.getUTCDate() + "日";
}
+})();
/*
* @title WhatDateis.js
* @description Selecting date text
* @include http://*
* @license MIT License
* @require https://raw.github.com/berryboy/chrono/master/chrono.min.js
*/
(function(){
var selectText = getSelectingText();
var parsingDates = chrono.parse(selectText);
var dates = buildDate(parsingDates);
alert(dates);
function openURL(url) {
location.assign(url);
}
function getSelectingText() {
return window.getSelection().toString();
}
function pickupChronoDate(chronoDates) {
if (chronoDates.length == 1) {
return chronoDates[0];
}
for (var i = 0; i < chronoDates.length; i++) {
var chronoDate = chronoDates[i];
if ("startDate" in chronoDate && "endDate" in chronoDate) {
return chronoDate;
}
}
return chronoDates[0];
}
function buildDate(chronoDates) {
if (typeof chronoDates === "undefined" || chronoDates.length === 0) {
return;
}
var chronoDate = pickupChronoDate(chronoDates);
var startDateText = formatDateString(chronoDate.startDate);
var endDateText = chronoDate.endDate ? formatDateString(chronoDate.endDate) : null;
if (startDateText && endDateText) {
return startDateText + "/" + endDateText;
} else {
return startDateText;
}
}
function formatDateString(date) {
var TDate = date.getUTCFullYear() + format0(date.getUTCMonth() + 1, 2) + format0(date.getUTCDate(), 2);
var times = format0(date.getUTCHours(), 2) + format0(date.getUTCMinutes(), 2) + format0(date.getUTCSeconds(), 2);
return date.getUTCFullYear() + "年" + (date.getUTCMonth() + 1) + "月" + date.getUTCDate() + "日";
}
})();
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。