ページ作成のショートカットを作る
week
作成済み
ctrl shift wでopen
バグが多すぎるのでscrapboxで使うことにした
code:week.js
// ボタンを押すと今週か来週か聞かれ、答えた方をクリップボードに保存する
function getDateRange(daysAgo = 0) {
const today = new Date();
today.setDate(today.getDate() - daysAgo + 1);
today.setDate(today.getDate() - today.getDay() + 1)
const year = today.getFullYear();
const month = 00${today.getMonth() + 1}.slice(-2)
const startDay = 00${today.getDate() - today.getDay() + 1}.slice(-2)
today.setDate(today.getDate() + 6)
const endDay = 00${today.getDate() - today.getDay()}.slice(-2)
return ${year}-${month}@${startDay}-${endDay};
}
function getNextSevenDaysArray(daysAgo = 0) {
const mondayDate = new Date();
mondayDate.setDate(mondayDate.getDate() - daysAgo + 1);
mondayDate.setDate(mondayDate.getDate() - mondayDate.getDay() + 1)
const datesArray = [];
for (let i = 0; i < 7; i++) {
const futureDate = new Date(mondayDate.getTime());
futureDate.setDate(mondayDate.getDate() + i);
const formattedDate = futureDate.getDate().toString().padStart(2, '0'); // DD形式
datesArray.push(formattedDate);
}
return datesArray;
}
async function fetchAndFormatCsv(daysAgo = 0) {
const formattedDate = getDateRange(daysAgo + 7);
return fetch(https://scrapbox.io/api/table/wogikaze-study/${formattedDate}/勉強時間.csv)
.then(response => response.text())
.then(data => {
const lines = data.split("\n");
const formattedLines = lines.map(line => line.split(",").join("\t"));
const headerLength = formattedLines0.split("\t").length; formattedLines.push(${getDateRange(daysAgo)}\t);
return formattedLines;
})
.catch(error => {
console.error('エラー:', error);
return [];
});
}
export async function copy_week_page() {
var result = prompt(
`-1:${getDateRange(7)}
0:${getDateRange(0)}
1:${getDateRange(-7)}
2:${getDateRange(-14)}`, '1');
var daysAgo;
if (result) {
daysAgo = parseInt(result) * -7;
} else {
return;
}
let content = [];
let formattedTable = await fetchAndFormatCsv(daysAgo)
content = [
"",
"",
"目標",
"",
getNextSevenDaysArray(daysAgo).join("\n"),
"",
"振り返り",
"",
"table:勉強時間",
\t${formattedTable.join("\n\t")},
""
].join("\n");
console.log(content);
const copyContent = () => {
navigator.clipboard.writeText(content).then(function () {
console.log('Copying to clipboard was successful!');
}, function (err) {
console.error('Could not copy text: ', err);
});
}
setTimeout(() => { copyContent() }, 1000)
}
month
1
code:month.js
export function copy_month_page() {
const yearString = (past = 0, date = new Date()) => {
const month = new Date(date.getFullYear(), date.getMonth() + past, 1);
return ${month.getFullYear()}-${String(month.getMonth() + 1).padStart(2, '0')};
}
const aprilMondays = getMondays();
const page_format = `${yearString()}
table:週目標
\t\t現文\t古典\t英語\t数学\t化学\t物理\t地理
`
navigator.clipboard.writeText(page_format).then(function () {
console.log('Copying to clipboard was successful!');
}, function (err) {
console.error('Could not copy text: ', err);
});
}
export function copy_month_page_for_test() {
const yearString = (past = 0, date = new Date()) => {
const month = new Date(date.getFullYear(), date.getMonth() + past, 1);
return ${month.getFullYear()}-${String(month.getMonth() + 1).padStart(2, '0')};
}
const aprilMondays = getMondays();
const page_format = `${yearString()}
`
navigator.clipboard.writeText(page_format).then(function () {
console.log('Copying to clipboard was successful!');
}, function (err) {
console.error('Could not copy text: ', err);
});
}
function getMondays() {
const currentDate = new Date();
const currentYear = currentDate.getFullYear();
const currentMonth = currentDate.getMonth();
const mondays = [];
// 最初の月曜日を取得
let firstMondayInMonth = new Date(currentYear, currentMonth, 1); // 現在の月の1日
while (firstMondayInMonth.getDay() !== 1) {
firstMondayInMonth.setDate(firstMondayInMonth.getDate() + 1);
}
// 最後の月曜日を取得
let lastMondayInMonth = new Date(currentYear, currentMonth + 1, 0); // 次の月の0日 = 現在の月の最終日
while (lastMondayInMonth.getDay() !== 1) {
lastMondayInMonth.setDate(lastMondayInMonth.getDate() - 1);
}
// 月曜日を列挙
let currentMonday = firstMondayInMonth;
while (currentMonday <= lastMondayInMonth) {
const daysAgo = Math.ceil((currentDate - currentMonday) / (1000 * 60 * 60 * 24));
const dateRange = getDateRange(daysAgo);
mondays.push(dateRange);
currentMonday.setDate(currentMonday.getDate() + 7);
}
return mondays;
}
function getDateRange(daysAgo = 0) {
const today = new Date();
today.setDate(today.getDate() - daysAgo + 1);
today.setDate(today.getDate() - today.getDay() + 1)
const year = today.getFullYear();
const month = 00${today.getMonth() + 1}.slice(-2)
const startDay = 00${today.getDate() - today.getDay() + 1}.slice(-2)
today.setDate(today.getDate() + 6)
const endDay = 00${today.getDate() - today.getDay()}.slice(-2)
return ${year}-${month}@${startDay}-${endDay};
}
作業室
これはコピペでいい気がする
違う、これは井戸端でやるべき