rescrap
code:script.js
const projects = new Promise((resolve, reject) => {
.then(response => response.json())
.then(json => json.projects)
.then(resolve)
.catch(reject)
})
const rescrap = project => {
const { title, lines } = scrapbox.Page
const body = lines.reduce((acc, { text }) => ${acc}\n${text}, '').trim() + \n\nfrom [/${scrapbox.Project.name}/${title}]\n
const link = https://scrapbox.io/${encodeURIComponent(project)}/new?body=${encodeURIComponent(body)}
console.log(body)
window.open(link, '_blank', 'noopener')
}
const rescrapProjectFilterInput = document.createElement('input')
rescrapProjectFilterInput.type = 'text'
rescrapProjectFilterInput.id = 'rescrap-filtering-input'
rescrapProjectFilterInput.addEventListener('input', async e => {
scrapbox.PageMenu('re-scrap').removeAllItems()
const query = rescrapProjectFilterInput.value.toLowerCase()
for (const { name, displayName } of await projects) {
if (!name.toLowerCase().includes(query) && !displayName.toLowerCase().includes(query)) continue
scrapbox.PageMenu('re-scrap').addItem({
title: displayName,
onClick: () => { rescrap(name) }
})
}
})
scrapbox.PageMenu.addMenu({
title: 're-scrap',
onClick: async () => {
scrapbox.PageMenu('re-scrap').addItem({ title: 'Now loading...', onClick: () => null })
await projects
scrapbox.PageMenu('re-scrap').removeAllItems()
for (const { name, displayName } of await projects) {
scrapbox.PageMenu('re-scrap').addItem({
title: displayName,
onClick: () => { rescrap(name) }
})
}
rescrapProjectFilterInput.value = ''
ul.prepend(rescrapProjectFilterInput)
rescrapProjectFilterInput.focus()
}
})
code:style.css
width: 300px;
text-overflow: ellipsis;
display: list-item;
}