From 43bea416e62528fc34b08b5caa9d10771d8b17f8 Mon Sep 17 00:00:00 2001 From: Scipline Date: Mon, 13 Nov 2023 09:09:55 +0800 Subject: [PATCH] 1. Remove unnecessary dark styles, Phind has a dark mode in the upper right corner 2. Fix the permissions in the manifest 3. Optimize the refresh token logic in content.js --- background.js | 54 ++++++++++++++++------------- content.js | 28 ++++++--------- manifest.json | 4 +-- styles.css | 94 +++------------------------------------------------ 4 files changed, 47 insertions(+), 133 deletions(-) diff --git a/background.js b/background.js index 610b0ff..7e9534f 100644 --- a/background.js +++ b/background.js @@ -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' }) + }) + } } - }); - }); + ) + }) } -}); +}) diff --git a/content.js b/content.js index acc49c8..70ee1ba 100644 --- a/content.js +++ b/content.js @@ -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() } -}); +}) diff --git a/manifest.json b/manifest.json index f0bd3fa..7d603ec 100644 --- a/manifest.json +++ b/manifest.json @@ -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" }, @@ -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"] } diff --git a/styles.css b/styles.css index 838b79e..0879a7f 100644 --- a/styles.css +++ b/styles.css @@ -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; }