├── .gitignore ├── src ├── .DS_Store ├── icons │ └── chat-128.png ├── html │ └── popup.html └── js │ ├── background.js │ ├── highlight.js │ └── popup.js ├── README.md ├── manifest.json └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyishi/gpt-index-extension/HEAD/src/.DS_Store -------------------------------------------------------------------------------- /src/icons/chat-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongyishi/gpt-index-extension/HEAD/src/icons/chat-128.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gpt-index-extension 2 | GPT Index Extension for Google Chrome 3 | 4 | To use: 5 | 1. Download this repo as a ZIP file from GitHub. 6 | 2. Unzip the file and you should have a folder named gpt-index-extension. 7 | 3. In Chrome go to the extensions page (chrome://extensions). 8 | 4. Enable Developer Mode. 9 | 5. Click on Load Unpacked and choose the extension folder. 10 | 11 | This extension asks for your OpenAI API key to use during webpage indexing and querying. Specifically it's only passed into the LangChain function call and never stored server side. You can also leave the API field blank and it will use mine, but please don't abuse or I will remove that feature. 12 | -------------------------------------------------------------------------------- /src/html/popup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 |in the document 75 | lineIndexStart = innerHTML.indexOf("
", index) + "
".length; 76 | lineIndexEnd = innerHTML.indexOf("
", lineIndexStart); 77 | // console.log("lineIndexStart: " + lineIndexStart); 78 | // console.log("lineIndexEnd: " + lineIndexEnd); 79 | // console.log(innerHTML.substring(lineIndexStart, lineIndexEnd)); 80 | document.body.innerHTML = innerHTML.slice(0, lineIndexStart) + "" + innerHTML.substring(lineIndexStart, lineIndexEnd) + "" + innerHTML.substring(lineIndexEnd); 81 | innerHTML = document.body.innerHTML; 82 | index = lineIndexEnd; 83 | } 84 | } 85 | else{ 86 | // console.log("lineIndexStart: " + lineIndexStart); 87 | // console.log("lineIndexEnd: " + lineIndexEnd); 88 | document.body.innerHTML = innerHTML.slice(0, lineIndexStart) + "" + innerHTML.substring(lineIndexStart, lineIndexEnd) + "" + innerHTML.substring(lineIndexEnd); 89 | } 90 | // console.log(document.body.innerHTML); 91 | document.querySelector("mark").scrollIntoView(); 92 | } 93 | } 94 | }; 95 | 96 | chrome.runtime.onMessage.addListener( 97 | function(request, sender, sendResponse) { 98 | if (request.message === "highlight") { 99 | console.log("highlight"); 100 | highlight(request.sourceText); 101 | } 102 | return true; 103 | } 104 | ); -------------------------------------------------------------------------------- /src/js/popup.js: -------------------------------------------------------------------------------- 1 | window.onload = function () { 2 | document.getElementById("index-button").addEventListener("click", indexWebPage); 3 | document.getElementById("query-button").addEventListener("click", sendQuery); 4 | chrome.storage.local.get(["query_response"]).then((result) => { 5 | console.log("Value currently is " + result.query_response); 6 | if( typeof result.query_response === 'undefined' || result.query_response === null ) { 7 | console.log('result.query_response is undefined or null'); 8 | } 9 | else { 10 | document.getElementById("query-results").innerHTML = result.query_response; 11 | } 12 | }); 13 | } 14 | 15 | // index web page 16 | function indexWebPage() { 17 | document.getElementById("index-button").disabled = true; 18 | console.log("index web page"); 19 | 20 | // // Get user's OpenAI API key 21 | var apiKey = document.getElementById("api-key-input").value; 22 | // if (apiKey == "") { 23 | // alert("Please enter your OpenAI API key"); 24 | // return; 25 | // } 26 | (async () => { 27 | const response = await chrome.runtime.sendMessage({ request: "url" }); 28 | // do something with response here, not outside the function 29 | console.log(response.response); 30 | var currentUrl = response.response; 31 | // Send a request to the server to check if the web page has already been indexed 32 | $.ajax({ 33 | url: "http://gptindexextensionserver-env.eba-ssmvy7mt.us-west-2.elasticbeanstalk.com/check-index", 34 | type: "POST", 35 | data: JSON.stringify({ 36 | url: currentUrl, 37 | apiKey: apiKey, 38 | }), 39 | headers: { 40 | "Content-Type": "application/json" 41 | }, 42 | success: function (response) { 43 | if (response === "True") { 44 | // Show query prompt 45 | document.getElementById("query-prompt").style.display = "block"; 46 | } else { 47 | // Send request to index web page 48 | $.ajax({ 49 | url: "http://gptindexextensionserver-env.eba-ssmvy7mt.us-west-2.elasticbeanstalk.com/index-webpage", 50 | type: "POST", 51 | data: JSON.stringify({ 52 | url: currentUrl, 53 | apiKey: apiKey 54 | }), 55 | headers: { 56 | "Content-Type": "application/json" 57 | }, 58 | success: function (response) { 59 | if (response === "done") { 60 | // Show query prompt 61 | document.getElementById("query-prompt").style.display = "block"; 62 | document.getElementById("index-button").disabled = false; 63 | } else { 64 | alert("Error indexing web page, please try again."); 65 | document.getElementById("index-button").disabled = false; 66 | } 67 | }, 68 | error: function (error) { 69 | alert("Error indexing web page, please try again."); 70 | document.getElementById("index-button").disabled = false; 71 | } 72 | }); 73 | } 74 | }, 75 | error: function (error) { 76 | alert("Error checking index status, please try again."); 77 | document.getElementById("index-button").disabled = false; 78 | } 79 | }); 80 | 81 | })(); 82 | 83 | } 84 | 85 | // Send query to server 86 | function sendQuery() { 87 | console.log("send query"); 88 | document.getElementById("query-button").disabled = true; 89 | 90 | // Get user's OpenAI API key 91 | var apiKey = document.getElementById("api-key-input").value; 92 | // if (apiKey == "") { 93 | // alert("Please enter your OpenAI API key"); 94 | // return; 95 | // } 96 | (async () => { 97 | const response = await chrome.runtime.sendMessage({ request: "url" }); 98 | // do something with response here, not outside the function 99 | console.log(response.response); 100 | var currentUrl = response.response; 101 | var query = document.getElementById("query-input").value; 102 | document.getElementById("query-results").innerHTML = "Querying..."; 103 | $.ajax({ 104 | url: "http://gptindexextensionserver-env.eba-ssmvy7mt.us-west-2.elasticbeanstalk.com/query", 105 | type: "POST", 106 | data: JSON.stringify({ 107 | url: currentUrl, 108 | query: query, 109 | apiKey: apiKey 110 | }), 111 | headers: { 112 | "Content-Type": "application/json" 113 | }, 114 | success: function (response) { 115 | console.log("query success response: " + response); 116 | // Display query results 117 | document.getElementById("query-results").innerHTML = response.response_str; 118 | chrome.storage.local.set({ query_response: response.response_str }).then(() => { 119 | console.log("Value is set to " + response.response_str); 120 | }); 121 | console.log("text_refs: " + response.text_refs) 122 | chrome.runtime.sendMessage({ request: "highlight", text_refs: response.text_refs }); 123 | 124 | document.getElementById("query-button").disabled = false; 125 | }, 126 | error: function (error) { 127 | alert("Error querying indexed web page, please try again."); 128 | document.getElementById("query-button").disabled = false; 129 | } 130 | }); 131 | })(); 132 | } --------------------------------------------------------------------------------