(public)

  • Code to import into Scrapbox using puppeteer

  • Requires node.js

  • Run it by setting the sid as shown in /ras/NodeでPrivateなscrapboxの情報を取得する

  • It currently works at a basic level

    • The JavaScript code is written in a rough manner for now
    • There are mixed uses of $ and $x which will be fixed later
  • It seems that pages opened in another browser while the import is running will not be overwritten?

    • No, that’s not the case.
  • Does it matter if the browser is closed when it says “Importing Pages…“?

    • No, that’s not the case either.
  • Copying pages that didn’t exist originally seems to work fine every time, but overwriting existing pages doesn’t always work properly.

    • The conditions for this are unknown…

.js

const puppeteer = require('puppeteer');
 
const sid = "YOUR SID";
const project = "experiment-blu3mo";
 
(async () => {
    const url = new URL(`https://scrapbox.io/projects/${project}/settings/page-data`);
    const browser = await puppeteer.launch({
        args: ['--no-sandbox', '--disable-setuid-sandbox'],
        defaultViewport: {width: 800, height: 1024}
    });
    const page = await browser.newPage();
 
    await page.setCookie({name: 'connect.sid', value: sid, domain: 'scrapbox.io'});
    await page.goto(url.toString());
    await page.waitFor(1000);
    
    const inputUploadHandle = await page.$('input[name="import-file"]');
    inputUploadHandle.uploadFile("FILE.json");
    await page.waitFor(1000);
 
    const importSubmitButton = await page.$x("//button[contains(., 'Import Pages')]");
    await importSubmitButton[0].click();
 
    await browser.close();
})()