Repository navigation
Expand file tree
/
Copy pathbackground.js
More file actions
64 lines (58 loc) · 1.97 KB
/
Copy pathbackground.js
File metadata and controls
64 lines (58 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var imported = document.createElement('script');
imported.src = 'jquery.js';
document.head.appendChild(imported);
chrome.runtime.onMessage.addListener(function(response,sender,sendResponse){
url = parseUrl(sender.url);
hashCode = url.pathname.split('/')[1];
getDataFromCode(hashCode);
});
function parseUrl(href) {
var l = document.createElement("a");
l.href = href;
return l;
};
function myOutsideFunc(domainUrl){
console.log(domainUrl);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var current = tabs[0];
console.log("current"+current.id);
chrome.tabs.update(current.id, {'url': domainUrl});
});
}
function getDataFromCode(refCode){
$.ajax({
url: 'http://127.0.0.1:5000/url/' + refCode,
type: 'GET',
async: false,
success: function(response) {
console.log(response);
myOutsideFunc(setDataToCurrentTab(response));
},
error: function(error) {
console.log(error);
return "url";
}
});
};
function setDataToCurrentTab(refData){
var domainUrl = "";
setJsons = JSON.parse(refData);
for(var i=0;i<setJsons.length;i++){
var singleCookie = setJsons[i];
singleCookie.url = "http" + ((singleCookie.secure) ? "s" : "") + "://" + singleCookie.domain + singleCookie.path;
if(domainUrl.length===0){
domainUrl = "https://www"+singleCookie.domain;
}
delete singleCookie["secure"];
singleCookie["expirationDate"] = parseInt(singleCookie["expirationDate"]);
delete singleCookie["expirationDate"];
console.log(JSON.stringify(setJsons[i]));
console.log(singleCookie);
chrome.cookies.set(setJsons[i],function (cookie){
console.log(JSON.stringify(cookie));
console.log(chrome.extension.lastError);
console.log(chrome.runtime.lastError);
});
}
return domainUrl;
};