Git Product home page Git Product logo

Comments (2)

gildas-lormeau avatar gildas-lormeau commented on June 26, 2024

Thank you for the suggestion. I'll have to think about it. The problem from my point of view is that if it's an option then the user risks creating a lot of profiles or changing the value of this option very often.

An interesting alternative for this use case is integration with userscripts. By enabling the hidden option userScriptEnabled, see https://github.com/gildas-lormeau/SingleFile/wiki/Hidden-options, you can create a simple userscript that will be adapted to the page to be saved.

Here is below an example of such a script which is designed to save pages on "Le Monde" as https://www.lemonde.fr/international/article/2024/02/20/julian-assange-tente-d-obtenir-un-dernier-recours-contre-son-extradition-vers-les-etats-unis_6217460_3210.html

// ==UserScript==
// @name         New Userscript
// @version      2024-02-20
// @author       Gildas
// @match        https://www.lemonde.fr/international/article/*
// @grant        none
// ==/UserScript==

(() => {
    "use strict";

    dispatchEvent(new CustomEvent("single-file-user-script-init"));

    addEventListener("single-file-on-before-capture-request", () => {
        const element = document.querySelector(".zone--article");
        isolateElement(element);
    });

    function isolateElement(element) {
        const parentNode = element.parentNode;
        Array.from(parentNode.childNodes).forEach(node => {
            if (node != element) {
                node.remove();
            }
        });
        if (parentNode != document.body) {
            isolateElement(parentNode);
        }
    }
})();

from singlefile.

frkd-dev avatar frkd-dev commented on June 26, 2024

I had an idea of using user scripts to prepare the page once I click a button, but custom events from a SingeFile are even better as no extra steps are required! I wasn't aware of custom events and hidden options. This will close my needs for now. Thanks for sharing! 👍

Regarding the script: where can I read why the extension needs a dispatchEvent() from the user script?

UPD: found the answer here.

from singlefile.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.