scrapboxに特定のページが存在するかどうか確かめる
2020-09-17 05:04:59
こっちのほうが早い
2020-09-05 04:35:53
code: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);
}
テスト用
code:bookmarklet.js
code: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}.);
})();
code: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}.);
})();