Skip to content

Commit

Permalink
Merge pull request #3 from Scipline/feature/optimize
Browse files Browse the repository at this point in the history
Optimize
  • Loading branch information
Lomusire authored Nov 13, 2023
2 parents 4f40f68 + 43bea41 commit 340f9a9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 133 deletions.
54 changes: 30 additions & 24 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.type === 'fetchToken') {
fetch('https://gpt4.freecrypto.tech')
.then(response => response.json())
.then(data => {
let token = data.token;
let expirationDate = (new Date().getTime() / 1000) + 60 * 60 * 24 * 365; // 1 year from now
chrome.cookies.set({
url: 'https://www.phind.com',
name: '__Secure-next-auth.session-token',
value: token,
path: '/',
secure: true,
httpOnly: true,
sameSite: 'lax',
expirationDate: Math.min(expirationDate, (new Date().getTime() / 1000) + 60 * 60 * 24 * 400) // Maximum of 400 days [support.google.com](https://developer.chrome.com/blog/cookie-max-age-expires/)
}, function(cookie) {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message);
} else {
// Send a message to content script to reload the page
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {type: 'reloadPage'});
});
.then((response) => response.json())
.then((data) => {
let token = data.token
let expirationDate = new Date().getTime() / 1000 + 60 * 60 * 24 * 365 // 1 year from now
chrome.cookies.set(
{
url: 'https://www.phind.com',
name: '__Secure-next-auth.session-token',
value: token,
path: '/',
secure: true,
httpOnly: true,
sameSite: 'lax',
expirationDate: Math.min(
expirationDate,
new Date().getTime() / 1000 + 60 * 60 * 24 * 400
), // Maximum of 400 days [support.google.com](https://developer.chrome.com/blog/cookie-max-age-expires/)
},
function (cookie) {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message)
} else {
// Send a message to content script to reload the page
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { type: 'reloadPage' })
})
}
}
});
});
)
})
}
});
})
28 changes: 11 additions & 17 deletions content.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
let eventCount = 0;

document.addEventListener('keydown', function(e) {
document.addEventListener('keydown', function (e) {
if (e.key === 'Enter') {
eventCount++;
checkEventCount();
checkEventCount()
}
});

document.addEventListener('click', function() {
eventCount++;
checkEventCount();
});

})
setInterval(function () {
checkEventCount()
}, 5000)
function checkEventCount() {
if (eventCount >= 10) {
chrome.runtime.sendMessage({type: 'fetchToken'});
eventCount = 0;
const left = +document.querySelector('.text-primary').firstChild.textContent
if (left <= 0) {
chrome.runtime.sendMessage({ type: 'fetchToken' })
}
}

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.type === 'reloadPage') {
window.location.reload();
window.location.reload()
}
});
})
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"name": "GPT-4 Unlimited",
"description": "Experience the power of GPT-4 with our easy-to-install browser extension.",
"version": "1.0",
"permissions": ["activeTab", "storage", "cookies", "http://*/*", "https://*/*", "webRequest", "tabs"],
"background": {
"service_worker": "background.js"
},
Expand All @@ -22,5 +21,6 @@
"48": "gpt4.png",
"128": "gpt4.png"
},
"host_permissions": ["http://www.phind.com/*", "https://www.phind.com/*", "https://gpt4.freecrypto.tech/*"]
"host_permissions": ["http://www.phind.com/*", "https://www.phind.com/*", "https://gpt4.freecrypto.tech/*"],
"permissions": ["activeTab", "storage", "cookies","webRequest", "tabs"]
}
94 changes: 4 additions & 90 deletions styles.css
Original file line number Diff line number Diff line change
@@ -1,95 +1,9 @@
/* Import Google font - Poppins */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');

body {
font-family: 'Poppins', sans-serif !important;
background-color: #343541 !important;
}

button {
background-color: #6b6c7b !important;
color: #000000 !important;
border: none !important;
padding: 10px 20px !important;
text-align: center !important;
text-decoration: none !important;
img[src='/images/phind_v2.svg'] {
content: url('https://upload.wikimedia.org/wikipedia/commons/0/04/ChatGPT_logo.svg') !important;
width: 100px !important; /* Adjust as required */
height: 35px !important; /* Adjust as required */
display: inline-block !important;
font-size: 16px !important;
margin: 10px 5px !important;
cursor: pointer !important;
}

button:hover {
background-color: #19c37d !important;
}

/* Add other styles based on the ChatGPT design... */

.chat-container {
overflow-y: auto !important;
max-height: 100vh !important;
padding-bottom: 150px !important;
}

.chat-container .chat.outgoing {
background: #E0E0E0 !important;
border: 1px solid #D9D9D9 !important;
}

.chat-container .chat.incoming {
background: #FFFFFF !important;
border: 1px solid #D9D9D9 !important;
}

.typing-container {
position: fixed !important;
bottom: 0 !important;
width: 100% !important;
display: flex !important;
padding: 20px 10px !important;
justify-content: center !important;
background: #E0E0E0 !important;
border-top: 1px solid #D9D9D9 !important;
}

img[src="/images/phind_v2.svg"] {
content: url('https://upload.wikimedia.org/wikipedia/commons/0/04/ChatGPT_logo.svg') !important;
width: 100px !important; /* Adjust as required */
height: 35px !important; /* Adjust as required */
display: inline-block !important;
}


input[type="text"] {
width: 100% !important;
height: 50px !important;
padding: 10px !important;
border: 1px solid #D9D9D9 !important;
border-radius: 5px !important;
}

.conversation-area {
width: 100% !important;
height: 80vh !important;
padding: 20px !important;
border: 1px solid #D9D9D9 !important;
border-radius: 5px !important;
overflow-y: auto !important;
}

.chat-bubble {
max-width: 70% !important;
padding: 10px !important;
border-radius: 15px !important;
margin-bottom: 10px !important;
}

.chat-bubble.outgoing {
background-color: #E0E0E0 !important;
align-self: flex-end !important;
}

.chat-bubble.incoming {
background-color: #FFFFFF !important;
align-self: flex-start !important;
}

0 comments on commit 340f9a9

Please sign in to comment.