Skip to content

Instantly share code, notes, and snippets.

@Dregu
Last active December 10, 2021 15:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Dregu/7d9ca25bd7f07433b800c19a6b65d324 to your computer and use it in GitHub Desktop.
Save Dregu/7d9ca25bd7f07433b800c19a6b65d324 to your computer and use it in GitHub Desktop.
Reddit Auto Expand
// ==UserScript==
// @name Reddit Auto Expand and keyboard navigation
// @namespace http://www.reddit.com/
// @version 0.1
// @description Auto expand all expandos on new reddit and a keyboard navigation that's not retarded.
// @author Dregu
// @match https://www.reddit.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
/*setInterval(function() {
var e = document.querySelector('button[data-click-id=expando_open]:not([data-clicked])');
if(e) {
var x = e;
setTimeout(function() { x.dataset.clicked = 1; }, 100);
setTimeout(function() { x.click(); }, 100);
}
}, 200);*/
document.addEventListener('keypress', navi);
window.postnum = -1;
function navi(e) {
if(e.key == '.') { // next post
var posts = document.querySelectorAll('.Post:not(.promotedlink)');
if(posts[window.postnum]) {
var current = posts[window.postnum].querySelector('button[data-click-id="expando_close"]');
if(current) current.click();
}
window.postnum++;
if(window.postnum > posts.length) window.postnum = posts.length;
posts[window.postnum].scrollIntoView();
var current = posts[window.postnum].querySelector('button[data-click-id="expando_open"]');
if(current) current.click();
var next = posts[window.postnum+1].querySelector('button[data-click-id="expando_open"]');
if(next) next.click();
}
if(e.key == ',') { // prev post
var posts = document.querySelectorAll('.Post:not(.promotedlink)');
window.postnum--;
if(window.postnum < 0) window.postnum = 0;
posts[window.postnum].scrollIntoView();
var current = posts[window.postnum].querySelector('button[data-click-id="expando_open"]');
if(current) current.click();
}
if(e.key == '-') { // comments
var close = document.querySelector('button[title="Close"]');
if(close) {
close.click();
} else {
var posts = document.querySelectorAll('.Post:not(.promotedlink)');
posts[window.postnum].scrollIntoView();
var current = posts[window.postnum].querySelector('a[data-click-id="comments"]');
if(current) current.click();
}
}
}
document.querySelector('header').style.position = 'absolute';
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment