-
Notifications
You must be signed in to change notification settings - Fork 12
/
background.js
127 lines (107 loc) · 4.4 KB
/
background.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === 'install') {
chrome.tabs.create({ url: 'onboarding.html' });
}
});
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
if (!tabs[0].url.includes('chat.openai.com')) {
chrome.tabs.create({ url: 'https://chat.openai.com/chat' });
return;
}
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.cookies.get(
{ url: tabs[0].url, name: '__Secure-next-auth.session-token' },
function (sessionTokenCookie) {
chrome.cookies.get(
{ url: tabs[0].url, name: 'cf_clearance' },
function (cfClearanceCookie) {
var sessionToken = sessionTokenCookie.value;
var cfClearance = cfClearanceCookie.value;
var userAgent = navigator.userAgent;
var finalOutput = `CF_CLEARANCE=${cfClearance}\r\n\r\nSESSION_TOKEN=${sessionToken}\r\n\r\nUSER_AGENT="${userAgent}"\r\n`;
var copyCfClearanceButton = document.createElement('button');
copyCfClearanceButton.innerHTML = 'Copy CF Clearance';
copyCfClearanceButton.addEventListener('click', function () {
navigator.clipboard.writeText(cfClearance);
displayCopyMessage(this);
});
document.body.appendChild(copyCfClearanceButton);
var copySessionTokenButton = document.createElement('button');
copySessionTokenButton.innerHTML = 'Copy Session Token';
copySessionTokenButton.addEventListener('click', function () {
navigator.clipboard.writeText(sessionToken);
displayCopyMessage(this);
});
document.body.appendChild(copySessionTokenButton);
var copyUserAgentButton = document.createElement('button');
copyUserAgentButton.innerHTML = 'Copy User Agent';
copyUserAgentButton.addEventListener('click', function () {
navigator.clipboard.writeText(userAgent);
displayCopyMessage(this);
});
document.body.appendChild(copyUserAgentButton);
var seperator = document.createElement('hr');
document.body.appendChild(seperator);
var copyAllButton = document.createElement('button');
copyAllButton.innerHTML = 'Copy All';
copyAllButton.addEventListener('click', function () {
navigator.clipboard.writeText(finalOutput);
displayCopyMessage(this);
});
document.body.appendChild(copyAllButton);
var seperator = document.createElement('hr');
document.body.appendChild(seperator);
var downloadLink = document.createElement('a');
downloadLink.innerHTML =
'<img id="downloadIcon" src="download-light.png" style="width: 20px; height: 20px; margin-right: 5px; vertical-align: middle;" /> .env-all';
downloadLink.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(finalOutput);
downloadLink.download = '.env-all';
downloadLink.addEventListener('click', function (e) {
e.preventDefault();
download('.env-all', finalOutput);
displayDownloadMessage(this);
});
downloadLink.onmouseover = function () {
document.getElementById('downloadIcon').src = 'download-dark.png';
};
downloadLink.onmouseout = function () {
document.getElementById('downloadIcon').src = 'download-light.png';
};
document.body.appendChild(downloadLink);
function displayCopyMessage(button) {
button.originalText = button.innerHTML;
button.innerHTML = 'Copied!';
button.style.backgroundColor = '#503EE2';
setTimeout(function () {
button.innerHTML = button.originalText;
button.style.backgroundColor = '#F5057B';
}, 3000);
}
function displayDownloadMessage(a) {
a.originalText = a.innerHTML;
a.innerHTML = 'Downloaded .env-all!';
a.style.backgroundColor = '#503EE2';
setTimeout(function () {
a.innerHTML = a.originalText;
document.getElementById('downloadIcon').src = 'download-light.png';
a.style.backgroundColor = '#F5057B';
}, 3000);
}
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute(
'href',
'data:text/plain;charset=utf-8,' + encodeURIComponent(text),
);
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
},
);
},
);
});
});