LoginSignup
7
7

More than 5 years have passed since last update.

Gmail の仕様変更で表示されなくなったイントラネットの画像を表示するブックマークレット

Posted at

Gmail が仕様変更して、メール内の画像を Google のプロキシを通じて表示するようになりました。
記事としては、GoogleがGmailの添付画像を自動表示可能に。 プロキシサーバを介しての配信でセキュリティ確保。とか、Gmail、メッセージに含まれる画像を自動表示するよう変更とか。

セキュリティの担保と利便性の向上っていう目的は分かるのですが、この措置により Google のプロキシがアクセスできないイントラネット上の画像が表示できない、という問題が発生しています。

…というのを解決するブックマークレット書きました。セキュリティを担保する、という Google の意志を尊重して、あえて自動化せずブックマークレットにしています。利用は自己責任で!
また、今のところ自分の目的では事足りていますが、もし画像の置換漏れがあれば、解説を参考に適宜追加したら良いと思います。

javascript:(function(d,ex){NodeList.prototype.each=Array.prototype.forEach;d.$=d.querySelectorAll;d.$('img[src*="googleusercontent.com"]').each(function(e){e.src=e.src.replace(ex,"\$1")});d.$('*[style*="googleusercontent.com"]').each(function(e){e.style.backgroundImage=e.style.backgroundImage.replace(ex,"\$1")})})(document,/https?:\/\/.*\.googleusercontent\.com\/[^#]+#([^\)"]+)/);

解説

// document オブジェクトと後で使う RegExp オブジェクトを受け取る
(function(d, ex){
    // NodeList が forEach 持って無いので Array から移植
    NodeList.prototype.each = Array.prototype.forEach; 
    // quarySelectorAll 長ったらしいので省略
    d.$ = d.querySelectorAll;
    // img 要素内の src 部分を置換
    d.$('img[src*="googleusercontent.com"]').each(function(e){
        e.src = e.src.replace(ex, "\$1");
    });
    // style の background で画像を指定しているところを置換
    d.$('*[style*="googleusercontent.com"]').each(function(e){
        e.style.backgroundImage = e.style.backgroundImage.replace(ex, "\$1");
    });
// 正規表現で Google のプロキシとその URL の後ろについているオリジナルの URL を取り出す
})(document, /https?:\/\/.*\.googleusercontent\.com\/[^#]+#([^\)"]+)/);
7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7