Last active
February 26, 2017 00:11
-
-
Save hectorm/9f1867da5170240b3a8943857fdb900d to your computer and use it in GitHub Desktop.
Disqus VigLink remover
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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