script.jsexport async function search(query, projects) {
// project idを取得する
let ids = await Promise.all(projects.map(async project => {
const res = await fetch(`/api/projects/${project}`);
if (!res.ok) return;
const {id} = await res.json();
return id;
}));
script.js const joinedIds = await (async () => {
const res = await fetch('/api/projects');
if (!res.ok) return [];
const {projects} = await res.json();
return projects?.map?.(({id}) => id) ?? [];
})();
ids = ids.filter(id => id && !joinedIds.some(joinedId => joinedId === id));
script.js // 横断検索する
const res = await fetch(`/api/projects/search/watch-list?q=${encodeURIComponent(query)}${ids.flatMap(id => id ? [`&ids=${id}`] : []).join('')}`);
return await res.json();
}
js(async () =>
const {execute} = await import('/api/code/programming-notes/任意のprojectを横断検索するUserScript/test1.js');
console.log(await execute('scrapbox'));
})();
test1.jsimport {search} from './script.js';
import {projects} from './project-list.js';
export const execute = (query) => search(query, projects);
project-list.jsexport const projects = [
'hub',
'shokai',
'nishio',
'masui',
'rakusai',
'yuiseki',
'june29',
'ucdktr2016',
'villagepump',
'rashitamemo',
'thinkandcreateteck',
'customize',
'scrapboxlab',
'scrasobox',
'foldrr',
'scrapbox-drinkup',
'motoso',
'public-mrsekut',
'mrsekut-p',
'marshmallow-rm',
'wkpmm',
'sushitecture',
'nwtgck',
'dojineko',
'kadoyau',
'inteltank',
'sta',
'kn1cht',
'miyamonz',
'rmaruon',
'MISONLN41',
'yuta0801',
'choiyakiBox',
'choiyaki-hondana',
'spud-oimo',
'keroxp',
'aioilight',
'takker',
'programming-notes',
];