-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8e7e3ca
Showing
12 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# General | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { | ||
if (request.action === "fetchText") { | ||
// Use chrome.tabs.query to get the active tab in the current window | ||
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { | ||
// tabs[0] will be the active tab in the current window | ||
const currentTab = tabs[0]; | ||
chrome.scripting.executeScript({ | ||
target: { tabId: currentTab.id }, | ||
function: getTextFromPage | ||
}, (injectionResults) => { | ||
for (const frameResult of injectionResults) | ||
sendTextToApi(frameResult.result, sendResponse); | ||
}); | ||
}); | ||
return true; // Will respond asynchronously. | ||
} | ||
}); | ||
|
||
function getTextFromPage() { | ||
return document.body.innerText; | ||
} | ||
|
||
function sendTextToApi(text, sendResponse) { | ||
fetch('https://localhost:11434/api/generate', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify( | ||
{ | ||
model: "phi3", | ||
prompt: text, | ||
system: "Given text from a webpage, generate a brief summary. Answer in only plaintext format.", | ||
stream: false, | ||
} | ||
) | ||
}) | ||
.then(response => { | ||
// Log the text response for debugging purposes | ||
response.text().then(text => { | ||
console.log("Received text:", text); | ||
try { | ||
// Attempt to parse it as JSON | ||
const data = JSON.parse(text); | ||
if (data && data.response) { | ||
sendResponse(data.response.replace(/\n/g, "\n")); // Send only the "response" key with newline replaced by <br> | ||
} else { | ||
sendResponse("No response found."); // Fallback text | ||
} | ||
} catch (e) { | ||
// Log parsing errors | ||
// console.error("Error parsing JSON:", e); | ||
console.error("Error parsing JSON:", text); | ||
sendResponse("Error in parsing response."); | ||
} | ||
}); | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
sendResponse("Error in fetching response."); // Error handling | ||
}); | ||
return true; // To allow asynchronous response | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// This file intentionally left blank as content injection is handled by background.js |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"manifest_version": 3, | ||
"name": "localsumm", | ||
"version": "0.1", | ||
"permissions": ["activeTab", "scripting"], | ||
"action": { | ||
"default_popup": "popup.html", | ||
"default_icon": { | ||
"16": "icon16.png", | ||
"48": "icon48.png", | ||
"128": "icon128.png" | ||
} | ||
}, | ||
"background": { | ||
"service_worker": "background.js" | ||
}, | ||
"content_scripts": [ | ||
{ | ||
"matches": ["<all_urls>"], | ||
"js": ["content.js"], | ||
"run_at": "document_idle" | ||
} | ||
], | ||
"icons": { | ||
"16": "icon16.png", | ||
"48": "icon48.png", | ||
"128": "icon128.png" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<link rel="preconnect" href="https://fonts.googleapis.com"> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap" rel="stylesheet"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css"> | ||
<title>API Response</title> | ||
<style> | ||
h1 { | ||
font-family: "JetBrains Mono", monospace; | ||
font-size: 3.4em; | ||
} | ||
body { | ||
width: 600px; | ||
height: 400px; | ||
margin: 10px; | ||
} | ||
#output { | ||
overflow-y: auto; /* Adds a scrollbar if text is too long */ | ||
font-size: 1.4em; | ||
} | ||
.blink_me { | ||
animation: blinker 1.5s linear infinite; | ||
} | ||
|
||
@keyframes blinker { | ||
50% { | ||
opacity: 0; | ||
} | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1><span style="color: darkorange">local</span><span style="color: teal">summ</span></h1> | ||
<hr> | ||
<div id="output"> | ||
<center> | ||
<h2 class="blink_me">Summarizing...</h2> | ||
<h3 class="blink_me">Model: Phi3</h3> | ||
<img src="icon512.png" style="width:240px" class="no_blink_me"/> | ||
</center> | ||
</div> | ||
<script src="popup.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
chrome.runtime.sendMessage({ action: "fetchText" }, function(response) { | ||
document.getElementById('output').textContent = response; | ||
}); | ||
}); |