Guest User

Untitled

a guest
May 5th, 2014
171
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     function runAppStart() {
  2.     var n = localStorage.uaStorage;
  3.     userAgents = n != undefined ? JSON.parse(n) : JSON_UserAgentsList, localStorage.uaStorage = JSON.stringify(userAgents), createContextMenu(),
  4. ////////////////////////////////////////////////
  5.     n = localStorage.selectedUserAgent;
  6.     if (n != undefined)
  7.         selectedUserAgent = JSON.parse(n);
  8.     else
  9.         localStorage.selectedUserAgent = JSON.stringify(selectedUserAgent);
  10. ////////////////////////////////////////////////
  11. }
  12.  
  13. function createContextMenu() {
  14.     chrome.contextMenus.removeAll(), chrome.contextMenus.create({
  15.         id: "Default",
  16.         contexts: ["all"],
  17.         onclick: function () {
  18.             setUserAgent("Default", !0, "ContextMenu")
  19.         },
  20.         title: "Default",
  21.         type: "checkbox",
  22.         checked: selectedUserAgent.Id == "Default"
  23.     }), chrome.contextMenus.create({
  24.         contexts: ["all"],
  25.         type: "separator"
  26.     }), userAgents.forEach(function (n) {
  27.         if (n.UserAgents.length != 0) var t = chrome.contextMenus.create({
  28.                 id: n.Id,
  29.                 contexts: ["all"],
  30.                 title: n.Name,
  31.                 type: "normal"
  32.             }),
  33.             i = n.UserAgents.forEach(function (i) {
  34.                 chrome.contextMenus.create({
  35.                     id: i.Id,
  36.                     parentId: n.Id,
  37.                     contexts: ["all"],
  38.                     onclick: function () {
  39.                         setUserAgent(i.Id, !0, "ContextMenu")
  40.                     },
  41.                     title: i.Name,
  42.                     type: "checkbox",
  43.                     checked: selectedUserAgent.Id == i.Id
  44.                 }), selectedUserAgent.Id == i.Id && chrome.contextMenus.update(t, {
  45.                     contexts: ["all"],
  46.                     title: "[ " + n.Name + " ]",
  47.                     type: "normal"
  48.                 })
  49.             })
  50.     }), chrome.contextMenus.create({
  51.         contexts: ["all"],
  52.         type: "separator"
  53.     }), chrome.contextMenus.create({
  54.         contexts: ["all"],
  55.         onclick: function () {
  56.             return chrome.tabs.create({
  57.                 url: "options.html"
  58.             }), !1
  59.         },
  60.         title: "Options",
  61.         type: "normal"
  62.     }), chrome.contextMenus.create({
  63.         contexts: ["all"],
  64.         onclick: function () {
  65.             return chrome.tabs.create({
  66.                 url: "http://www.esolutions.se/whatsmyinfo"
  67.             }), !1
  68.         },
  69.         title: "Show User-agent",
  70.         type: "normal"
  71.     })
  72. }
  73.  
  74. function setUserAgent(n, t, i, r) {
  75.     for (var f, u = 0; u < userAgents.length; u++)
  76.         for (userAgents[u].Id == n && (selectedUserAgent.Id = userAgents[u].Id, selectedUserAgent.Name = userAgents[u].Name, selectedUserAgent.UserAgent = userAgents[u].UserAgent), f = 0; f < userAgents[u].UserAgents.length; f++) userAgents[u].UserAgents[f].Id == n && (selectedUserAgent.Id = userAgents[u].UserAgents[f].Id, selectedUserAgent.Name = userAgents[u].UserAgents[f].Name, selectedUserAgent.UserAgent = userAgents[u].UserAgents[f].UserAgent);
  77. ////////////////////////////////////////////////
  78.     localStorage.selectedUserAgent = JSON.stringify(selectedUserAgent);
  79. ////////////////////////////////////////////////
  80.     createContextMenu(), setIconAndText(), t == !0 && chrome.tabs.reload(), r && typeof r == "function" && r()
  81. }
  82.  
  83. function setIconAndText() {
  84.     selectedUserAgent.UserAgent != "" ? (chrome.browserAction.setIcon({
  85.         path: "img/active.png"
  86.     }), chrome.browserAction.setBadgeText({
  87.         text: "On"
  88.     })) : (chrome.browserAction.setIcon({
  89.         path: "img/icon19.png"
  90.     }), chrome.browserAction.setBadgeText({
  91.         text: ""
  92.     }))
  93. }
  94. var selectedUserAgent = JSON_DefaultUserAgent,
  95.     userAgents = JSON_UserAgentsList;
  96. handler = function (n) {
  97.     if (selectedUserAgent.UserAgent != "") {
  98.         for (var t = 0, i = n.requestHeaders.length; t < i; ++t)
  99.             if (n.requestHeaders[t].name === "User-Agent") {
  100.                 n.requestHeaders[t].value = selectedUserAgent.UserAgent;
  101.                 break
  102.             }
  103.         return {
  104.             requestHeaders: n.requestHeaders
  105.         }
  106.     }
  107. }, chrome.webRequest.onBeforeSendHeaders.addListener(handler, {
  108.     urls: ["<all_urls>"]
  109. }, ["blocking", "requestHeaders"]), chrome.runtime.onMessage.addListener(function (n, t, i) {
  110.     i({
  111.         userAgent: selectedUserAgent.UserAgent
  112.     })
  113. }), runAppStart(), setIconAndText();
RAW Paste Data