scrapboxに特定のページが存在するかどうか確かめる
2020-09-17 05:04:59
こっちのほうが早い
2020-09-05 04:35:53
pageExists.jsexport 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.jsjavascript:(()=>{const s=document.createElement("script");s.src='https://scrapbox.io/api/code/takker/scrapboxに特定のページが存在するかどうか確かめる/test.js';document.body.appendChild(s);})()
test.jsjavascript:(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.jsjavascript:(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}.`);
})();