Commit 1e413c8d authored by chenghong_tao's avatar chenghong_tao

优化嵌入文件

parent 2b895f7e
(function() {
// 获取URL
const urlParams = new URLSearchParams(window.location.search);
const baseUrl = urlParams.get('url') || 'https://tk-test.infi-inside.com:2443';
// 优先用 document.currentScript(现代浏览器支持),不支持则回退方案使用遍历匹配(兼容旧浏览器)
const currentScript = document.currentScript || Array.from(document.scripts).find(script => script.src.endsWith('embed.min.js'));
if (!currentScript) {
console.error('无法获取当前脚本标签');
return;
}
let baseUrl = '';
try {
// 处理相对路径(如 src="./embed.js")
const scriptUrl = new URL(currentScript.src, location.href);
baseUrl = scriptUrl.searchParams.get('url');
if (!baseUrl) {
console.error('未找到URL参数');
return;
}
// 在这里使用 baseUrl...
} catch (error) {
console.error('解析URL失败:', error);
}
// 创建悬浮按钮
const button = document.createElement('button');
button.id = 'chatbot-bubble-button';
button.style.position = 'fixed';
button.style.bottom = '20px';
button.style.bottom = '10px';
button.style.right = '20px';
button.style.width = '50px';
button.style.height = '50px';
......@@ -22,8 +39,8 @@
// Create an img element
const img = document.createElement('img');
img.src = baseUrl + '/deepseek.png'; // Replace with the path to your image
img.style.width = '60px';
img.src = baseUrl + '/ai_icon.png'; // Replace with the path to your image
img.style.width = '50px';
// img.style.height = '100%';
img.style.objectFit = 'cover';
......@@ -36,7 +53,7 @@
const iframeContainer = document.createElement('div');
iframeContainer.id = 'chatbot-bubble-window';
iframeContainer.style.position = 'fixed';
iframeContainer.style.bottom = '80px';
iframeContainer.style.bottom = '60px';
iframeContainer.style.right = '20px';
iframeContainer.style.width = '650px'; // 24rem
iframeContainer.style.height = '85%'; // 40rem
......@@ -49,26 +66,29 @@
// 创建关闭按钮并插入SVG
const closeButton = document.createElement('button');
closeButton.style.position = 'absolute';
closeButton.style.top = '15px';
closeButton.style.right = '5px';
closeButton.style.width = '20px';
closeButton.style.height = '20px';
closeButton.style.top = 'calc(22px - 5px)';
closeButton.style.right = '7px';
closeButton.style.width = '14px';
closeButton.style.height = '14px';
closeButton.style.border = 'none';
closeButton.style.backgroundColor = 'transparent';
closeButton.style.cursor = 'pointer';
closeButton.style.outline = 'none';
closeButton.style.padding = '0';
closeButton.style.margin = '0';
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svg.setAttribute("t", "1745391895314");
svg.setAttribute("class", "icon");
// svg.setAttribute("class", "icon");
svg.setAttribute("viewBox", "0 0 1024 1024");
svg.setAttribute("version", "1.1");
svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
svg.setAttribute("width", "16");
svg.setAttribute("height", "16");
svg.setAttribute("width", "14");
svg.setAttribute("height", "14");
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
path.setAttribute("d", "M512 0C229.273 0 0 229.273 0 512s229.273 512 512 512 512-229.273 512-512S794.727 0 512 0z m241.36 701.668a36.571 36.571 0 1 1-51.715 51.715L512 563.715 322.355 753.36a36.571 36.571 0 1 1-51.715-51.715L460.285 512 270.64 322.355a36.571 36.571 0 0 1 51.715-51.715L512 460.285 701.645 270.64a36.571 36.571 0 0 1 51.715 51.715L563.715 512z");
path.setAttribute("fill", "#D81E06");
path.setAttribute("fill", "#d55444");
svg.appendChild(path);
closeButton.appendChild(svg);
......@@ -99,4 +119,13 @@
closeButton.addEventListener('click', () => {
iframeContainer.style.display = 'none';
});
// 关闭按钮鼠标移入效果
closeButton.addEventListener('mouseenter', () => {
// 设置svg颜色
path.setAttribute("fill", "#D81E06");
});
// 关闭按钮鼠标移出效果
closeButton.addEventListener('mouseleave', () => {
path.setAttribute("fill", "#d55444");
});
})();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment