Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save selection feature #82

Open
patchhg opened this issue Apr 10, 2024 · 1 comment
Open

Save selection feature #82

patchhg opened this issue Apr 10, 2024 · 1 comment

Comments

@patchhg
Copy link

patchhg commented Apr 10, 2024

First of all, thank you so much for all your great work on SingleFile over the years. It is such a great tool for storing technical articles to my knowledge base rather than having a million links that randomly go offline or saving screenshots which contain code snippets. Some of the articles I've saved are no longer available on wayback machine even.

I need to save a bunch of articles from medium and was hoping there was a way I could automate this using singlefile CLI. Unfortunately, I can't find any CLI arguments to save a page selection in the same way the SingleFile extension works.

Do you have any suggestions for implementing this? I was thinking of having a script after page load which manually removes the unnecessary DOM elements but this is not ideal. Is there a better way to emulate the behavior of the browser extension?

In case you deem it relevant, perhaps this might also be a good idea for a feature request.

@gildas-lormeau
Copy link
Owner

gildas-lormeau commented Apr 10, 2024

You can run a script when saving a page with the --browser-script. The problem, particularly on Medium, is that writing such a script in a reliable way may be complicated. For example, on Medium, all the elements have minified class names (see HTML below) that are not guaranteed to be constant.

...
<div class="ui t uj v uk ul um un uo up ab q cn fi">
    <div class="uq ur us ut uu l">
        <div class="am l fr uv uw">
            <div class="h k">
                <div class="l fi n ux">
                    <button class="af ag ah ai aj ak al am an ao ap aq ar as at ab" data-testid="close-button" aria-label="close">
                    ...
                </div>
            </div>
        </div>
    </div>
</div>
...

If by any chance you're interested in removing the bottom banner, you could run ./single-file --browser-script=medium-script.js "https://medium.com/..." with the script below. Note that it tries to work in a generic way, without relying on class names.

medium-script.js

onload = () => {
	const elements = document.querySelectorAll("*");
	elements.forEach(element => {
		if (!element.ariaHidden) {
			const style = getComputedStyle(element);
			if (style.position == "fixed") {
				element.remove();
			}
		}
	});
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants