LoginSignup
0
2

More than 1 year has passed since last update.

GitHubのREADME内のリンクを別タブで開くユーザースクリプト

Posted at

GitHubのREADMEページにリンクがある場合、クリックすると同じタブで開かれます。これはMarkdown内に生のHTMLを書いてtarget="_blank"属性を追加しても解決しないようです。そこで、JavaScriptでaタグにtarget="_blank"属性を追加するようなユーザースクリプトを作成しました。

Chromeに拡張機能Tampermonkeyを追加し、以下のスクリプトを追加すれば良いです。

// ==UserScript==
// @name         GitHub README open in a new tab
// @namespace
// @version      0.1
// @description 
// @author       You
// @match        https://github.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let article = document.querySelector("article");
    if (article) {
        article.querySelectorAll("a").forEach(elem => {
            elem.setAttribute("target", "_blank");
        });
    }
})();
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2