Last active
December 10, 2015 22:29
-
-
Save tarao/4502411 to your computer and use it in GitHub Desktop.
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 hatena-bookmark-lower-thumbnail | |
// @namespace orednu.org | |
// @include http://b.hatena.ne.jp/* | |
// @version 1 | |
// ==/UserScript== | |
(function(w, d) { | |
w.addEventListener('load', function () { | |
var getElementsByTagAndClassName = function(element, tag, klass) { | |
var elements = element.getElementsByTagName(tag); | |
return Array.prototype.slice.call(elements).reduce(function(r, e) { | |
var klasses = e.className||''; | |
if (klasses.split(/ +/).indexOf(klass) >= 0) r.push(e); | |
return r; | |
}, []); | |
}; | |
var getThumbnail = function(div) { | |
return getElementsByTagAndClassName(div, 'a', 'thumbnail')[0]; | |
}; | |
var getQuote = function(div) { | |
return div.getElementsByTagName('blockquote')[0]; | |
}; | |
var swapTitleAndThumbnail = function(div) { | |
var thumb = getThumbnail(div); | |
var ul = div.parentNode.parentNode; | |
if (thumb && /^entry-vertical/.test(ul.className||'')) { | |
div.removeChild(thumb); | |
div.appendChild(thumb); | |
} | |
}; | |
var divs = getElementsByTagAndClassName(d, 'div', 'entry-contents'); | |
divs.forEach(swapTitleAndThumbnail); | |
}); | |
})(window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment