Compare commits
2 Commits
a7b3e3e14b
...
e2f8e8a137
Author | SHA1 | Date | |
---|---|---|---|
e2f8e8a137 | |||
a0963842a6 |
@@ -26,6 +26,11 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: max-content;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
input, button {
|
input, button {
|
||||||
margin: 10px 10px;
|
margin: 10px 10px;
|
||||||
font-size: 1.8em;
|
font-size: 1.8em;
|
||||||
@@ -35,7 +40,7 @@
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>🚀</h1>
|
<img src="rocket.png" />
|
||||||
<input type="url" id="URL" />
|
<input type="url" id="URL" />
|
||||||
<button id="sendButton">SEND</button>
|
<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")) {
|
if (website.toString().endsWith(".pdf")) {
|
||||||
fn = sendPDF;
|
fn = sendPDF;
|
||||||
}
|
}
|
||||||
|
if (website.toString().endsWith(".epub")) {
|
||||||
|
fn = sendEpub;
|
||||||
|
}
|
||||||
|
|
||||||
if (await fn(website)) {
|
if (await fn(website)) {
|
||||||
fs.readFile(__dirname + "/success.html", function (err,data) {
|
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) {
|
async function sendPage(website, tries = 0) {
|
||||||
const browser = await puppeteer.launch({
|
const browser = await puppeteer.launch({
|
||||||
ignoreHTTPSErrors: true,
|
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 {
|
try {
|
||||||
// Refresh token
|
// Refresh token
|
||||||
let response = await axios.post(
|
let response = await axios.post(
|
||||||
@@ -257,7 +279,7 @@ async function sendToRemarkable(title, myPDF) {
|
|||||||
let zip = new JSZip();
|
let zip = new JSZip();
|
||||||
zip.file(`${ID}.content`, JSON.stringify({
|
zip.file(`${ID}.content`, JSON.stringify({
|
||||||
extraMetadata: {},
|
extraMetadata: {},
|
||||||
fileType: 'pdf',
|
fileType: fileType,
|
||||||
lastOpenedPage: 0,
|
lastOpenedPage: 0,
|
||||||
lineHeight: -1,
|
lineHeight: -1,
|
||||||
margins: 180,
|
margins: 180,
|
||||||
@@ -266,7 +288,7 @@ async function sendToRemarkable(title, myPDF) {
|
|||||||
transform: {},
|
transform: {},
|
||||||
}));
|
}));
|
||||||
zip.file(`${ID}.pagedata`, []);
|
zip.file(`${ID}.pagedata`, []);
|
||||||
zip.file(`${ID}.pdf`, myPDF);
|
zip.file(`${ID}.${fileType}`, myPDF);
|
||||||
const zipContent = await zip.generateAsync({ type: 'nodebuffer' });
|
const zipContent = await zip.generateAsync({ type: 'nodebuffer' });
|
||||||
|
|
||||||
// Upload zip
|
// Upload zip
|
||||||
|
@@ -2,8 +2,8 @@
|
|||||||
"name": "Website-to-reMarkable",
|
"name": "Website-to-reMarkable",
|
||||||
"short_name": "Website-to-reMarkable",
|
"short_name": "Website-to-reMarkable",
|
||||||
"description": "Send websites as PDFs to reMarkable",
|
"description": "Send websites as PDFs to reMarkable",
|
||||||
"theme_color": "#999",
|
"theme_color": "#e54655",
|
||||||
"background_color": "#999",
|
"background_color": "#e54655",
|
||||||
"display": "standalone",
|
"display": "standalone",
|
||||||
"scope": "/",
|
"scope": "/",
|
||||||
"start_url": "/",
|
"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;
|
padding: 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: max-content;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>🚀</h1>
|
<img src="rocket.png" />
|
||||||
<h2>Sent to reMarkable</h2>
|
<h2>Sent to reMarkable</h2>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Reference in New Issue
Block a user