Last active
April 24, 2017 01:22
-
-
Save cauerego/c970f7921f906ddf895cda05d30a7a93 to your computer and use it in GitHub Desktop.
Revisions
-
cauerego revised this gist
Apr 24, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ // @namespace reddit // @include http*//*reddit.com/* // @version 0.1 // @description 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. // @author [email protected] // @grant none // ==/UserScript== -
cauerego revised this gist
Apr 24, 2017 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -38,9 +38,12 @@ div.md {max-width: none;} } openAllComments(); function openAllComments () { function countComments () { return $('.commentarea .comment:visible').length; } var delay = 500; var itemsOpened = 0; var button = createButton('open all comments (' + countComments() + ')'); $(button).click(function() { button.disabled = true; var item; @@ -79,14 +82,13 @@ div.md {max-width: none;} itemsOpened += 1; button.textContent = 'openning ' + itemsOpened; item.click(); checkItem(); } else { finish(); } }, delay); function finish () { button.textContent = 'open all comments (' + countComments() + ')'; button.disabled = false; clearInterval(interval); } -
cauerego revised this gist
Apr 24, 2017 . 1 changed file with 47 additions and 19 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -29,8 +29,6 @@ div.md {max-width: none;} button.textContent = caption; return button; }; $('.commentarea').addClass('print'); formatForPrinting(); function formatForPrinting () { @@ -40,28 +38,58 @@ div.md {max-width: none;} } openAllComments(); function openAllComments () { var delay = 500; var itemsOpened = 0; var button = createButton('open all comments'); $(button).click(function() { button.disabled = true; var item; var checkItem = function() {}; var stuck = 0; var interval = setInterval(function() { if (checkItem()) { // still loading if (stuck > 20) { finish(); $('span.morecomments a.button.opened:contains("loading")').first().focus(); } stuck += 1; return; } if (!item || item.length === 0) { item = $('span.morecomments a.button:visible:not(.opened)').first(); checkItem = function() { if (item && !item.is(':visible')){ item = null; return false; } return true; }; } if (!item || item.length === 0) { item = $('div.collapsed>div>p>a.expand:visible:not(.opened):contains("[+]")'); // all at once, why not? checkItem = function() { item = null; return false; }; } if (item && item.length > 0 && item.is(':visible') && !item.is('.opened')) { stuck = 0; item.addClass('opened'); itemsOpened += 1; button.textContent = 'openning ' + itemsOpened; item.click(); console.log(itemsOpened, item); checkItem(); } else { finish(); } }, delay); function finish () { button.textContent = 'open all comments'; button.disabled = false; clearInterval(interval); } }); } removeThisSide(); -
cauerego revised this gist
Apr 23, 2017 . 1 changed file with 23 additions and 25 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -20,56 +20,54 @@ div.md {max-width: none;} `; $('head').append(`<style type="text/css">@media print {${css}}</style>`); var shortlink = document.querySelector('div.shortlink'); var createButton = function (caption) { var div = document.createElement('div'); div.class = 'printbutton'; var button = document.createElement('button'); div.appendChild(button); shortlink.parentNode.appendChild(div); button.textContent = caption; return button; }; var nextDelay = 0; let itemsOpenned = 0; $('.commentarea').addClass('print'); formatForPrinting(); function formatForPrinting () { $(createButton('format for printing')).click(function() { $('head').append(`<style type="text/css">${css}</style>`); }); } openAllComments(); function openAllComments () { var button = createButton('open all comments'); var openSelector = function(sel, delay) { $(sel).each(function (i, collapsed) { if (collapsed) { nextDelay += delay; setTimeout(function (item) { itemsOpenned += 1; button.textContent = 'openning ' + itemsOpenned; item.click(); }, nextDelay, collapsed); } }); }; $(button).click(function() { button.disabled = true; openSelector('span.morecomments a.button', 500); openSelector('div.collapsed>div>p>a.expand', 100); nextDelay += 69; setTimeout(function() { button.textContent = 'open all comments'; button.disabled = false; }, nextDelay); }); } removeThisSide(); function removeThisSide () { $(createButton('remove this side')).click(function() { $('.side').toggle(); }); } }; -
cauerego revised this gist
Apr 23, 2017 . 1 changed file with 10 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -20,11 +20,15 @@ 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) { @@ -65,7 +69,7 @@ div.md {max-width: none;} printbutton.textContent = 'remove this side'; $(printbutton).click(function() { $('.side').toggle(); //$('div.content').prepend(printbutton.parentNode); }); } }; -
cauerego revised this gist
Apr 23, 2017 . 1 changed file with 30 additions and 24 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,6 +12,13 @@ '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 printdiv = document.createElement('div'); printdiv.class = 'printbutton'; @@ -32,35 +39,34 @@ } }); }; $('.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(printdiv); }); } }; -
cauerego revised this gist
Apr 23, 2017 . 1 changed file with 42 additions and 28 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,48 +6,62 @@ // @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 shortlink = document.querySelector('div.shortlink'); var printdiv = document.createElement('div'); printdiv.class = 'printbutton'; var printbutton = document.createElement('button'); printdiv.appendChild(printbutton); shortlink.parentNode.appendChild(printdiv); 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); } }); }; printbutton.textContent = 'format for printing'; $(printbutton).click(formatForPrinting); function formatForPrinting () { $('.commentarea').addClass('print'); $('head').append(` <style type="text/css"> .side {float: none;} #siteTable .link.self {margin-right: 0;} .commentarea.print div {margin-right: 0 !important;} div.md {max-width: none;} </style> `); printbutton.textContent = 'open all comments'; $(printbutton).click(openAllComments); } function openAllComments () { printbutton.disabled = true; openSelector('span.morecomments a.button', 500); openSelector('div.collapsed>div>p>a.expand', 100); nextDelay += 69; setTimeout(function() { printbutton.textContent = 'remove this side'; printbutton.disabled = false; }, nextDelay); $(printbutton).click(removeThisSide); } function removeThisSide () { $('.side').toggle(); //$('div.content').prepend(printdiv); } }; var script = document.createElement('script'); -
cauerego revised this gist
Apr 23, 2017 . 1 changed file with 6 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ (function() { 'use strict'; var start = function() { var delay = 100; //ms var shortlink = document.querySelector('div.shortlink'); @@ -32,25 +32,19 @@ nextDelay += delay; } }; $(printbutton).click(function() { $('span.morecomments').each(itemDelay); $('div.collapsed').each(itemDelay); printbutton.textContent = 'format for printing'; $(printbutton).click(function() { $('.side').css({'float':'none'}); $('#siteTable .link.self').css({'margin-right':0}); $('.commentarea .comment').attr('style', function(i,s){ return s + 'margin-right: 0 !important;';}); $('div.md').css({'max-width':'none'}); printbutton.textContent = 'remove this side'; $(printbutton).click(function() { $('.side').toggle(); $('div.content').prepend(printdiv); }); }); }); -
cauerego revised this gist
Apr 23, 2017 . 1 changed file with 39 additions and 29 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,50 +5,60 @@ // @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 // @todo use css instead of javascript to format // ==/UserScript== (function() { 'use strict'; var start = function(){ var delay = 100; //ms var shortlink = document.querySelector('div.shortlink'); var printdiv = document.createElement('div'); printdiv.class = 'printbutton'; var printbutton = document.createElement('button'); printbutton.textContent = 'open all comments'; printdiv.appendChild(printbutton); shortlink.parentNode.appendChild(printdiv); var nextDelay = delay; var itemDelay = function (i, divcollapsed) { var aexpand = $('a.expand', divcollapsed).first(); if (aexpand) { setTimeout(function (item) { item.click(); }, nextDelay, aexpand); nextDelay += delay; } }; $(printbutton).click(function(){ $('span.morecomments').each(itemDelay); $('div.collapsed').each(itemDelay); printbutton.textContent = 'format for printing'; $(printbutton).click(function(){ $('.side').css({'float':'none'}); $('.nestedlisting>.comment').css({'margin-right':0}); $('#siteTable .linkflair').css({'margin-right':0}); $('div.md').css({'max-width':'none'}); printbutton.textContent = 'remove this side'; $(printbutton).click(function(){ $('.side').toggle(); $('div.content').prepend(printdiv); printbutton.textContent = 'back to normal'; $(printbutton).click(function(){ $('.side').toggle(); printdiv.remove(); start(); }); }); }); }); }; var script = document.createElement('script'); script.type = 'text/javascript'; script.textContent = '(' + start + ')()'; document.body.appendChild(script); })(); -
cauerego revised this gist
Apr 23, 2017 . 1 changed file with 39 additions and 24 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,35 +5,50 @@ // @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] // @require https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js // @require https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js // @grant none // ==/UserScript== /* jshint ignore:start */ var inline_src = (<><![CDATA[ /* jshint ignore:end */ /* jshint esnext: false */ /* jshint esversion: 6 */ const delay = 200; //ms let start = function(){ let shortlink = document.querySelector('div.shortlink'); let printdiv = document.createElement('div'); printdiv.class = 'printbutton'; let printbutton = document.createElement('button'); printbutton.value = 'format for printing'; printdiv.appendChild(printbutton); shortlink.parentNode.appendChild(printdiv); let nextDelay = delay; let itemDelay = function (item) { setTimeout(function (item) { item.click(); nextDelay += delay; }, nextDelay); }; $(printbutton).click(function(){ $('.side').css({'float':''}); $('#siteTable .linkflair').css({'margin-right':0}); $('div.md').css({'max-width':'none'}); $('span.morecomments').each(itemDelay); $('div.collapsed a.expand').each(itemDelay); }); }; let script = document.createElement('script'); script.type = 'text/javascript'; script.textContent = `(${start})()`; document.body.appendChild(script); /* jshint ignore:start */ ]]></>).toString(); var c = Babel.transform(inline_src, { presets: [ "es2015", "es2016" ] }); eval(c.code); /* jshint ignore:end */ -
cauerego created this gist
Apr 23, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ // ==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'; const delay = 200 //ms let start = function(){ let shortlink = document.querySelector('div.shortlink') let printdiv = document.createElement('div') printdiv.class = 'printbutton' let printbutton = document.createElement('button') printbutton.value = 'format for printing' printdiv.appendChild(printbutton) shortlink.parentNode.appendChild(printdiv) let nextDelay = delay let itemDelay = (item => {setTimeout(item => item.click(), nextDelay); nextDelay += delay}) $(printbutton).click(function(){ $('.side').css({'float':''}) $('#siteTable .linkflair').css({'margin-right':0}) $('div.md').css({'max-width':'none'}) $('span.morecomments').each(itemDelay) $('div.collapsed a.expand').each(itemDelay) }) } let script = document.createElement('script') script.type = 'text/javascript' script.textContent = `(${start})()` document.body.appendChild(script) })()