Google Images Bypass Content Security Policy

Bypasses the Content Security Policy of websites that are blocking the website preview view on Google Images results. Otherwise you only see the mesage: Blocked by Content Security Policy. This page has a content security policy that prevents it from being loaded in this way. Firefox prevented this page from loading in this way because the page has a content security policy that disallows it.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Google Images Bypass Content Security Policy
// @description Bypasses the Content Security Policy of websites that are blocking the website preview view on Google Images results. Otherwise you only see the mesage: Blocked by Content Security Policy. This page has a content security policy that prevents it from being loaded in this way. Firefox prevented this page from loading in this way because the page has a content security policy that disallows it.
// @namespace   cuzi
// @oujs:author cuzi
// @version     2
// @license     GPL-3.0
// @include     /^https?:\/\/images\.google\.\w{2,3}\//
// @grant       GM_xmlhttpRequest
// ==/UserScript==
(function() {
  function loadFrame(ev) {
    removeButton();
    var iframe = document.getElementById("il_f");
    GM_xmlhttpRequest({
      method: "GET",
      url: iframe.src,
      onload: function(response) { 
        var charset = "utf-8";
        var re = /<meta charset=\"(.*?)\">/;
        var m = response.responseText.match(re);
        if(m && m[1]) {
          charset = m[1];
        }        
        iframe.src = 'data:text/html;charset='+charset+',' + encodeURIComponent(response.responseText);
      }
    });
  }
  function addButton(ev) {
    button = document.createElement("button");
    button.appendChild(document.createTextNode("Bypass Content Security Policy"));
    button.setAttribute("style","font-size:150%; color:crimson;");
    button.addEventListener("click",loadFrame);
    document.getElementById("il_mi").insertBefore(button, document.getElementById("il_mi").firstChild);
  }
  function removeButton(ev) {
    if(button) {
      button.parentNode.removeChild(button);
      button = null;
    }
  }
  if(document.getElementById("il_f")) {
    var iframe = document.getElementById("il_f");
    var t0 = window.setTimeout(loadFrame,4000);
    var button;
    addButton();
    iframe.addEventListener("load",function(ev) {
       clearInterval(t0);
    });
  }
})();