// ==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);