Skip to content

Instantly share code, notes, and snippets.

@sfantree
Last active March 29, 2020 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfantree/f779a2ee4948a09cb1cd8e5790735748 to your computer and use it in GitHub Desktop.
Save sfantree/f779a2ee4948a09cb1cd8e5790735748 to your computer and use it in GitHub Desktop.
convert web page to kindle

convert web page to kindle

I want to learn English by Kindle, so read a English web page is a good choice

Now install Caiyunxiaoyi Chrome Extension

https://chrome.google.com/webstore/detail/lingocloud-web-translatio/jmpepeebcbihafjjadogphmbgiffiajh

Calibre Convertor

https://manual.calibre-ebook.com/generated/en/ebook-convert.html

step

  1. open link like https://wiki.archlinux.org/index.php/installation_guide

  2. click caiyun extension

  3. open F12 and copy following js code in Console

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}
async function scroller() {
    let position = 0;    
    while (position <= document.body.scrollHeight)  
    {  
        position += 50;  
        scroll(0, position); 
        await sleep(80)
    }
}
scroller();
  1. save a fully html document as local file
var saveData = (function () {
    var a = document.createElement("a");
    document.body.appendChild(a);
    a.style = "display: none";
    return function (data, fileName) {
        var json = data,
            blob = new Blob([json], {type: "text/plain;charset=utf-8"}),
            url = window.URL.createObjectURL(blob);
        a.href = url;
        a.download = fileName;
        a.click();
        window.URL.revokeObjectURL(url);
    };
}());
var data = document.documentElement.outerHTML;
var fileName = "document.html";
saveData(data, fileName);
  1. convert with calibre
@ECHO OFF
echo %date%
set YYYYMMDD=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%
echo %YYYYMMDD%
set _TIME=%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%
set NAME=%YYYYMMDD%%_TIME%
echo %NAME%
chcp 65001
ebook-convert.exe document.html document%YYYYMMDD%%_TIME%.mobi --filter-css ',background,color,background-color,font-family' --mobi-file-type both --pretty-print 
ebook-meta.exe --authors lin --publisher calibre 

Reference

javascript如何能简短优雅地实现sleep函数? - 贺师俊的回答 - 知乎

https://www.zhihu.com/question/31636244/answer/52835780

JavaScript: Save a blob to disc · GitHub

https://gist.github.com/philipstanislaus/c7de1f43b52531001412

How to download a blob file from Chrome iOS in Javascript?

https://stackoverflow.com/questions/29134418/how-to-download-a-blob-file-from-chrome-ios-in-javascript

页面自动滚动

https://wiki.jikexueyuan.com/project/javascript-special-efficacy-examples/page-automatically-scroll.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment