0
Chrome Stroge синхронизация Возврат Ошибка
//Options
var useProxy = false;
var useIPDebugger = false;
var useUserAgentT = false;
var useBlockJS = false;
var useBlockCSS = false;
//Load Options
chrome.storage.sync.get("useUserAgent",
function(val) {
alert(val.useUserAgent); //return True
useUserAgentT = val.useUserAgent; //marking
}
);
alert(useUserAgentT); //but return False
val.useUserAgent
возвращается Правда, но useUserAgentT = val.useUserAgent;
и alert(useUserAgentT);
возвращаются ложь:/
Более подробно файлы.
options.js
$(document).ready(function() {
\t var isCheckedProxy = false;
\t var isCheckedIPDebug = false;
\t var isCheckedUserAgent = false;
\t var isCheckedJS = false;
\t var isCheckedCSS = false;
\t $('#isCheckedProxy').on('change', function(){
\t \t if(this.checked) {isCheckedProxy = true; chrome.browserAction.setBadgeText({text: String("true")});} else {isCheckedProxy = false; chrome.browserAction.setBadgeText({text: String("false")});}
\t \t save_options();
\t });
\t $('#isCheckedIPDebug').on('change', function(){
\t \t if(this.checked) {isCheckedIPDebug = true;} else {isCheckedIPDebug = false;}
\t \t save_options();
\t });
\t $('#isCheckedUserAgent').on('change', function(){
\t \t if(this.checked) {isCheckedUserAgent = true;} else {isCheckedUserAgent = false;}
\t \t save_options();
\t });
\t $('#isCheckedJS').on('change', function(){
\t \t if(this.checked) {isCheckedJS = true;} else {isCheckedJS = false;}
\t \t save_options();
\t });
\t $('#isCheckedCSS').on('change', function(){
\t \t if(this.checked) {isCheckedCSS = true;} else {isCheckedCSS = false;}
\t \t save_options();
\t });
\t //Kaydet
\t function save_options() {
\t \t chrome.storage.sync.set({
\t \t \t isCheckedProxy: isCheckedProxy,
\t \t \t isCheckedIPDebug: isCheckedIPDebug,
\t \t \t isCheckedUserAgent: isCheckedUserAgent,
\t \t \t useUserAgent: isCheckedUserAgent, //this is useUserAgent setting.
\t \t \t isCheckedJS: isCheckedJS,
\t \t \t isCheckedCSS: isCheckedCSS
\t \t }, function() {
\t \t \t //alert("saved.");
\t \t });
\t }
\t //Yükle
\t function restore_options() {
\t \t chrome.storage.sync.get({
\t \t \t isCheckedProxy: isCheckedProxy,
\t \t \t isCheckedIPDebug: isCheckedIPDebug,
\t \t \t isCheckedUserAgent: isCheckedUserAgent,
\t \t \t isCheckedJS: isCheckedJS,
\t \t \t isCheckedCSS: isCheckedCSS
\t \t }, function(items) {
\t \t \t $('#isCheckedProxy').attr('checked', items.isCheckedProxy);
\t \t \t isCheckedProxy = items.isCheckedProxy;
\t \t \t if(items.isCheckedProxy == true) {chrome.browserAction.setBadgeText({text: String("true")});} else {chrome.browserAction.setBadgeText({text: String("false")});}
\t \t \t $('#isCheckedIPDebug').attr('checked', items.isCheckedIPDebug);
\t \t \t isCheckedIPDebug = items.isCheckedIPDebug;
\t \t \t $('#isCheckedUserAgent').attr('checked', items.isCheckedUserAgent);
\t \t \t isCheckedUserAgent = items.isCheckedUserAgent;
\t \t \t $('#isCheckedJS').attr('checked', items.isCheckedJS);
\t \t \t isCheckedJS = items.isCheckedJS;
\t \t \t $('#isCheckedCSS').attr('checked', items.isCheckedCSS);
\t \t \t isCheckedCSS = items.isCheckedCSS;
\t \t });
\t }
\t restore_options();
});
background.js
//Options
var useProxy = false;
var useIPDebugger = false;
var useUserAgentT = false;
var useBlockJS = false;
var useBlockCSS = false;
//Load Options
chrome.storage.sync.get("useUserAgent",
function(val) {
useUserAgentT = val.useUserAgent;
\t //alert(val.useUserAgent);
}
);
alert(useUserAgentT);
\t var items = ["Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1", "Googlebot/2.1 (+http://www.google.com/bot.html)", "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.7 (KHTML, like Gecko) Comodo_Dragon/16.1.1.0 Chrome/16.0.912.63 Safari/535.7", "Mozilla/5.0 (compatible; BecomeBot/3.0; MSIE 6.0 compatible; +http://www.become.com/site_owners.html)", "Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20121202 Firefox/17.0 Iceweasel/17.0.1", "Mozilla/4.0 (compatible; MSIE 5.23; Macintosh; PPC) Escape 5.1.8", "Mozilla/5.0 (compatible; IBrowse 3.0; AmigaOS4.0)", "Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16"];
\t chrome.webRequest.onBeforeSendHeaders.addListener(function(details){
\t var headers = details.requestHeaders,
\t blockingResponse = {};
\t for(var i = 0, l = headers.length; i < l; ++i) {
\t \t if(headers[i].name == 'User-Agent') {
\t \t headers[i].value = items[Math.floor(Math.random()*items.length)];
\t \t console.log(headers[i].value);
\t \t break;
\t \t }
\t }
\t blockingResponse.requestHeaders = headers;
\t return blockingResponse;
\t },
\t {urls: [ "<all_urls>" ]},['requestHeaders','blocking']);
}
//Set Status
chrome.browserAction.setBadgeText({text: String("unknown")});
спасибо, но нерешенным: / –