Forked from oradwell/gmail_remove_image_proxy.user.js
Last active
August 29, 2015 14:25
-
-
Save hilyjiang/1d6729c3db0c8fe1bb99 to your computer and use it in GitHub Desktop.
Gmail Image Proxy Disable - Greasemonkey script
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 Gmail remove gstatic | |
// @namespace ockcyp/gmail-remove-gstatic | |
// @version 0.1 | |
// @description Remove gstatic from external image URLs (useful when URLs contain internal domains) | |
// @author ockcyp | |
// @grant none | |
// ==/UserScript== | |
setTimeout(function() { | |
// Page is loaded and the div is not already created | |
if (document.title.match(/@/) === null || document.getElementById('remove_img_proxy_div')) { | |
return; | |
} | |
var textNode = document.createTextNode("Don't use Image Proxy"); | |
// The div containing the links | |
var divElem = document.createElement('div'); | |
divElem.setAttribute('style', 'position:absolute;bottom:15px;' | |
+ 'font-size:12px;background-color:#EFF;padding:10px;margin:auto'); | |
divElem.setAttribute('id', 'remove_img_proxy_div'); | |
// Link to disable proxy | |
var anchorElem = document.createElement('a'); | |
anchorElem.setAttribute('href', '#'); | |
anchorElem.addEventListener('click', function () { | |
var img, elem, src; | |
// img src | |
while (img = document.evaluate('//img[contains(@src, \'googleusercontent.com\') and contains(@src, \'#http\')]', document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue) { | |
src = img.attributes.src.value; | |
src = src.substr(src.indexOf('#') + 1); | |
img.attributes.src.value = src; | |
} | |
// CSS background url etc | |
while (elem = document.evaluate('//*[contains(@style,\'googleusercontent.com\') and contains(@src, \'#http\')]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue) { | |
style = elem.attributes.style.value; | |
style = style.replace(/url\(([^\)#]*)#([^\)]*)\)/, "url($2)"); | |
elem.attributes.style.value = style; | |
} | |
return false; | |
}); | |
anchorElem.setAttribute('style', 'text-decoration:none;color:black;margin-right:5px'); | |
anchorElem.appendChild(textNode); | |
divElem.appendChild(anchorElem); | |
// Link to hide the button | |
var hideAnchor = document.createElement('a'); | |
hideAnchor.setAttribute('href', '#'); | |
hideAnchor.setAttribute('style', 'text-decoration:none;color:black;font-size:14px'); | |
hideAnchor.setAttribute('onclick', "document.getElementsByTagName('body')[0].removeChild(document.getElementById('remove_img_proxy_div'))"); | |
hideAnchor.innerHTML = '×'; | |
divElem.appendChild(hideAnchor); | |
document.getElementsByTagName('body')[0].appendChild(divElem); | |
}, 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment