Created
February 18, 2016 16:41
-
-
Save a142/962129fa06c2c00644f2 to your computer and use it in GitHub Desktop.
Twitter Image opener user.js
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 Twitter Image opener | |
// @version 0.1 | |
// @description Open twitter image from thumbnail | |
// @author a142 | |
// @match https://twitter.com/* | |
// @grant none | |
// ==/UserScript== | |
(function(){ | |
var ovserver = new MutationObserver(function(mutationRecords){ | |
for(var i = 0; i < mutationRecords.length; i++) { | |
var record = mutationRecords[i]; | |
if (record.addedNodes.length > 0) { | |
var img = record.addedNodes[0]; | |
if (img.className == "media-image") { | |
var src = img.currentSrc.replace(":large", ":orig"); | |
var link = document.createElement('a'); | |
link.setAttribute("href", src); | |
link.setAttribute("target", "_blank"); | |
link.appendChild(img); | |
record.target.appendChild(link); | |
} | |
} | |
} | |
}); | |
ovserver.observe(document, { | |
childList: true, | |
subtree: true, | |
attributes: false, | |
characterData: false, | |
}); | |
var next = document.getElementsByClassName("GalleryNav--next")[0]; | |
if (next) next.style.width = "33%"; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment