platypush-ext-save-link.js
· 1.5 KiB · JavaScript
Raw
/**
* A script for the Platypush browser extension that saves the current page URL to Wallabag.
* Use together with the Reader Mode script https://gist.manganiello.tech/fabio/c731b57ff6b24d21a8f43fbedde3dc30 for best results.
*/
// Entry point for the script, which is executed when the user runs the
// associated action. All the logic should be encapsulated in this function.
async (app, args) => {
// (Optional) topic for the ntfy notification
const ntfyTopic = 'notebook-saved-links-random-suffix';
// Get the page URL and DOM
const url = await app.getURL();
const dom = await app.getDOM();
const getContent = () => {
// Check if the current DOM has already been "distilled" by the Mercury script.
// If that's the case, use the already distilled content as the body of the saved article.
const simplifiedContainer = dom.querySelector('.platypush__simplified-body');
return (simplifiedContainer || dom.querySelector('body')).innerHTML;
};
// Save the URL to Wallabag leveraging the Platypush API
const title = dom.querySelector('head title')?.innerText;
const response = await app.run({
action: 'wallabag.save',
args: {
url: url,
title: title,
content: getContent(),
}
}, args.host);
/*
// Optional: Send a notification via ntfy
await app.run({
action: 'ntfy.send_message',
args: {
topic: ntfyTopic,
message: response.title || title,
title: 'URL saved to Wallabag',
url: url,
}
}, args.host);
*/
}
1 | /** |
2 | * A script for the Platypush browser extension that saves the current page URL to Wallabag. |
3 | * Use together with the Reader Mode script https://gist.manganiello.tech/fabio/c731b57ff6b24d21a8f43fbedde3dc30 for best results. |
4 | */ |
5 | |
6 | |
7 | // Entry point for the script, which is executed when the user runs the |
8 | // associated action. All the logic should be encapsulated in this function. |
9 | async (app, args) => { |
10 | // (Optional) topic for the ntfy notification |
11 | const ntfyTopic = 'notebook-saved-links-random-suffix'; |
12 | |
13 | // Get the page URL and DOM |
14 | const url = await app.getURL(); |
15 | const dom = await app.getDOM(); |
16 | const getContent = () => { |
17 | // Check if the current DOM has already been "distilled" by the Mercury script. |
18 | // If that's the case, use the already distilled content as the body of the saved article. |
19 | const simplifiedContainer = dom.querySelector('.platypush__simplified-body'); |
20 | return (simplifiedContainer || dom.querySelector('body')).innerHTML; |
21 | }; |
22 | |
23 | // Save the URL to Wallabag leveraging the Platypush API |
24 | const title = dom.querySelector('head title')?.innerText; |
25 | const response = await app.run({ |
26 | action: 'wallabag.save', |
27 | args: { |
28 | url: url, |
29 | title: title, |
30 | content: getContent(), |
31 | } |
32 | }, args.host); |
33 | |
34 | /* |
35 | // Optional: Send a notification via ntfy |
36 | await app.run({ |
37 | action: 'ntfy.send_message', |
38 | args: { |
39 | topic: ntfyTopic, |
40 | message: response.title || title, |
41 | title: 'URL saved to Wallabag', |
42 | url: url, |
43 | } |
44 | }, args.host); |
45 | */ |
46 | } |