テンプレート
code:週報テンプレート.js
// 週報1週間分のフォーマットを生成する。
(function() {
Date.prototype.setWeek = function(year, week, day) {
var week1 = new Date(year, 0, 1)
var prevLastDay = new Date(week1.getTime() - 86400000 * (week1.getDay() || 7))
console.log(prevLastDay)
return this.setTime(prevLastDay.getTime() + 86400000 * ((week - 1) * 7 + day))
}
Date.prototype.setISOWeek = function(year, week, day) {
var week1 = new Date(year, 0, 4)
var prevLastDay = new Date(week1.getTime() - 86400000 * (week1.getDay() || 7))
console.log(prevLastDay)
return this.setTime(prevLastDay.getTime() + 86400000 * ((week - 1) * 7 + day))
}
Date.prototype.format = function(format) {
// yyyy, MM, dd, ddd だけ
.replace('yyyy', this.getFullYear())
.replace('MM', ('0' + (this.getMonth() + 1)).slice(-2))
.replace('dd', ('0' + this.getDate()).slice(-2))
}
// 処理ここから
const yearWeek = scrapbox.Page.title.split("'") // 新規ページの仮タイトルから、年と週番号を取得して
const d = new Date()
console.log(yearWeek)
// 週番号の計算方法をここで指定するよ
//d.setWeek(yearWeek0, yearWeek1, 0) // 米国式・月曜始まり //d.setWeek(yearWeek0 - 1, yearWeek1, 6) // 米国式・日曜始まり d.setISOWeek(yearWeek0, yearWeek1, 0) // ISO式・月曜始まり //d.setISOWeek(yearWeek0, yearWeek1 - 1, 6) // ISO式・日曜始まり const dateFormat = "yyyy-MM-dd"
const dayFormat = "ddd"
// ここで返してるものがページのタイトルと本文になるよ! 1週間分の日付と曜日を並べていきます
return `
Backlog
`
})()
code:週報テンプレートS.js
(function() {
Date.prototype.setWeek = function(year, week, day) {
var week1 = new Date(year, 0, 1)
var prevLastDay = new Date(week1.getTime() - 86400000 * (week1.getDay() || 7))
return this.setTime(prevLastDay.getTime() + 86400000 * ((week - 1) * 7 + day))
}
Date.prototype.setISOWeek = function(year, week, day) {
var week1 = new Date(year, 0, 4)
var prevLastDay = new Date(week1.getTime() - 86400000 * (week1.getDay() || 7))
return this.setTime(prevLastDay.getTime() + 86400000 * ((week - 1) * 7 + day))
}
Date.prototype.format = function(format) {
// yyyy, MM, dd, ddd だけ
.replace('yyyy', this.getFullYear())
.replace('MM', ('0' + (this.getMonth() + 1)).slice(-2))
.replace('dd', ('0' + this.getDate()).slice(-2))
}
// 処理ここから
const yearWeek = scrapbox.Page.title.split("'") // 新規ページの仮タイトルから、年と週番号を取得して
const d = new Date()
// 週番号の計算方法をここで指定するよ
//d.setWeek(yearWeek0, yearWeek1, 0) // 米国式・月曜始まり //d.setWeek(yearWeek0 - 1, yearWeek1, 6) // 米国式・日曜始まり d.setISOWeek(yearWeek0, yearWeek1, 0) // ISO式・月曜始まり //d.setISOWeek(yearWeek0, yearWeek1 - 1, 6) // ISO式・日曜始まり const dateFormat = "yyyy-MM-dd"
const dayFormat = "ddd"
// ここで返してるものがページのタイトルと本文になるよ! 1週間分の日付と曜日を並べていきます
return `
Backlog
`
})()
code:日誌テンプレート.js
// 日誌用テンプレートを生成する
// {前の日付リンク}→前 次→{次の日付リンク}
function yyyymmdd(date, separator) {
const year = date.getFullYear();
const month = (date.getMonth()+1).toString().padStart(2, "0");
const dt = date.getDate().toString().padStart(2, "0");
return year + separator + month + separator + dt;
}
function makeLink(txt) {
return "+ txt + "";
}
(function (){
// 新規ページの仮タイトルから、年月日を取得
// yyyy/mm/ddな仮タイトルを想定している
const title = scrapbox.Page.title.split(/-//) const baseDate = new Date(title0, title1 - 1, title2); const yesterday = new Date(baseDate.getTime() - 24 * 60 * 60 * 1000);
const tomorrow = new Date(baseDate.getTime() + 24 * 60 * 60 * 1000);
// セパレータを検出
const separator = scrapbox.Page.title.includes("/") ? "/" : "-";
const text = makeLink(yyyymmdd(yesterday, separator)) + "←前 次→" + makeLink(yyyymmdd(tomorrow, separator));
return `
${text}
`
})()
code:ページテンプレート.js
// ページ用のテンプレートを生成する
// Wikipedia形式で参考・関連と分けておくとページが散らかりにくい
/**
* URLのクエリを読めるようにするため特定の文字だけエンコードする
* @param {string} str
* @return {string}
*/
function encode2ReadableQuery(str) {
const specialChars = ' !"#$%&\'()*+,/:;<=>?@[]^`{|}~';
let result = '';
for (let i = 0; i < str.length; i++) {
if (specialChars.indexOf(stri) !== -1) { result += "%" + str.charCodeAt(i).toString(16).padStart(2, "0");
} else {
}
}
return result;
}
/**
* 文字列の先頭のみ大文字に変換
* @param {string} str 対象の文字列
* @return {string} 変換された文字列を返す
*/
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
}
/**
*
* @return {boolean|null}
* true ... OK
* false ... キャンセル
* null ... エラー・禁止?
*/
function safeConfirm(message) {
// confirm が存在しない or 閉じ込められている環境対策
if (typeof window === "undefined" || typeof window.confirm !== "function") {
console.warn("confirm が使えない環境です");
return null;
}
try {
const result = window.confirm(message);
// 仕様上 result は boolean だが、念のため型チェック
if (typeof result !== "boolean") {
console.warn("confirm の戻り値が boolean ではありません:", result);
return null;
}
return result;
} catch (e) {
console.warn("confirm 呼び出しで例外発生:", e);
return null; // confirm が使えないとみなす
}
}
/**
*
*/
function safePrompt(message, defaultValue) {
if (typeof window === "undefined" || typeof window.prompt !== "function") {
console.warn("prompt が使えない環境です");
return null;
}
try {
const value = window.prompt(message, defaultValue);
if (value === null) {
// キャンセル
return null;
}
return value;
} catch (e) {
console.warn("prompt 呼び出しで例外発生:", e);
return null;
}
}
(function (){
try {
if (!window.scrapbox || !scrapbox.Page || !scrapbox.Page.title) {
console.error("scrapbox.Page.title が取得できません");
console.error("# エラー: Scrapbox のページタイトルが取得できませんでした");
return;
}
const title = scrapbox.Page.title.trim();
console.log("raw title:", title);
const result1 = safeConfirm("タイトルは日本語?");
console.log("confirm result:", result1);
let title_ja;
let title_en;
if (result1 === true) {
// 日本語タイトルの場合
title_ja = title;
title_en = safePrompt("英語タイトルを入力", title) || title;
} else if (result1 === false) {
// 日本語じゃない(たぶん英語)
title_en = title;
title_ja = safePrompt("日本語タイトルを入力", title) || title;
} else {
// confirm が使えない or 例外 → フォールバックルート
console.warn("confirm が使えないため、両方のタイトルを個別に入力させます");
title_ja = safePrompt("日本語タイトルを入力", title);
title_en = safePrompt("英語タイトルを入力", title);
if (!title_ja || !title_en) {
// どちらかキャンセルされたら処理中止
console.warn("タイトル入力がキャンセルされたため、テンプレート生成を中止します。");
console.warn("# キャンセル: タイトルが入力されませんでした");
return;
}
}
console.log("title_ja:", title_ja);
console.log("title_en:", title_en);
const title1 = (() => {
if (result1) {
return title_ja + '(' + title_en + ')'
}
return title_en + '(' + title_ja + ')'
})();
const title_underscore_ja = title_ja.replaceAll(/ /g, "_");
const title_underscore_en = title_en.replaceAll(/ /g, "_");
const title_display_en = capitalize(title_en);
const title_plus_ja = title_ja.split(" ").map(encode2ReadableQuery).join("+");
const title_plus_en = title_en.split(" ").map(encode2ReadableQuery).join("+");
const output = `
${title1}
確認用
Q. ${title}
調査用
/pogi-log/Wikipedia.icon
/pogi-log/Wikipedia.icon
`
return output;
} catch (e) {
console.error("テンプレート生成中に例外が発生しました:", e);
return "# エラー: テンプレート生成中に例外が発生しました";
}
})();
code:調査用テンプレート.js
// 調査用のリンクテンプレート
function encodeReadableQuery(str) {
const specialChars = ' !"#$%&\'()*+,/:;<=>?@[]^`{|}~';
let result = '';
for (let i = 0; i < str.length; i++) {
if (specialChars.indexOf(stri) !== -1) { result += "%" + str.charCodeAt(i).toString(16).substring(-2);
} else {
}
}
return result;
}
(function (){
const title = scrapbox.Page.title.split("/")
console.log(title)
const title_underscore = title.join(" ").trim().replaceAll(/ /g, "_")
const title_plus = title.join(" ").trim().map((x) => {
return encodeReadableQuery(x)
}).join("+")
return `
調査用
/pogi-log/Wikipedia.icon
/pogi-log/Wikipedia.icon
`
})()
code:図書館テンプレ.js
// テンプレ挿入(所持のところを自分の名前に)
(function (){
const temp = "著者:\n訳者:\n版元:\n発行年:\n頁数:\n形態:\n流通:\n定価:\n所持:pogin503.icon\n\n#文献";
return `
${temp}
`
})()
code:論文用テンプレ(落合式).js
(function (){
return `
1. どんなもの?
2. 先行研究と比べてどこがすごい?
3. 技術や手法のキモはどこ?
4. どうやって有効だと検証した?
5. 議論はある?
6. 次に読むべき論文は?
確認用
Q.
`
})()