Skip to content

Instantly share code, notes, and snippets.

@JossWhittle
Created July 14, 2012 15:11
Show Gist options
  • Save JossWhittle/3111758 to your computer and use it in GitHub Desktop.
Save JossWhittle/3111758 to your computer and use it in GitHub Desktop.
Chrome Extension Script to convert all title links to open in new tabs. Requires jquery.
// JQuery included here...
// A variable to hold the "timeout-id" for our DOM check
var update;
// Page is ready
$(document).ready(function() {
// The DOM (page) was updated
$("body").bind("DOMSubtreeModified", function() {
// Attempt to clear the currently scheduled check
try { clearTimeout(update); } catch(err) {}
// Schedule a new check for 100ms time from now
update = setTimeout(function() {
fix();
}, 100);
});
});
// Any DOM optimizations we want to do go here
function fix() {
// Make sure all <a> for post titles are set to
// open in a new tab (target="_blank")
$('a.title').attr('target', '_blank');
// I decided I wanted the comment link in a new tab too...
$('a.comments').attr('target', '_blank');
}
{
"name": "Reddit Linker",
"version": "0.1",
"description": "Makes Reddit title links open in a new tab...",
"permissions": [
"tabs", "http://www.reddit.com/*"
],
"content_scripts": [{
"matches": ["http://www.reddit.com/*"],
"js": ["linker.js"]
}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment