Disqus Ignore Redirects

Prevent URLs on embedded Disqus discussions from redirecting.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

/*
    This is a Greasemoneky user script to prevent URLs on embedded Disqus discussions from redirecting.
    Copyright (C) 2017 aktai

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

// ==UserScript==
// @name        Disqus Ignore Redirects
// @description Prevent URLs on embedded Disqus discussions from redirecting.
// @namespace   aktai
// @include     https://disqus.com/embed/*
// @version     1
// @grant       none
// @license     GPL-3.0+
// @supportURL  https://github.com/aktai0/Disqus-Ignore-Redirects
// ==/UserScript==

// This is implemented as a click listener, so it works even on links in comments added after clicking "Load More Comments"
document.addEventListener('click', function (event) {
   // Ignore clicks on non-"a" tags and "a" tags whose href attribute does not contain "disq.us"
	if (event.target.tagName != "A" || event.target.href.search(/https?:\/\/disq\.us\//) == -1) {
		return;
	}
   
   // Regex to match a "disq.us" URL and group the original URL, up to the last encoded colon
	var redirRegex = /https?:\/\/disq\.us\/url\?url=(.*)%3A.*/g;
   var newURL = event.target.href.replace(redirRegex, function (match, p1) {
         // Match the original URL and return the decoded version
			return decodeURIComponent(p1);
		});
      
   // Update the "a" tag's href attribute
   event.target.href = newURL;
}, true);