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.

目前為 2015-11-26 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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     1
// @license     GNUGPL
// @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(addButton,1000);
    var t1 = window.setTimeout(loadFrame,4000);
    var button;
    iframe.addEventListener("load",function(ev) {
      clearInterval(t0);
      clearInterval(t1);
      removeButton();
    });
  }
})();