generated at
scrapboxに特定のページが存在するかどうか確かめる
404 Not Foundかどうかで判定する。

2020-09-17 05:04:59
今いるページと同じproject内を検索するときは、APIではなく/scrapboxlab/scrapbox.Project.pagesを使うようにした。
こっちのほうが早い
2020-09-05 04:35:53
response.okを使って書き換えた

pageExists.js
export async function pageExists(projectName, title) { if(scrapbox && scrapbox.Project.name === projectName) { return scrapbox.Project.pages .find(page => page.title === title && page.exists) !== undefined; } return fetch(`/api/pages/${projectName}/${title}/text`) .then(res => res.ok); }

テスト用

bookmarklet.js
javascript:(()=>{const s=document.createElement("script");s.src='https://scrapbox.io/api/code/takker/scrapboxに特定のページが存在するかどうか確かめる/test.js';document.body.appendChild(s);})()

test.js
javascript:(async () => { async function pageExists(projectName, title) { return fetch(`/api/pages/${projectName}/${title}/text`) .then(res => res.ok); } const isScrapboxPage = document.domain == 'scrapbox.io'; const project_name = 'takker-private'; const title = isScrapboxPage ? scrapbox.Page.title : 'scrapboxに特定のページが存在するかどうか確かめる'; const isExist = await pageExists(project_name,title); window.alert(isExist ? `${title} exists in /${project_name}.` : `${title} dosen't exist in /${project_name}.`); })();

test2.js
javascript:(async () => { async function pageExists(projectName, title) { return fetch(`/api/pages/${projectName}/${title}/text`) .then(res => res.ok); } const isScrapboxPage = document.domain == 'scrapbox.io'; const project_name = 'takker'; const title = isScrapboxPage ? scrapbox.Page.title : 'scrapboxに特定のページが存在するかどうか確かめる'; const isExist = await pageExists(project_name,title); window.alert(isExist ? `${title} exists in /${project_name}.` : `${title} dosen't exist in /${project_name}.`); })();

#2020-10-02 03:36:41
#2020-09-17 05:04:31
#2020-09-06 00:25:06
#2020-09-05 04:35:48
#2020-08-20 02:41:19
#2020-08-19 12:13:04