UserScript:MyExt
作業中.icon
削除予定
code: script.js
const project = scrapbox.Project.name ;
scrapbox.PageMenu.addMenu({
title: 'suto3ext',
})
// ---
// scrapbox.PageMenu('suto3ext').addSeparator()
code: scriptxx.js
scrapbox.PageMenu('suto3ext').addItem({
title: '🏠go home',
})
scrapbox.PageMenu('suto3ext').addItem({
title: 'go Source',
})
scrapbox.PageMenu('suto3ext').addItem({
title: '🔧settings',
})
code: scriptxx.js
scrapbox.PageMenu('suto3ext').addItem({
title: 'Projects',
onClick: () => {
const url = '/api/projects'
//console.log(url)
fetch(url)
.then(response => response.json())
.then(json => {
console.log(json)
}).catch(err => {
console.error('fetch failed', err)
})
}
})
code: scriptx.js
// scrapbox.PageMenu('suto3ext').addSeparator();
scrapbox.PageMenu('suto3ext').addItem({
title: () => "API-test",
onClick: () => {
const project = scrapbox.Project.name
const report="API-test-" + scrapbox.Project.name
const url =/api/pages/${project}?limit=20
fetch(url)
.then((response) => response.json())
.then((json) => {
// JSONデータを扱った処理など
//console.log(json)
const line= json.pages.map(page =>
+ page.views + "\t"
+ page.created + "\t"
+ page.updated
)
.join('\n')
//console.log(line)
// ページ本文を組み立て
const now = new Date().toLocaleString()
const body =
"Project : + project + "\n"
+ "Date : " + now + "\n\n"
+ "Page Count : " + json.count + "\n\n"
+ "table:" + project + "\n"
+ " title\t views\t created\t updated\n"
+ line
+ "\nEOF\n"
//console.log(body);
// バックアップ用プロジェクトにレポートを作成
window.open(https://scrapbox.io/${backup}/${report}?body=${encodeURIComponent(body)})
}).catch(err => {
console.error('fetch failed', err)
})
}
})
code: scriptx.js
// ページリストをパターンマッチングで拾ってくる API版
// パターンマッチングの対象は、ページタイトルのみ
scrapbox.PageMenu('suto3ext').addItem({
title: 'API-test 2',
onClick: () => {
const project = scrapbox.Project.name
const report="Pattern-" + scrapbox.Project.name
const limit = 1000
let skip = 0
const max = 200 // 最大取得件数
const pat = prompt(
"検索パターンを入力してください\n"
+ "最大 " + max + " 件まで取得します\n"
+ "何も入力しなければキャンセルします"
)
if (pat === undefined || pat === null) return
if (!(0 < pat.length && pat.length < 101)) return
const url =/api/pages/${project}?limit=${limit}&skip=${skip}
fetch(url)
.then((response) => response.json())
.then((json) => {
//console.log(json);
const pagelist = json.pages
.filter(line => line.title.match(pat))
//console.log(pagelist);
if (pagelist.length > max) {
const ret = confirm(
"件数が " + max + " 件を超えています。\n"
+ "続行しますか? (OKで強制続行)"
)
if(!ret) return
}
// ページ本文を組み立て
const now = new Date().toLocaleString()
const body =
"Project : + project + "\n"
+ "Date : " + now + "\n\n"
+ "Pattern : " + pat + "\n\n"
+ "\nEOF\n"
//console.log(body);
// バックアップ用プロジェクトにレポートを作成
window.open(https://scrapbox.io/${backup}/${report}?body=${encodeURIComponent(body)})
}).catch(err => {
console.error('fetch failed', err)
})
}
})
code: scriptxx.js
// ページトップにメモを追記
const mode_id = '__pg_memo__'
const change_css = pat => {
const css =
".page::before {"
+ "content: '" + pat + "';"
+ "display: block;"
+ "border-bottom: 1px solid #bbb;" + "margin-top: 2rem;"
+ "}"
change_style(css)
}
const change_style = css => {
let style = document.getElementById(mode_id)
if (style){ style.remove() }
// console.log(css)
style = document.createElement('style')
style.setAttribute('id', mode_id)
style.appendChild(document.createTextNode(css))
document.head.appendChild(style)
}
scrapbox.PageMenu.addItem({
title: 'ページトップにメモを追記',
onClick: () => {
const pat = prompt(
"メモを入力してください\n"
+ "何も入力しなければキャンセルします"
)
if (pat === undefined || pat === null) return
if (!(0 < pat.length && pat.length < 101)) return
change_css(pat)
}
})
scrapbox.PageMenu.addItem({
title: 'メモを消す',
onClick: () => {
let style = document.getElementById(mode_id)
if (style){ style.remove() }
}
})
code: script.js
scrapbox.PageMenu('suto3ext').addItem({
title: 'Markdown API test',
onClick: () => {
const text = '# Hello, world!'
//window.open(https://api.github.com/markdown/raw?${encodeURIComponent(text)})
}
})
code: script.js
scrapbox.PageMenu('suto3ext').addItem({
title: 'Hello World',
onClick: () => {
/*const d = new Date(Date.now()+9*60*60*1000).toISOString();*/
const d = new Date();
/*window.location.href = https://scrapbox.io/villagepump/${d.slice(0,4)}/${d.slice(5,7)}/${d.slice(8,10)}*/
window.alert(${d.getFullYear()}/${('0'+(d.getMonth()+1)).slice(-2)}/${('0'+d.getDate()).slice(-2)});
}
})
code: script.js
// 多段インポートもできるのか
//import '/api/code/suto3/UserScript:HelloWorld/script.js'
// EOF
UserScript.icon