Skip to content

Instantly share code, notes, and snippets.

@jewel-andraia
Last active May 19, 2016 17:09
Show Gist options
  • Save jewel-andraia/602ed8376896449f2d09 to your computer and use it in GitHub Desktop.
Save jewel-andraia/602ed8376896449f2d09 to your computer and use it in GitHub Desktop.
unsub from all on /subreddits/mine
  1. Open http://ted.mielczarek.org/code/mozilla/bookmarklet.html in a new window.
  2. Find bookmarklet.js. Find the "Raw" button on the right edge. Right-click the button > open in new window.
  3. For Input > Name, put in "unsubscribe from all subreddits".
  4. For Input's big empty text area, paste in bookmarklet.js
  5. Follow the instructions on the crunchinator page.
  6. Click your new bookmarklet. You'll need to click it again once you're on the subreddits listing page.
(function() {
if (!/reddit.com\/subreddits\/mine/.test(window.location.href)) {
var redirectConfirm = window.confirm('This feature only works on /subreddits/mine. Do you want to go there and try again?');
if (redirectConfirm) window.location.href = 'http://reddit.com/subreddits/mine';
return;
}
var subreddits = document.querySelectorAll('.subscribe-button .remove');
var redirectConfirm = window.prompt('About to unsubscribe from ' + subreddits.length + ' subreddits. Type in "yes" to proceed.');
if (redirectConfirm !== 'yes') {
window.alert('Not unsubscribing from anything, since you do not confirm you wanted to.');
return;
}
var unsubscribing = chunk(click, subreddits, undefined, undefined, function() { window.alert("All done!"); });
window.addEventListener('beforeunload', function() {
if (unsubscribing.remaining) {
return 'Cancel unsubscribing? There are ' + unsubscribing.remaining + ' subreddits left to unsubscribe from.';
}
});
function click(obj, button) {
console.log("attempting to click obj:", obj);
var evt = document.createEvent('MouseEvents');
button = button || 0;
evt.initMouseEvent('click', true, true, window.wrappedJSObject, 0, 1, 1, 1, 1, false, false, false, false, button, null);
obj.dispatchEvent(evt);
}
function chunk(action, list, delay, state) {
console.log("chunking, remaining: " + list.length);
state = state || {};
if (!list.length) {
state.remaining = 0;
delete state.timeout;
return;
}
if (typeof delay !== "number") {
delay = 2000;
}
action(list[0]);
state.remaining = list.length - 1;
var list = [].slice.call(list, 1);
var next = chunk.bind(this, action, list, delay, state);
state.timeout = setTimeout(next, delay);
return state;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment