Guest User

background.js

a guest
May 6th, 2014
182
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // masks Opera to Chrome 34 on all Google sites
  2. // copyright (c) 2014 dqdb
  3.  
  4. // regex mask based on parseUri 1.2.2 strict mode by Steven Levithan
  5. // http://blog.stevenlevithan.com/archives/parseuri
  6. urlRegex = /^(?:([^:\/?#]+):)?(?:\/\/([^:\/?#]*)(?::\d*)?)?((?:\/[^#]*)+)(?:#.*)?$/;
  7.  
  8. chrome.webRequest.onBeforeSendHeaders.addListener(function (details)
  9. {
  10.     var headers = details.requestHeaders;
  11.     var matches = urlRegex.exec(details.url);
  12.     if (matches != null && matches.length == 4)
  13.     {
  14.         var host = matches[2];
  15.         if (host.indexOf("google") != -1 || host.indexOf("goo.gl") != -1)
  16.         {
  17.             for (var n = 0; n < headers.length; n++)
  18.             {
  19.                 var p = headers[n];
  20.                 if (p.name == "User-Agent")
  21.                 {
  22.                     p.value = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36";
  23.                     break;
  24.                 }
  25.             }
  26.             console.log(headers);
  27.         }
  28.     }
  29.    
  30.     return { requestHeaders: headers };
  31. },
  32. {
  33.     urls: ["<all_urls>"]
  34. }, ["blocking", "requestHeaders"]);
RAW Paste Data