Skip to content

Instantly share code, notes, and snippets.

@vzvu3k6k
Forked from noromanba/t-um-block.user.js
Last active February 17, 2016 08:31
Show Gist options
  • Save vzvu3k6k/d58e066ccf9c86c6702d to your computer and use it in GitHub Desktop.
Save vzvu3k6k/d58e066ccf9c86c6702d to your computer and use it in GitHub Desktop.
detox t.umblr.com link on tumblr.com for UserScript
// ==UserScript==
// @name t.um block (googlish)
// @namespace http://noromanba.flavors.me
// @description Hide t.umblr.com link on tumblr.com as Google does in its search result pages
// @match http://*.tumblr.com/*
// @match https://*.tumblr.com/*
// @grant none
// @noframes
// @run-at document-end
// @version 2016.2.13.0
// @homepage https://gist.github.com/vzvu3k6k/d58e066ccf9c86c6702d
// @downloadURL https://gist.github.com/vzvu3k6k/d58e066ccf9c86c6702d/raw/tumblock.user.js
// @license CC0 Univ PD https://creativecommons.org/publicdomain/zero/1.0/legalcode
// @author noromanba http://noromanba.flavors.me
// @author vzvu3k6k
// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/WHMIS_Class_D-2.svg/32px-WHMIS_Class_D-2.svg.png
// @icon64 https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/WHMIS_Class_D-2.svg/64px-WHMIS_Class_D-2.svg.png
// ==/UserScript==
// Icon (PD by Silsor/Health Canada)
// https://commons.wikimedia.org/wiki/File%3AWHMIS_Class_D-2.svg
// Originally written by noromanba
// - Blog - http://ptech.g.hatena.ne.jp/noromanba/20160208/1454965267
// - Hatena::Let - http://let.hatelabo.jp/noromanba/let/hLHU2KbCtZgI
// - Devel - https://gist.github.com/noromanba/76a3d7791cf6eaf1c94c
// c.f.
// https://stackoverflow.com/questions/35023389/tumblr-injecting-new-code-into-my-links
// e.g.
// http://yahoo.tumblr.com
(() => {
'use strict';
// can't catch events on the bubbling phase
window.addEventListener('click', event => {
if (event.target.dataset.tumblockRedirectUrl) {
event.target.href = event.target.dataset.tumblockRedirectUrl;
}
}, true);
const detox = (ctx) => {
if (!ctx.querySelectorAll) return;
Array.from(ctx.querySelectorAll([
'a[href^="http://t.umblr.com/redirect?z="]',
'area[href^="http://t.umblr.com/redirect?z="]'
//'[src^="http://t.umblr.com/redirect?z="]'
]), link => {
// redirector syntax;
// http://t.umblr.com/redirect?z=<ENCODED_URL>&t=<66_DIGIT_HASH>%3D%3D
link.dataset.tumblockRedirectUrl = link.href;
link.href = link.searchParams.get('z');
});
};
detox(document.body);
new MutationObserver(records => {
records.forEach(record => {
detox(record.target);
});
}).observe(document.body, { childList: true, subtree: true });
})();
// DBG
/*
Array.from(document.querySelectorAll([
'[href^="http://t.umblr.com/redirect?z="]',
'[src^="http://t.umblr.com/redirect?z="]'
]), link => link.tagName ).filter((val, idx, ary) => {
return ary.indexOf(val) === idx;
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment