GithubHelp home page GithubHelp logo

johnwang1023 / trilium-web-clipper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zadam/trilium-web-clipper

0.0 0.0 0.0 138 KB

Save web clippings to Trilium Notes.

JavaScript 95.10% Shell 1.78% HTML 2.71% CSS 0.41%

trilium-web-clipper's Introduction

ClipperHTML

const template = `
<script>
    var iframe = document.getElementById('r-iframe');
    function pageY(elem) {
        return elem.offsetParent ? (elem.offsetTop + pageY(elem.offsetParent)) : elem.offsetTop;
    }
    function resizeIframe() {
        var height = document.documentElement.clientHeight;
        height -= pageY(iframe) + 20 ;
        height = (height < 0) ? 0 : height;
        iframe.style.height = height + 'px';
    }
    iframe.onload = resizeIframe;
    window.onresize = resizeIframe;
</script>
<iframe id="r-iframe" style="width:100%" src="data:text/html;charset=utf-8,%%CONTENT%%" sandbox=""></iframe>
`;

const {req, res} = api;
const {title, url, content} = req.body;

if (req.method == 'POST') {
    api.log("==========================");

    //const todayNote = await api.getDateNote(today);
    const todayNote = await api.getTodayNote();
    
    // create render note
    const renderNote = (await api.createNewNote({
        parentNoteId: todayNote.noteId,
        title: title,
        content: '',
        type: 'render'
    })).note;
    await renderNote.setLabel('clipType', 'clipper-HTML');
    await renderNote.setLabel('pageUrl', url);
    await renderNote.setLabel('pageTitle', title);

    // create child `content.html`
    var wrapped_content = template.replace("%%CONTENT%%", encodeURIComponent(content));
    const htmlNote = (await api.createNewNote({
        parentNoteId: renderNote.noteId,
        title: 'content.html',
        content: wrapped_content,
        type: 'file',
        mime: 'text/html'
    })).note;
    await htmlNote.setLabel('archived');

    // link renderNote to htmlNote
    await renderNote.setRelation('renderNote', htmlNote.noteId);

    res.status(200).send("{\"noteId\": \""+renderNote.noteId+"\"}");
}
else {
    res.send(500); 
}

Based on https://github.com/nil0x42/trilium-utils/blob/master/singlefile2trilium/singlefile2trilium-handler.js and https://github.com/html-screen-capture-js/html-screen-capture-js

trilium-web-clipper's People

Contributors

johnwang1023 avatar zadam avatar

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.