Created
February 23, 2012 16:41
-
-
Save saitamanodoruji/1893676 to your computer and use it in GitHub Desktop.
Tumblr Dashboard Auto Click Inline External Images
This file contains 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 Tumblr Dashboard Auto Click Inline External Images | |
// @namespace http://saitamanodoruji.tumblr.com/ | |
// @include http://www.tumblr.com/dashboard* | |
// @include http://www.tumblr.com/show/* | |
// @include http://www.tumblr.com/likes* | |
// @include http://www.tumblr.com/liked/by/* | |
// @include http://www.tumblr.com/tagged* | |
// @include http://www.tumblr.com/blog* | |
// @include https://www.tumblr.com/dashboard* | |
// @include https://www.tumblr.com/show/* | |
// @include https://www.tumblr.com/likes* | |
// @include https://www.tumblr.com/liked/by/* | |
// @include https://www.tumblr.com/tagged* | |
// @include https://www.tumblr.com/blog* | |
// @version 0.0.2.1 | |
// @update 2014-08-15 | |
// @contributer syoichi https://gist.github.com/syoichi/1913412 | |
// @author saitamanodoruji | |
// @updateURL https://gist.github.com/saitamanodoruji/1893676/raw/tumblr_dashboard_auto_click_inline_external_images.user.js | |
// @downloadURL https://gist.github.com/saitamanodoruji/1893676/raw/tumblr_dashboard_auto_click_inline_external_images.user.js | |
// ==/UserScript== | |
(function(){ | |
var $$ = function(sel, ctx) { | |
return Array.prototype.slice.call((ctx || document).querySelectorAll(sel)) | |
} | |
var isAnchored = function(node) { | |
if (/(?:^| )post_content(?:$| )/.test(node.parentNode.className)) { | |
return false | |
} else if (node.parentNode.nodeName == 'A' && node.parentNode.href) { | |
return true | |
} else { | |
return isAnchored(node.parentNode) | |
} | |
} | |
var ext = function(node) { | |
var sel = [ | |
'.album_art', | |
'.inline_external_image:not(.enlarged)', | |
'.image_thumbnail:not(.enlarged)', | |
'.toggle_inline_image' | |
].join(','), | |
img = $$(sel, node), | |
clicked = false | |
if (img.length) { | |
if ( /(?:^| )album_art(?:$| )/.test(img[0].className) || | |
!img.some(function(i) { return isAnchored(i) }) ) { | |
img[0].click() | |
clicked = true | |
} | |
img.forEach(function(i) { | |
i.removeAttribute('width') | |
i.removeAttribute('height') | |
if (!clicked && i.getAttribute('external_src')) { | |
i.src = i.getAttribute('external_src') | |
} | |
}) | |
} | |
} | |
// for the first page | |
$$('li.post_container').forEach(function(li) { | |
window.setTimeout(function() { ext(li) }, 0) | |
}) | |
// for inserted pages | |
document.body.addEventListener('DOMNodeInserted', function(evt) { | |
if (/(?:^| )post_container(?:$| )/.test(evt.target.className)) ext(evt.target) | |
}, false) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment