Created
May 17, 2020 09:54
-
-
Save vitalibondar/b40679c8ef7afcac7cb1a90715f9cf72 to your computer and use it in GitHub Desktop.
А так?
const diffDate = (date, diff) => {
// date: '1993-09-11'
// diff: +1, -1
date.setDate(date.getDate() + diff);
const a = [
date.getFullYear(),
('00' + (1 + date.getMonth())).slice(-2),
('00' + date.getDate()).slice(-2),
];
console.log(a);
return a.join('-');
};
const main = function() {
const days = [
'неділя',
'понеділок',
'вівторок',
'середа',
'четвер',
'пʼятниця',
'субота',
];
const monthNames = [
'січень',
'лютий',
'березень',
'квітень',
'травень',
'червень',
'липень',
'серпень',
'вересень',
'жовтень',
'листопад',
'грудень',
]; //масив з локалізованими місяцями
const dateHandling = () => {
const askDate = prompt('Enter date: ', 'YYYYMMDD or YYYY MM DD');
if (askDate === null) return new Date();
const dates = (str) => {
const year = str.slice(0, 4);
const month = str.slice(4, 6) - 1;
const day = str.slice(6, 8);
return [year, month, day];
};
if (askDate.match(/\d{8}/)) {
return new Date(...dates(askDate));
}
if (askDate.match(/[0-9]{4}(([-:\s])[0-9]{2}){2}/)) {
const match = /[0-9]{4}(([-:\s])[0-9]{2}){2}/.exec(askDate);
const dateString = askDate.split(match[2]).join('');
return new Date(...dates(dateString));
}
return new Date();
};
const d = dateHandling();
const year = d.getFullYear();
const dt = d.getDate();
const month = d.getMonth() + 1;
const date = [year, ('00' + month).slice(-2), ('00' + dt).slice(-2)];
const day = days[d.getDay()];
/****** 編集エリア ******/
// お好きなタイトル
const title = date.join('-');
console.log(title)
// var monthLocal = date.toLocaleString('uk-UA', { month: 'long' }); //не працює
/************************/
const scrapboxProject = location.href.match(/scrapbox.io\/([^\/.]*)/)[1];
const projectUrl = 'https://scrapbox.io/' + scrapboxProject + '/';
const tags = [
'[← ' + projectUrl + encodeURIComponent(diffDate(d, -1)) + ']',
'[' + year + ' рік' + ']' + ',',
// '[' + month + '-й місяць' + ']' + ',',
'[' + monthNames[d.getMonth()] + ']' + ',',
// '[' + monthLocal + ']' + ',', //не працює
'[' + day + '' + ']',
'[→ ' + projectUrl + encodeURIComponent(diffDate(d, +1)) + ']',
];
/****** 編集エリア ******/
// お好きなハッシュタグまたは本文
const body = encodeURIComponent(
'[* Справи:]' +
'\n' +
'[* Що сталося за день:]' +
'\n' +
'[* Цікаві думки та ідеї:]' +
'\n' +
tags.join(' ') +
'\n' +
'#Щоденник'
);
/************************/
const scrapboxUrl =
'https://scrapbox.io/' + scrapboxProject + '/' + encodeURIComponent(title);
window.open(scrapboxUrl + '?body=' + body);
};
main();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Попробуй вот так: