Non-popup dialogs for gcup

Opens profile information (and a few other) pages on gcup.ru as new tabs instead of popups.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Non-popup dialogs for gcup
// @description Opens profile information (and a few other) pages on gcup.ru as new tabs instead of popups.
// @description:ru Открывает информацию о профиле (и несколько других страниц) на gcup.ru как новые вкладки, а не всплывающие окна.
// @namespace   http://yal.cc
// @include     http://gcup.ru/*
// @version     1
// @grant       none
// ==/UserScript==
var list = document.getElementsByTagName("a");
var rxWindowOpen = /window\.open\('([^']+)'[^)]+\);return false;/;
for (var i = 0; i < list.length; i++) {
	var a = list[i];
	if (a.href == "javascript://") { // handled via JS
		var js = a.getAttribute("onclick"), m;
		if (js.indexOf("window.open") == 0) { // starts with `window.open`
			m = rxWindowOpen.exec(js);
			if (m != null) { // matches the `window.open('...'); return false;`
				a.href = m[1]; // set href to `...`
				a.target = "_blank"; // open in new tab
				a.removeAttribute("onclick"); // onclick no longer needed.
			}
		}
	}
}