Skip to content

Instantly share code, notes, and snippets.

@interfect
Last active August 29, 2015 14:08
Show Gist options
  • Save interfect/f734996559708180ecc4 to your computer and use it in GitHub Desktop.
Save interfect/f734996559708180ecc4 to your computer and use it in GitHub Desktop.
Reddit Open In Same Tab
// ==UserScript==
// @name Reddit open in same tab
// @namespace roist
// @description Makes links on reddit.com open in the same tab by default, even if not logged in.
// @include http://*.reddit.com/*
// @include https://*.reddit.com/*
// @version 1
// @author Interfect
// @copyright 2014 Interfect
// @grant none
// ==/UserScript==
document.body.addEventListener('click', function(e){
var element = e.target;
if(element.tagName == "A" && element.hasAttribute("target") && element.getAttribute("target") == "_blank") {
// This is a link that wants to open in a new tab. Tell it to use the same frame instead.
element.setAttribute("target", "_self");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment