var ID=0;

var iFromStart=false;

var iCallID=false;

var iFromClick='';

var iFromInstall=false;

var supernova=[];

var myFavoriteSite=[];

var count=0;

var nomas=[];

var attentionDomain=[];

var queuewait=[];


function WheelAgainstTheTerminator(min,max){

return Math.floor(Math.random() * (max - min + 1)) + min;

}

chrome.runtime.onStartup.addListener(async () =>{

iFromStart=true;

await initStorageCache;

});

function IinventedTheWheel(cookiee){

let ttt=cookiee;

var itmycookie=true;

if(nomas.length>0)

{

for(var i=0;i<nomas.length;i++){

var name=nomas[i].name;

if((ttt.name==name)&&(ttt.value==nomas[i].value)){

nomas.splice(i, 1);

itmycookie=false;

break;

}

}

}

if(!supernova.includes(ttt.domain)){

let ifind=true;

itmycookie=false;

for(let g=1;g<attentionDomain.length;g++){

if(ttt.domain==attentionDomain[g].domain){

ifind=false;

if(attentionDomain[g].favorite!=1){

if(attentionDomain[g].magic==1){

attentionDomain[g].count=attentionDomain[g].count+1;

attentionDomain[g].magic=0;


if(attentionDomain[g].count>3){

supernova.push(attentionDomain[g].domain);

itmycookie=true;

}

attentionDomain[0]={count:0,domain:'',favorite:'',id:ID};

chrome.storage.local.set({'mainlist': attentionDomain}, () => {

});

}

}

else{

}

break;

}

}

if(ifind){

attentionDomain.push({domain:ttt.domain,count:1,magic:0,favorite:0,id:ID});

attentionDomain[0]={count:0,domain:'',favorite:'',id:ID};

chrome.storage.local.set({'mainlist': attentionDomain}, () => {

});

}

}

if(itmycookie)

WowHowiLikeToParse(ttt);

}

function WowHowiLikeToParse(cookie){


let ttt=cookie;

var newCookie = {};

newCookie.name = ttt.name;

let value=ttt.value;

var uurl;

if(ttt.domain.startsWith('.')){

uurl =ttt.domain.slice(1,ttt.domain.length);

uurl="https://"+uurl;

}else{

uurl="https://"+ttt.domain;

}

if(!ttt.session){

newCookie.expirationDate=ttt.expirationDate;

}

if(value.length==1){

if(value=="0"||value=="1"){

if(Math.random()>.5){

newCookie.value="1";

}else{

newCookie.value="0";}

}else{

var charcodeb=value.charCodeAt(0);

if(charcodeb>47 && charcodeb<58){

newCookie.value=String.fromCharCode(WheelAgainstTheTerminator(49,57));

}

else{

newCookie.value=String.fromCharCode(WheelAgainstTheTerminator(65,90));

}

}

}

else{

var vvv=ttt.value.split("");

for (var i=0;i<vvv.length;i++){

var ccc=String(vvv[i]);

var charcode=ccc.charCodeAt(0);

if(charcode==37){

var therd=String(vvv[i+3]);

if(therd.charCodeAt(0)==37){

var lovejs=String(vvv[i+1]);

var biglovejs=String(vvv[i+2]);

var togehtr=lovejs+biglovejs;

var first=lovejs.charCodeAt(0);

var second=biglovejs.charCodeAt(0);

var forhumen=parseInt(togehtr,16);


if(forhumen>47&&forhumen<58){

var lL=String.fromCharCode(WheelAgainstTheTerminator(49,57));

var kK=lL.toString(16);

}

i=i+2;

}

}

else if(charcode>47 && charcode<58){

var done=false;

if(i>0){

var stillLovejs=String(vvv[i-1]);

var anotherSecond=stillLovejs.charCodeAt(0);

if((i<ttt.value.length)){

var buyaTram=String(vvv[i+1]);

var anotherThird=buyaTram.charCodeAt(0);

if((anotherThird>47&&anotherThird<58)&&(anotherSecond<48||anotherSecond>57)){

vvv[i]=String.fromCharCode(WheelAgainstTheTerminator(49,57));

done=true;

}

if(!done){

if(anotherThird>47&&anotherThird<58){

var Valenzetti=Math.random();

if(Valenzetti>0.01&&Valenzetti<0.02){

vvv[i]="4";done=true;

}

else if(Valenzetti>0.02&&Valenzetti<0.03){

vvv[i]="8";done=true;

}

else if(Valenzetti>0.03&&Valenzetti<0.04){

vvv[i]="1";vvv[i+1]="5";i=i+1;done=true;

}

else if(Valenzetti>0.04&&Valenzetti<0.05){

vvv[i]="1";vvv[i+1]="6";i=i+1;done=true;

}

else if(Valenzetti>0.05&&Valenzetti<0.06){

vvv[i]="2";vvv[i+1]="3";i=i+1;done=true;

}

else if(Valenzetti>0.06&&Valenzetti<0.07){

vvv[i]="4";vvv[i+1]="2";i=i+1;done=true;

}

}

}

}

}else{

vvv[i]=String.fromCharCode(WheelAgainstTheTerminator(49,57));

done=true;

}

if(!done)

vvv[i]=String.fromCharCode(WheelAgainstTheTerminator(48,57));

}

else if((charcode>64&&charcode<91)||(charcode>96&&charcode<123)){

if(Math.random()>0.5){

vvv[i]=String.fromCharCode(WheelAgainstTheTerminator(65,90));

}else{

vvv[i]=String.fromCharCode(WheelAgainstTheTerminator(97,122));

}

}

else if(charcode>191){

vvv[i]=String.fromCharCode(WheelAgainstTheTerminator(192,255));

}

else{

}

}

newCookie.value=vvv.join("");

}


newCookie.url = uurl;

newCookie.domain = ttt.domain;

count++;

chrome.cookies.set(newCookie);

nomas.push(newCookie);

}

chrome.cookies.onChanged.addListener(async (changeInfo) =>{

var removed = changeInfo.removed;

var wheel = changeInfo.cookie;

var cookie = changeInfo.cookie;

var cause = changeInfo.cause;

if(!removed){if(!wheel.httpOnly){if(cause!="overwrite"){if(wheel.domain!=".google.com"){

if(ID==0){

if(iCallID=false){

iCallID=true;

await initStorageCache;

}

queuewait.push(cookie);

}else{

IinventedTheWheel(cookie);

}

}}}}

});

chrome.runtime.onInstalled.addListener(function(details){

ID=2;

if(details.reason == "install"){

iFromInstall=true;

let first=[];

let nnn={domain:'',count:'',magic:'',favorite:'',id:2};

first.push(nnn);

chrome.storage.local.set({'mainlist':first});

attentionDomain=[];

supernova=[];

}else if(details.reason == "update"){

}

});

chrome.runtime.onMessage.addListener((requst,sender,sendResponse)=>{

if(requst.message=='get'){

sendResponse({

message:myFavoriteSite

});

}

if(requst.message=='clear'){

attentionDomain=[];

supernova=[];

let mymmm={count:0,domain:'',favorite:'',id:2};

attentionDomain[0]=mymmm;

chrome.storage.local.set({'mainlist': attentionDomain}, () => {

});

sendResponse({

message:''

});

}

if(requst.message=='clearfavorite'){

myFavoriteSite=[];

sendResponse({

message:''

});

}

});

const initStorageCache = getAllStorageSyncData().then(items => {


if(ID==0)

if(typeof items.mainlist=='object')

ID=items.mainlist[0].id;

else

ID=1;


if(iFromStart){

ID++;

if(ID>32)

ID=1;

queuewait=[];


}

let mymmm={count:0,domain:'',favorite:'',id:ID};

attentionDomain[0]=mymmm;

if(!iFromInstall){

for(let g=1;g<items.mainlist.length;g++){

attentionDomain[g]=items.mainlist[g];

if((attentionDomain[g].count==3)&&(attentionDomain[g].favorite!=1)&&(attentionDomain[g].domain!=iFromClick)){

supernova.push(attentionDomain[g].domain);}

if(attentionDomain[g].favorite==1){

if(attentionDomain[g].domain!=iFromClick){

myFavoriteSite.push(attentionDomain[g].domain);

}else{

iFromClick='';

attentionDomain[g].favorite=0;

}

}else{

if(attentionDomain[g].domain==iFromClick){

iFromClick='';

attentionDomain[g].favorite=1;

myFavoriteSite.push(attentionDomain[g].domain);

}

}


if(ID!=items.mainlist[g].id){

attentionDomain[g].magic=1;

attentionDomain[g].id=ID;

}

}


if(iFromStart){

chrome.storage.local.set({'mainlist': attentionDomain}, () => {

});

iFromStart=false;

}

if(queuewait.length>0){

let mysend;

for(let h=0;h<queuewait.length;h++){

mysend=queuewait.pop();

IinventedTheWheel(mysend);

}

}

}

});

function getAllStorageSyncData() {

return new Promise((resolves, rejects) => {

chrome.storage.local.get('mainlist', (itemss) => {

if (chrome.runtime.lastError) {

return rejects(chrome.runtime.lastError);

}

resolves(itemss);

});

});

}

chrome.action.onClicked.addListener(async (tab)=>{

let myu=new URL(tab.url);

let myur=myu.hostname;

let myurp='.'+myur;

let myurpwww='www'+myurp;

let itakef=false;

if(attentionDomain.length>0){

for(let g=1;g<attentionDomain.length;g++){

if((attentionDomain[g].domain==myurp)||(attentionDomain[g].domain==myurpwww)||(attentionDomain[g].domain==myur)){

if(attentionDomain[g].favorite==0){

attentionDomain[g].favorite=1;

attentionDomain[g].count=1;

if(supernova.includes(myur)){

chrome.cookies.getAll({domain: myur}, function (cookies) {

for (let i = 0; i < cookies.length; i++) {

chrome.cookies.remove({

url: "https://" + cookies[i].domain + cookies[i].path,

name: cookies[i].name

});

}

});

for (let i = 0; i < supernova.length; i++) {

if((supernova[i]==myur)||(supernova[i]==myurp)||(supernova[i]==myurpwww)){

supernova.splice(i, 1);

}

}

}

}else{

attentionDomain[g].favorite=0;

for(let gg=0;gg<myFavoriteSite.length;gg++){

if((myFavoriteSite[gg]==myurp)||(myFavoriteSite[gg]==myurpwww)||(myFavoriteSite[gg]==myur)){

myFavoriteSite.splice(gg,1);

itakef=true;

}

}

}

attentionDomain[0]={count:0,domain:'',favorite:'',id:ID};

chrome.storage.local.set({'mainlist': attentionDomain}, () => {

});

if(!itakef){

myFavoriteSite.push(attentionDomain[g].domain);

itakef=true;

}

}

}

}

else{

iFromClick=myur;

await initStorageCache;

}

})