Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Kobo Reader > Kobo Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 01-23-2022, 12:40 PM   #1
benjaffe
Junior Member
benjaffe doesn't litterbenjaffe doesn't litter
 
Posts: 2
Karma: 102
Join Date: Jan 2022
Device: Kobo Libra H2O
Lightbulb Saving/Syncing Reddit Threads to Kobo with comments intact!

Hello all! Yesterday I went on a journey to get reddit threads (with comments intact) onto my Kobo easily (on MacOS). This is a big deal, since I use Pocket, but it doesn't sync Reddit threads (which are ~20% of my reading). Below are configuration instructions, but once it's configured, here are the simple steps to save a thread:

1. Open a reddit thread
2. File - Print - Save as PDF to ~/Dropbox/kobo
3. Tell Kobo to sync, and you're done!


At its core, the ~/Dropbox/kobo folder is picked up by KoboCloud when the Kobo syncs. But there are a number of extra bits I added to make it easier and prettier, which I'll enumerate below.

The parts:
* Dropbox (or another syncing service) for syncing pdfs to the Kobo
* CSS applied via Stylus (a Chrome extension) for making the pdf more readable
* AppleScript and Folder Actions for replacing spaces with underscores in the filename.
* KoboCloud for syncing the pdfs from Dropbox to the Kobo

Here are the configuration instructions:
1. Install KoboCloud on your kobo. You can find the download and installation instructions here. Once it's installed on your Kobo, configure it to sync with a folder. I use Dropbox, and named my folder "kobo". This will probably work wonderfully with Google Drive, or other supported sync services too. I configured it to remove files from the Kobo when they are removed from Dropbox.
2. Make it pretty. (You can skip this step if you don't mind hard-to-read pdfs). Reddit threads render with faded text, and buttons/comment boxes/etc are intact. None of this is useful when reading on a Kobo, so I added a custom CSS snippet to clean up the styling. Install the Stylus Chrome Extension, open a reddit thread, open the extension, and where it says "write style for..." click on the text "reddit.com". It should open a window, and you can paste the CSS code into the code box and click "Save".
3. Automatically fix the file names. (You can skip this step if you don't mind ugly file names). When you save a file and it syncs to the Kobo, spaces turn into "%20" in my experience. To fix this, right-click on the "kobo" folder that is syncing, and click "Services - Folder Actions Setup". Click "Run Service". Then choose a script to attach. I chose "add - new item alert". Then click "Edit Script". Choose "File - Duplicate", then "File - Save". Save it as "add - replace spaces with underscores.scpt", and make sure it's saving to "/Library/Scripts/Folder Action Scripts". Now replace the content of the script with my script below. Save it, and close "Script Editor". Return to "Folder Actions Setup", and use the +/- buttons in the right pane to remove the "new item alert" script, and add the new script you just saved. Lastly, make sure the "Enable Folder Actions" checkbox in the upper left of the window is checked. Now when a file is added to the "kobo" folder, this script will automatically run and replace spaces with underscores in the filename.


CSS snippet
Code:
@media print {
    h1, h2, h3, h4, h5, h6, p {
        font-size: 120%;
    }
    * {
        color: black!important;
    }
    a {
        color: #999!important;
    }

    /* get rid of top bar */
    ._2L5G9B5yaoqW3IegiYN-FL {
        margin-top: 100px;
    }
    .hciOr5UGrnYrZxB11tX9s > style + div {
        display: none;
    }
    .hciOr5UGrnYrZxB11tX9s > style + div + style + div {
        display: block;
    }
    ._1nxEQl5D2Bx2jxDILRHemb {
        padding-top: 0;
    }
    ._1gVVmSnHZpkUgVShsn7-ua,
    .res-floater-inNavbar,
    ._3KTYozwt91D81Yub-OQ4S3 {
        display: none;
    }
    /* remove comments area */
    ._1hwEKkB_38tIoal6fcdrt9,
    ._1r4smTyOEZFO91uFIdWW6T.aUM8DQ_Nz5wL0EJc_wte6,
    ._2ulKn_zs7Y3LWsOqoFLHPo {
        display: none;
    }
    /* remove usernames and avatars */
    ._2mHuuvyV9doV3zwbZPtIPG.ZvAy-PJfJmB8pzQxpz1sS {
        background-color: #ccc;
        border-radius: 50%;
        width: 25px;
        height: 25px;
        position: relative;
        top: 8px;
        visibility: hidden;
    }
    ._2mHuuvyV9doV3zwbZPtIPG.ZvAy-PJfJmB8pzQxpz1sS * {
        visibility: hidden;
    }
    ._36MHhLdcmnzdWt0OMdNlwd {
        pointer-events: none;
    }
    .RESUserTag,
    .P8SGAKMtRxNwlmLz1zdJu.HZ-cv9q391bm8s7qT54B3 ._3KgrO85L1p9wQbgwG27q4y button,
    .XZK-LTFT5CgGo9MvPQQsy {
        display: none;
    }
    .-Xcv3XBXmgiY2X5RqaPbO._1S45SPAIb30fsXtEcKPSdt {
        flex-direction: row;
        justify-content: start;
    }
    ._3w527zTLhXkd08MyacMV9H {
        margin-left: 4px;
    }
    /* upvote count */
    .P8SGAKMtRxNwlmLz1zdJu.HZ-cv9q391bm8s7qT54B3 ._3KgrO85L1p9wQbgwG27q4y ._1rZYMD_4xY3gRcSS3p8ODO {
        position: absolute;
        color: #aaa!important;
        font-weight: normal;
        top: 18px;
        left: 6px;
        width: 24px;
        overflow: hidden;
        text-align: center;
    }
}
Folder Action Script
Code:
on adding folder items to this_folder after receiving added_items
	try
		set defDel to AppleScript's text item delimiters
		tell application "Finder"
			repeat with thisItem in added_items
				set thename to name of thisItem
				if thename contains " " then
					set AppleScript's text item delimiters to " "
					set newname to text items of thename
					set AppleScript's text item delimiters to "_"
					set name of thisItem to (newname as string)
					set AppleScript's text item delimiters to defDel
				end if
			end repeat
		end tell
	end try
end adding folder items to

Notes:
* This will work for saving any website to the kobo as a pdf. If you want to tweak the appearance and you know CSS, you can add a print rule to any page you wish using Stylus.
* This saves and syncs reddit threads as pdfs, which means you can't easily make text bigger or smaller once you're on the kobo. But you can always tweak the font-size values at the top of the CSS to change the font size in the pdfs you generate.
* This only properly reformats threads that are in their own tab/window. I always open links in new tabs, but to make it work for posts that load in a page modal, it's just some more css that has to be added. Maybe I'll do that someday, and if so, I'll update this post.
benjaffe is offline   Reply With Quote
Reply

Tags
reddit, rube goldberg, sync


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Comments Not Syncing HippieWiccan Calibre Companion 3 08-13-2019 05:24 PM
Reddit feed with comments Phoebus Recipes 5 11-16-2018 06:43 AM
Saw this question on reddit. Which "Operating System" do you use for your Kobo? lori87 Kobo Reader 8 10-11-2018 02:10 PM
Comments field results in bad characters upon saving to CSV da_jane Library Management 1 11-21-2012 05:29 PM
Saving forum threads to Kindle feelsgoodman Amazon Kindle 5 08-06-2010 09:02 AM


All times are GMT -4. The time now is 01:53 AM.


MobileRead.com is a privately owned, operated and funded community.