新页面打开网页链接
// ==UserScript==
// @name 新页面打开网页链接
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Make all links open in a new tab.
// @author Even
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAADcNJREFUeF7tnWFOHDkThu0wIOUUS26xUohC7hCk/Rc4SchJQv6tRO4QohAptwi3WCkZ4sUz3dAMDW2X7Z637Hd+fLvf0u2x36pnqsp2u63hhwpQgUcVsNSGClCBxxUgIPQOKvCEAgSE7kEFCAh9gArIFGAEkenGuxpRgIA0YmgOU6YAAZHpxrsaUYCANGJoDlOmAAGR6ca7GlGAgDRiaA5TpgABkenGuxpRgIA0YmgOU6YAAZHpxrsaUYCANGJoDlOmAAGR6ca7GlGAgDRiaA5TpgABkenGuxpRgIA0YmgOU6YAAZHpxrsaUYCANGJoDlOmAAGR6ca7GlGAgDRiaA5TpgABkenGuxpRgIA0YmgOU6YAAZHpxrsaUYCANGJoDlOmAAGR6ca7GlGAgDRiaA5TpgABkenGuxpRgIA0YmgOU6YAAZHpxrsaUYCAKDX0f//8vb9YLvaNMa9XQ7DmsB+KM87/99uPNfbK/x9n3Oqfxjz7ap272v18eaF0+LN1m4DMJnXaF3VAvOtAuIUhrdVbaC4IzbiSBCTVwwre//vtwfvcQEx1t4syF9bZT4wwPjDzA6XAIFKcbrtjHhbr7Nlysfz0/N8fXXq27V7N+/0EZF69H/22328PDp11H62x9+oHhO61HFUIyJY90KdRzrpjRDDGpLmZADhrKf0iIFsCxKdSO9c7X7SA8UAmZ05bSL0IyMyAINUYqUPva5Tdz5cfUttCvZ+AzGgZX2cYa77M+JWzfJUH5Xrn+k2NhTwBmcWFjOmmbLc+M1VquLVGEwJSymO6dlcp1fXiozF3K92Fv3K7zTtzWlPKRUAKulOtKdWUZD6a7J1/fzF1nYa/E5BCVpobjlWK82DP1Xpwg5mybFtUpmSrpS4hIFOWFvz919GrY2ucT6uKfPp8v2v8a8yWkH6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oFeAD0Jf0hQgakAhGDDQNAnICChFV7lDrN2nUsvF8lPoSn1Iu7wmTYGmARlKt978uHtozJ/Xc8x8Dbew8A1ZaU5c8m4CMqJuqT1UfZTwe7pyb4Is6SQtt01AAqzvgfGX+cOhnV0fHGGd+8tZt/73+/uwrqxb79HyIPj/IQwBIoNeQkBADcNuYShAQDDswF6AKkBAQA3DbmEoQEAw7MBegCpAQEANw25hKEBAMOzAXoAqQEBADcNuYShAQDDswF6AKkBAQA3DbmEoQEAw7MBegCpAQEANw25hKEBAMOzAXoAqQEBADcNuYShAQDDswF6AKkBAQA3DbmEoQEAw7MBegCpAQEANw25hKEBAMOzAXoAqQEBADcNuYShAQDDswF6AKkBAQA3DbmEoQEAw7MBegCpAQEANw25hKEBAMOzAXoAqQEBADcNuYShAQDDswF6AKkBAQA3DbmEoQEAw7MBegCpAQEANw25hKEBAMOzAXoAqQEBADcNuYShAQDDswF6AKkBAQA3DbmEoQEAw7MBegCpAQEANw25hKPA/taVOMlbxRz0AAAAASUVORK5CYII=
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 获取页面上的所有链接
var links = document.getElementsByTagName('a');
// 遍历所有链接,修改它们的target属性
for (var i = 0; i < links.length; i++) {
links[i].target = '_blank';
}
// 对于后续动态添加到页面的链接,可以通过MutationObserver来处理
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes) {
mutation.addedNodes.forEach(function(node) {
// 检查是否为元素节点,并且包含链接
if (node.nodeType === 1 && node.tagName === 'A') {
node.target = '_blank';
}
});
}
});
});
// 配置观察选项:
var config = { childList: true, subtree: true };
// 传入目标节点和观察选项
observer.observe(document.body, config);
})();