Compare commits
2 Commits
a7b3e3e14b
...
e2f8e8a137
Author | SHA1 | Date |
---|---|---|
Marcus Noble | e2f8e8a137 | |
Marcus Noble | a0963842a6 |
|
@ -26,6 +26,11 @@
|
|||
text-align: center;
|
||||
}
|
||||
|
||||
img {
|
||||
width: max-content;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
input, button {
|
||||
margin: 10px 10px;
|
||||
font-size: 1.8em;
|
||||
|
@ -35,7 +40,7 @@
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>🚀</h1>
|
||||
<img src="rocket.png" />
|
||||
<input type="url" id="URL" />
|
||||
<button id="sendButton">SEND</button>
|
||||
|
||||
|
|
28
index.js
28
index.js
|
@ -17,6 +17,9 @@ const server = http.createServer(async (req, res) => {
|
|||
if (website.toString().endsWith(".pdf")) {
|
||||
fn = sendPDF;
|
||||
}
|
||||
if (website.toString().endsWith(".epub")) {
|
||||
fn = sendEpub;
|
||||
}
|
||||
|
||||
if (await fn(website)) {
|
||||
fs.readFile(__dirname + "/success.html", function (err,data) {
|
||||
|
@ -84,6 +87,25 @@ async function sendPDF(website, tries = 0) {
|
|||
}
|
||||
}
|
||||
|
||||
async function sendEpub(website, tries = 0) {
|
||||
try {
|
||||
const response = await axios.get(website.toString(), {
|
||||
responseType: 'arraybuffer'
|
||||
})
|
||||
const title = website.toString().substring(website.toString().lastIndexOf("/")+1, website.toString().lastIndexOf("."))
|
||||
await sendToRemarkable(title, Buffer.from(response.data, 'binary'), 'epub');
|
||||
|
||||
return true;
|
||||
} catch (ex) {
|
||||
console.log(ex);
|
||||
if (tries < 5) {
|
||||
return await sendEpub(website, ++tries);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function sendPage(website, tries = 0) {
|
||||
const browser = await puppeteer.launch({
|
||||
ignoreHTTPSErrors: true,
|
||||
|
@ -208,7 +230,7 @@ async function sendPage(website, tries = 0) {
|
|||
}
|
||||
}
|
||||
|
||||
async function sendToRemarkable(title, myPDF) {
|
||||
async function sendToRemarkable(title, myPDF, fileType = "pdf") {
|
||||
try {
|
||||
// Refresh token
|
||||
let response = await axios.post(
|
||||
|
@ -257,7 +279,7 @@ async function sendToRemarkable(title, myPDF) {
|
|||
let zip = new JSZip();
|
||||
zip.file(`${ID}.content`, JSON.stringify({
|
||||
extraMetadata: {},
|
||||
fileType: 'pdf',
|
||||
fileType: fileType,
|
||||
lastOpenedPage: 0,
|
||||
lineHeight: -1,
|
||||
margins: 180,
|
||||
|
@ -266,7 +288,7 @@ async function sendToRemarkable(title, myPDF) {
|
|||
transform: {},
|
||||
}));
|
||||
zip.file(`${ID}.pagedata`, []);
|
||||
zip.file(`${ID}.pdf`, myPDF);
|
||||
zip.file(`${ID}.${fileType}`, myPDF);
|
||||
const zipContent = await zip.generateAsync({ type: 'nodebuffer' });
|
||||
|
||||
// Upload zip
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
"name": "Website-to-reMarkable",
|
||||
"short_name": "Website-to-reMarkable",
|
||||
"description": "Send websites as PDFs to reMarkable",
|
||||
"theme_color": "#999",
|
||||
"background_color": "#999",
|
||||
"theme_color": "#e54655",
|
||||
"background_color": "#e54655",
|
||||
"display": "standalone",
|
||||
"scope": "/",
|
||||
"start_url": "/",
|
||||
|
|
BIN
rocket.png
BIN
rocket.png
Binary file not shown.
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 76 KiB |
|
@ -20,10 +20,15 @@
|
|||
padding: 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
img {
|
||||
width: max-content;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>🚀</h1>
|
||||
<img src="rocket.png" />
|
||||
<h2>Sent to reMarkable</h2>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue