Last active
April 24, 2017 01:22
-
-
Save cauerego/c970f7921f906ddf895cda05d30a7a93 to your computer and use it in GitHub Desktop.
a few new buttons for reddit: prepare page for printing (or saving) in a better reading streamable format, open all comments and remove side bar. made for http://tampermonkey.net/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name print reddit | |
| // @namespace reddit | |
| // @include http*//*reddit.com/* | |
| // @version 0.1 | |
| // @description create a button in reddit to prepare page for printing (or saving) in a better reading streamable format | |
| // @author [email protected] | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| var start = function() { | |
| var css = ` | |
| .side {float: none;} | |
| #siteTable .link.self {margin-right: 0;} | |
| .commentarea.print div {margin-right: 0 !important;} | |
| div.md {max-width: none;} | |
| `; | |
| $('head').append(`<style type="text/css">@media print {${css}}</style>`); | |
| var shortlink = document.querySelector('div.shortlink'); | |
| var createButton = function () { | |
| var div = document.createElement('div'); | |
| div.class = 'printbutton'; | |
| var button = document.createElement('button'); | |
| div.appendChild(button); | |
| shortlink.parentNode.appendChild(div); | |
| return button; | |
| }; | |
| var printbutton = createButton(); | |
| var nextDelay = 0; | |
| let itemsOpenned = 0; | |
| var openSelector = function(sel, delay) { | |
| $(sel).each(function (i, collapsed) { | |
| if (collapsed) { | |
| nextDelay += delay; | |
| setTimeout(function (item) { | |
| itemsOpenned += 1; | |
| printbutton.textContent = 'openning ' + itemsOpenned; | |
| item.click(); | |
| }, nextDelay, collapsed); | |
| } | |
| }); | |
| }; | |
| $('.commentarea').addClass('print'); | |
| formatForPrinting(); | |
| function formatForPrinting () { | |
| printbutton.textContent = 'format for printing'; | |
| $(printbutton).click(function() { | |
| $('head').append(`<style type="text/css">${css}</style>`); | |
| openAllComments(); | |
| }); | |
| } | |
| function openAllComments () { | |
| printbutton.textContent = 'open all comments'; | |
| $(printbutton).click(function() { | |
| printbutton.disabled = true; | |
| openSelector('span.morecomments a.button', 500); | |
| openSelector('div.collapsed>div>p>a.expand', 100); | |
| nextDelay += 69; | |
| setTimeout(function() { | |
| removeThisSide(); | |
| printbutton.disabled = false; | |
| }, nextDelay); | |
| }); | |
| } | |
| function removeThisSide () { | |
| printbutton.textContent = 'remove this side'; | |
| $(printbutton).click(function() { | |
| $('.side').toggle(); | |
| //$('div.content').prepend(printbutton.parentNode); | |
| }); | |
| } | |
| }; | |
| var script = document.createElement('script'); | |
| script.type = 'text/javascript'; | |
| script.textContent = '(' + start + ')()'; | |
| document.body.appendChild(script); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment