在耍github时,一点链接,就会覆盖原有的页面,这一点真的让我好不爽
打开个说明文档,github没了,想把文档留着还要重开个页面
打开个演示地址,页面又没了,又要重开
…………
此脚本可以在github中点击链接时,新开一个标签页
v1.1更新:仅对外部链接有效
// ==UserScript==
// @name GitHub Open Links in New Tab
// @namespace http://tampermonkey.net/
// @version v1.1
// @description Make all links in GitHub open in new tabs.
// @author Lucky_Lau
// @match *://github.com/*
// @grant none
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
// 获取当前网页的基本URL,用于后面判断链接是否为GitHub内部链接
const githubBaseURL = window.location.origin;
document.querySelectorAll('a').forEach(function(link) {
// 检查链接是否指向GitHub外部
if (link.href.startsWith('http') && !link.href.startsWith(githubBaseURL)) {
// 如果是外部链接,则设置为在新标签页中打开
link.target = '_blank';
}
});
})();