chrome extensions (#4308)
Browse filesBuild chrome extensions that allow interaction with browser content
- intergrations/extension_chrome/README.md +45 -0
- intergrations/extension_chrome/assets/logo-with-text.png +0 -0
- intergrations/extension_chrome/assets/logo.png +0 -0
- intergrations/extension_chrome/assets/logo.svg +29 -0
- intergrations/extension_chrome/background.js +17 -0
- intergrations/extension_chrome/content.js +68 -0
- intergrations/extension_chrome/icons/icon-128x128.png +0 -0
- intergrations/extension_chrome/icons/icon-16x16.png +0 -0
- intergrations/extension_chrome/icons/icon-48x48.png +0 -0
- intergrations/extension_chrome/manifest.json +34 -0
- intergrations/extension_chrome/options.html +39 -0
- intergrations/extension_chrome/options.js +36 -0
- intergrations/extension_chrome/popup.html +20 -0
- intergrations/extension_chrome/popup.js +24 -0
- intergrations/extension_chrome/styles/options.css +91 -0
- intergrations/extension_chrome/styles/popup.css +20 -0
intergrations/extension_chrome/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Chrome Extension
|
2 |
+
|
3 |
+
chrome-extension/
|
4 |
+
│
|
5 |
+
├── manifest.json # Main configuration file for the extension
|
6 |
+
├── popup.html # Main user interface of the extension
|
7 |
+
├── popup.js # Script for the main interface
|
8 |
+
├── background.js # Background script for the extension
|
9 |
+
├── content.js # Script to interact with web pages
|
10 |
+
├── styles/
|
11 |
+
│ └── popup.css # CSS file for the popup
|
12 |
+
├── icons/
|
13 |
+
│ ├── icon16.png # 16x16 pixel icon
|
14 |
+
│ ├── icon48.png # 48x48 pixel icon
|
15 |
+
│ └── icon128.png # 128x128 pixel icon
|
16 |
+
├── assets/
|
17 |
+
│ └── ... # Directory for other assets (images, fonts, etc.)
|
18 |
+
├── scripts/
|
19 |
+
│ ├── utils.js # File containing utility functions
|
20 |
+
│ └── api.js # File containing API call logic
|
21 |
+
└── README.md # Instructions for using and installing the extension
|
22 |
+
|
23 |
+
|
24 |
+
# Installation
|
25 |
+
1. Open chrome://extensions/.
|
26 |
+
2. Enable Developer mode.
|
27 |
+
3. Click Load unpacked and select the project directory.
|
28 |
+
# Features
|
29 |
+
1. Interact with web pages.
|
30 |
+
2. Run in the background to handle logic.
|
31 |
+
# Usage
|
32 |
+
- Click the extension icon in the toolbar.
|
33 |
+
- Follow the instructions in the interface.
|
34 |
+
# Additional Notes
|
35 |
+
- **manifest.json**: This file is crucial as it defines the extension's metadata, permissions, and entry points.
|
36 |
+
- **background.js**: This script runs independently of any web page and can perform tasks such as listening for browser events, making network requests, and storing data.
|
37 |
+
- **content.js**: This script injects code into web pages to manipulate the DOM, modify styles, or communicate with the background script.
|
38 |
+
- **popup.html/popup.js**: These files create the popup that appears when the user clicks the extension icon.
|
39 |
+
icons: These icons are used to represent the extension in the browser's UI.
|
40 |
+
More Detailed Explanation
|
41 |
+
- **manifest.json**: Specifies the extension's name, version, permissions, and other details. It also defines the entry points for the background script, content scripts, and the popup.
|
42 |
+
- **background.js**: Handles tasks that need to run continuously, such as syncing data, listening for browser events, or controlling the extension's behavior.
|
43 |
+
- **content.js**: Interacts directly with the web page's DOM, allowing you to modify the content, style, or behavior of the page.
|
44 |
+
- **popup.html/popup.js**: Creates a user interface that allows users to interact with the extension.
|
45 |
+
Other files: These files can contain additional scripts, styles, or assets that are used by the extension.
|
intergrations/extension_chrome/assets/logo-with-text.png
ADDED
![]() |
intergrations/extension_chrome/assets/logo.png
ADDED
![]() |
intergrations/extension_chrome/assets/logo.svg
ADDED
|
intergrations/extension_chrome/background.js
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
chrome.runtime.onInstalled.addListener(() => {
|
2 |
+
console.log("Tiện ích đã được cài đặt!");
|
3 |
+
});
|
4 |
+
|
5 |
+
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
6 |
+
if (message.action === "PAGE_INFO") {
|
7 |
+
console.log( message);
|
8 |
+
|
9 |
+
|
10 |
+
chrome.storage.local.set({ pageInfo: message }, () => {
|
11 |
+
console.log("Page info saved to local storage.");
|
12 |
+
});
|
13 |
+
|
14 |
+
// Send a response to the content script
|
15 |
+
sendResponse({ status: "success", message: "Page info received and processed." });
|
16 |
+
}
|
17 |
+
});
|
intergrations/extension_chrome/content.js
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function () {
|
2 |
+
const extractElementData = (el) => {
|
3 |
+
const tag = el.tagName.toLowerCase();
|
4 |
+
if (
|
5 |
+
tag === "input" &&
|
6 |
+
el.name !== "DXScript" &&
|
7 |
+
el.name !== "DXMVCEditorsValues" &&
|
8 |
+
el.name !== "DXCss"
|
9 |
+
) {
|
10 |
+
return {
|
11 |
+
type: "input",
|
12 |
+
name: el.name,
|
13 |
+
value:
|
14 |
+
el.type === "checkbox" || el.type === "radio"
|
15 |
+
? el.checked
|
16 |
+
? el.value
|
17 |
+
: null
|
18 |
+
: el.value,
|
19 |
+
};
|
20 |
+
} else if (tag === "select") {
|
21 |
+
const selectedOption = el.querySelector("option:checked");
|
22 |
+
return {
|
23 |
+
type: "select",
|
24 |
+
name: el.name,
|
25 |
+
value: selectedOption ? selectedOption.value : null,
|
26 |
+
};
|
27 |
+
} else if (tag.startsWith("h") && el.textContent.trim()) {
|
28 |
+
return { type: "header", tag, content: el.textContent.trim() };
|
29 |
+
} else if (
|
30 |
+
["label", "span", "p", "b", "strong"].includes(tag) &&
|
31 |
+
el.textContent.trim()
|
32 |
+
) {
|
33 |
+
return { type: tag, content: el.textContent.trim() };
|
34 |
+
}
|
35 |
+
};
|
36 |
+
|
37 |
+
const getElementValues = (els) =>
|
38 |
+
Array.from(els).map(extractElementData).filter(Boolean);
|
39 |
+
|
40 |
+
const getIframeInputValues = (iframe) => {
|
41 |
+
try {
|
42 |
+
const iframeDoc = iframe.contentWindow.document;
|
43 |
+
return getElementValues(
|
44 |
+
iframeDoc.querySelectorAll("input, select, header, label, span, p")
|
45 |
+
);
|
46 |
+
} catch (e) {
|
47 |
+
console.error("Can't access iframe:", e);
|
48 |
+
return [];
|
49 |
+
}
|
50 |
+
};
|
51 |
+
|
52 |
+
const inputValues = getElementValues(
|
53 |
+
document.querySelectorAll("input, select, header, label, span, p")
|
54 |
+
);
|
55 |
+
const iframeInputValues = Array.from(document.querySelectorAll("iframe")).map(
|
56 |
+
getIframeInputValues
|
57 |
+
);
|
58 |
+
|
59 |
+
return `
|
60 |
+
## input values\n
|
61 |
+
\`\`\`json\n
|
62 |
+
${JSON.stringify(inputValues)}\n
|
63 |
+
\`\`\`\n
|
64 |
+
## iframe input values\n
|
65 |
+
\`\`\`json\n
|
66 |
+
${JSON.stringify(iframeInputValues)}\n
|
67 |
+
\`\`\``;
|
68 |
+
})();
|
intergrations/extension_chrome/icons/icon-128x128.png
ADDED
![]() |
intergrations/extension_chrome/icons/icon-16x16.png
ADDED
![]() |
intergrations/extension_chrome/icons/icon-48x48.png
ADDED
![]() |
intergrations/extension_chrome/manifest.json
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"manifest_version": 3,
|
3 |
+
"name": "Ragflow Extension",
|
4 |
+
"description": "Ragflow for Chrome",
|
5 |
+
"version": "1.0",
|
6 |
+
"options_page": "options.html",
|
7 |
+
|
8 |
+
"permissions": ["activeTab", "scripting", "storage"],
|
9 |
+
"background": {
|
10 |
+
"service_worker": "background.js"
|
11 |
+
},
|
12 |
+
|
13 |
+
"action": {
|
14 |
+
"default_popup": "popup.html",
|
15 |
+
"default_icon": {
|
16 |
+
"16": "icons/icon-16x16.png",
|
17 |
+
"48": "icons/icon-48x48.png",
|
18 |
+
"128": "icons/icon-128x128.png"
|
19 |
+
}
|
20 |
+
},
|
21 |
+
|
22 |
+
"content_scripts": [
|
23 |
+
{
|
24 |
+
"matches": ["<all_urls>"],
|
25 |
+
"js": ["content.js"],
|
26 |
+
"css": ["styles/popup.css"]
|
27 |
+
}
|
28 |
+
],
|
29 |
+
"icons": {
|
30 |
+
"16": "icons/icon-16x16.png",
|
31 |
+
"48": "icons/icon-48x48.png",
|
32 |
+
"128": "icons/icon-128x128.png"
|
33 |
+
}
|
34 |
+
}
|
intergrations/extension_chrome/options.html
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<meta charset="UTF-8" />
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7 |
+
<title>RagFlow option</title>
|
8 |
+
<link rel="stylesheet" href="styles/options.css" />
|
9 |
+
</head>
|
10 |
+
|
11 |
+
<body id="ragflow">
|
12 |
+
<div id="form-config">
|
13 |
+
<div class="header">
|
14 |
+
<img src="assets/logo-with-text.png" alt="Logo" class="logo" />
|
15 |
+
</div>
|
16 |
+
<div class="content">
|
17 |
+
<label for="base-url">Base URL:</label>
|
18 |
+
<input type="text" id="base-url" placeholder="Enter base URL" />
|
19 |
+
|
20 |
+
<label for="from">From:</label>
|
21 |
+
<select id="from">
|
22 |
+
<option selected value="agent">agent</option>
|
23 |
+
<option value="chat">chat</option>
|
24 |
+
</select>
|
25 |
+
|
26 |
+
<label for="auth">Auth:</label>
|
27 |
+
<input type="text" id="auth" placeholder="Enter auth" />
|
28 |
+
|
29 |
+
<label for="shared-id">Shared ID:</label>
|
30 |
+
<input type="text" id="shared-id" placeholder="Enter shared ID" />
|
31 |
+
|
32 |
+
<button id="save-config">🛖</button>
|
33 |
+
|
34 |
+
</div>
|
35 |
+
</div>
|
36 |
+
<script src="options.js"></script>
|
37 |
+
</body>
|
38 |
+
|
39 |
+
</html>
|
intergrations/extension_chrome/options.js
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
document.addEventListener("DOMContentLoaded", () => {
|
2 |
+
|
3 |
+
chrome.storage.sync.get(["baseURL", "from", "auth", "sharedID"], (result) => {
|
4 |
+
if (result.baseURL) {
|
5 |
+
document.getElementById("base-url").value = result.baseURL;
|
6 |
+
}
|
7 |
+
if (result.from) {
|
8 |
+
document.getElementById("from").value = result.from;
|
9 |
+
}
|
10 |
+
if (result.auth) {
|
11 |
+
document.getElementById("auth").value = result.auth;
|
12 |
+
}
|
13 |
+
if (result.sharedID) {
|
14 |
+
document.getElementById("shared-id").value = result.sharedID;
|
15 |
+
}
|
16 |
+
});
|
17 |
+
|
18 |
+
document.getElementById("save-config").addEventListener("click", () => {
|
19 |
+
const baseURL = document.getElementById("base-url").value;
|
20 |
+
const from = document.getElementById("from").value;
|
21 |
+
const auth = document.getElementById("auth").value;
|
22 |
+
const sharedID = document.getElementById("shared-id").value;
|
23 |
+
|
24 |
+
chrome.storage.sync.set(
|
25 |
+
{
|
26 |
+
baseURL: baseURL,
|
27 |
+
from: from,
|
28 |
+
auth: auth,
|
29 |
+
sharedID: sharedID,
|
30 |
+
},
|
31 |
+
() => {
|
32 |
+
alert("Successfully saved");
|
33 |
+
}
|
34 |
+
);
|
35 |
+
});
|
36 |
+
});
|
intergrations/extension_chrome/popup.html
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<meta charset="utf-8" />
|
6 |
+
<meta name="viewport"
|
7 |
+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
|
8 |
+
<title>RAGFLOW</title>
|
9 |
+
<link rel="stylesheet" href="styles/popup.css" />
|
10 |
+
</head>
|
11 |
+
|
12 |
+
<body id="ragflow">
|
13 |
+
<div class="window">
|
14 |
+
<textarea id="getHtml"></textarea>
|
15 |
+
<iframe src="" style="width: 100%; height: 100%; min-height: 600px" frameborder="0"></iframe>
|
16 |
+
</div>
|
17 |
+
<script src="popup.js"></script>
|
18 |
+
</body>
|
19 |
+
|
20 |
+
</html>
|
intergrations/extension_chrome/popup.js
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
document.addEventListener("DOMContentLoaded", () => {
|
2 |
+
chrome.storage.sync.get(["baseURL", "from", "auth", "sharedID"], (result) => {
|
3 |
+
if (result.baseURL && result.sharedID && result.from && result.auth) {
|
4 |
+
const iframeSrc = `${result.baseURL}chat/share?shared_id=${result.sharedID}&from=${result.from}&auth=${result.auth}`;
|
5 |
+
const iframe = document.querySelector("iframe");
|
6 |
+
iframe.src = iframeSrc;
|
7 |
+
}
|
8 |
+
});
|
9 |
+
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
10 |
+
chrome.scripting.executeScript(
|
11 |
+
{
|
12 |
+
target: { tabId: tabs[0].id },
|
13 |
+
files: ["content.js"],
|
14 |
+
},
|
15 |
+
(results) => {
|
16 |
+
if (results && results[0]) {
|
17 |
+
const getHtml = document.getElementById("getHtml");
|
18 |
+
getHtml.value = results[0].result;
|
19 |
+
|
20 |
+
}
|
21 |
+
}
|
22 |
+
);
|
23 |
+
});
|
24 |
+
});
|
intergrations/extension_chrome/styles/options.css
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#ragflow {
|
2 |
+
font-family: "Segoe UI", Arial, sans-serif;
|
3 |
+
margin: 0;
|
4 |
+
padding: 0;
|
5 |
+
display: flex;
|
6 |
+
justify-content: center;
|
7 |
+
align-items: center;
|
8 |
+
height: 600px;
|
9 |
+
}
|
10 |
+
|
11 |
+
#ragflow .window {
|
12 |
+
display: flex;
|
13 |
+
flex-direction: column;
|
14 |
+
justify-content: space-between;
|
15 |
+
flex: 1;
|
16 |
+
overflow: hidden;
|
17 |
+
}
|
18 |
+
#ragflow #form-config {
|
19 |
+
background-color: #fff;
|
20 |
+
box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
|
21 |
+
display: flex;
|
22 |
+
flex-direction: column;
|
23 |
+
justify-content: space-between;
|
24 |
+
overflow: hidden;
|
25 |
+
}
|
26 |
+
|
27 |
+
#ragflow .header {
|
28 |
+
background-color: #fff;
|
29 |
+
padding: 4px;
|
30 |
+
display: flex;
|
31 |
+
justify-content: space-between;
|
32 |
+
align-items: center;
|
33 |
+
flex-direction: row;
|
34 |
+
}
|
35 |
+
|
36 |
+
#ragflow .header .title {
|
37 |
+
font-size: 16px;
|
38 |
+
}
|
39 |
+
|
40 |
+
#ragflow .header .logo {
|
41 |
+
width: 100px; /* Adjust size as needed */
|
42 |
+
height: auto;
|
43 |
+
margin-right: 10px;
|
44 |
+
}
|
45 |
+
|
46 |
+
#ragflow .content {
|
47 |
+
padding: 20px;
|
48 |
+
display: flex;
|
49 |
+
flex-direction: column;
|
50 |
+
justify-content: space-between;
|
51 |
+
}
|
52 |
+
|
53 |
+
#ragflow label {
|
54 |
+
font-weight: bold;
|
55 |
+
margin-bottom: 5px;
|
56 |
+
}
|
57 |
+
|
58 |
+
#ragflow input,
|
59 |
+
#ragflow select {
|
60 |
+
width: 100%;
|
61 |
+
padding: 8px;
|
62 |
+
margin-bottom: 15px;
|
63 |
+
border: 1px solid #ccc;
|
64 |
+
border-radius: 5px;
|
65 |
+
box-sizing: border-box;
|
66 |
+
}
|
67 |
+
|
68 |
+
#ragflow button {
|
69 |
+
background-color: #0078d4;
|
70 |
+
color: #fff;
|
71 |
+
padding: 10px;
|
72 |
+
border: none;
|
73 |
+
border-radius: 5px;
|
74 |
+
cursor: pointer;
|
75 |
+
font-size: 14px;
|
76 |
+
}
|
77 |
+
|
78 |
+
#ragflow button:hover {
|
79 |
+
background-color: #005bb5;
|
80 |
+
}
|
81 |
+
|
82 |
+
#ragflow #config-button {
|
83 |
+
display: flex;
|
84 |
+
position: absolute;
|
85 |
+
top: 2px;
|
86 |
+
right: 2px;
|
87 |
+
font-size: 22px;
|
88 |
+
}
|
89 |
+
#ragflow #config-button:hover {
|
90 |
+
cursor: pointer;
|
91 |
+
}
|
intergrations/extension_chrome/styles/popup.css
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#ragflow {
|
2 |
+
font-family: "Segoe UI", Arial, sans-serif;
|
3 |
+
margin: 0;
|
4 |
+
padding: 0;
|
5 |
+
display: flex;
|
6 |
+
justify-content: center;
|
7 |
+
align-items: center;
|
8 |
+
width: 320px;
|
9 |
+
}
|
10 |
+
|
11 |
+
#ragflow .window {
|
12 |
+
display: flex;
|
13 |
+
flex-direction: column;
|
14 |
+
justify-content: space-between;
|
15 |
+
flex: 1;
|
16 |
+
overflow: hidden;
|
17 |
+
}
|
18 |
+
#ragflow #output {
|
19 |
+
position: absolute;
|
20 |
+
}
|