Skip to content

Instantly share code, notes, and snippets.

@attie
Last active May 6, 2024 12:37
Show Gist options
  • Save attie/6ee3fa3dea286452070ed6249de98d70 to your computer and use it in GitHub Desktop.
Save attie/6ee3fa3dea286452070ed6249de98d70 to your computer and use it in GitHub Desktop.
Make image links open in a new tab
// ==UserScript==
// @name Make image links open in a new tab
// @namespace http://attie.co.uk/
// @source https://gist.github.com/attie/6ee3fa3dea286452070ed6249de98d70
// @version 2024-05-06
// @description Some links should just open in a new tab...
// @author Attie Grande <attie@attie.co.uk>
// @match https://*.stackexchange.com/*
// @match https://stackoverflow.com/*
// @match https://superuser.com/*
// @match https://serverfault.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=stackexchange.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
document.querySelectorAll('div.question a > img, div.answer a > img').forEach(
(el) => { el.parentNode.setAttribute('target','_blank') }
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment