Skip to content

Instantly share code, notes, and snippets.

@hectorm
Last active February 26, 2017 00:11
Show Gist options
  • Save hectorm/9f1867da5170240b3a8943857fdb900d to your computer and use it in GitHub Desktop.
Save hectorm/9f1867da5170240b3a8943857fdb900d to your computer and use it in GitHub Desktop.
Disqus VigLink remover
// ==UserScript==
// @name Disqus VigLink remover
// @namespace xyz.molinero
// @version 1.0.2
// @grant none
// @run-at document-end
// @include /^https?:\/\/(www\.)?disqus.com\/embed\/.*$/
// @downloadURL https://gist.github.com/zant95/9f1867da5170240b3a8943857fdb900d/raw/DisqusVigLinkRemover.user.js
// ==/UserScript==
(function () {
function replaceDisqusLink (anchor) {
if (anchor.href.match(/disq.us\/url/)) {
const url = new URL(anchor.href);
const realUrl = url.searchParams.get('url').replace(/:[0-9a-z_-]{16,48}$/i, '');
if (realUrl != null) {
anchor.href = decodeURIComponent(realUrl);
}
}
}
['click', 'dblclick', 'contextmenu'].forEach(function (eventName) {
window.addEventListener(eventName, function (event) {
if (event.target instanceof HTMLAnchorElement) {
replaceDisqusLink(event.target);
} else if (event.target.parentElement instanceof HTMLAnchorElement) {
replaceDisqusLink(event.target.parentElement);
}
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment