需要管理员权限来操作 1、进入管理中心,点击右上角【新建插件】 2、填写相关信息后点击【确定】 3、找到刚刚创建的插件,点击【编辑代码】按钮来添加代码
4、将以下代码复制到文本框中,点击【确定】。 如果要限制只有编辑者才能看到的话需要把代码中第8行const editorOnly = false; 修改为 const editorOnly = true; - GD.on('gd-ready', () => {
- const isMobileUrl = window.location.pathname.startsWith('/m');
- if (isMobileUrl) {
- return;
- }
-
- // 如果要限制只有编辑者才可以看到的话需要把下面这行的false改成true
- const editorOnly = false;
- const userInfo = GD.getUser();
- if (userInfo.role[0] === 'participant' && editorOnly) {
- return;
- }
- const innerWidth = window.innerWidth;
- const userAgent = navigator.userAgent || navigator.vendor || window.opera;
- const isMobile = /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(userAgent.toLowerCase()) || innerWidth < 480;
- const isPrintPage = window.location.pathname.includes('/print');
- if (window.self === window.top && !isMobile && !isPrintPage) {
- // Create a button and append it to the document body
- const button = document.createElement('div');
- button.style.position = 'fixed';
- button.style.bottom = '20px';
- button.style.right = '10px';
- button.style.backgroundColor = '#fff';
- button.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
- button.style.cursor = 'pointer';
- button.style.padding = '8px 8px';
- button.style.borderRadius = '30px';
- button.style.display = 'flex';
- button.style.flexDirection = 'column';
- button.style.alignItems = 'center';
- button.style.zIndex = 1000;
- document.body.appendChild(button);
-
- // Modify the button to include an image and text in a vertical layout
- button.innerHTML = '';
-
- const dragSvg = '<svg t="1743060843660" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3628" width="14"><path fill="#00bebe" d="M219.428571 585.142857c-36.571429 0-73.142857 36.571429-73.142857 73.142857s36.571429 73.142857 73.142857 73.142857 73.142857-36.571429 73.142858-73.142857-36.571429-73.142857-73.142858-73.142857z m585.142858-146.285714c36.571429 0 73.142857-36.571429 73.142857-73.142857s-36.571429-73.142857-73.142857-73.142857-73.142857 36.571429-73.142858 73.142857 36.571429 73.142857 73.142858 73.142857zM219.428571 292.571429c-36.571429 0-73.142857 36.571429-73.142857 73.142857s36.571429 73.142857 73.142857 73.142857 73.142857-36.571429 73.142858-73.142857-36.571429-73.142857-73.142858-73.142857z m585.142858 292.571428c-36.571429 0-73.142857 36.571429-73.142858 73.142857s36.571429 73.142857 73.142858 73.142857 73.142857-36.571429 73.142857-73.142857-36.571429-73.142857-73.142857-73.142857zM512 292.571429c-36.571429 0-73.142857 36.571429-73.142857 73.142857s36.571429 73.142857 73.142857 73.142857 73.142857-36.571429 73.142857-73.142857-36.571429-73.142857-73.142857-73.142857z m0 292.571428c-36.571429 0-73.142857 36.571429-73.142857 73.142857s36.571429 73.142857 73.142857 73.142857 73.142857-36.571429 73.142857-73.142857-36.571429-73.142857-73.142857-73.142857z" p-id="3629"></path></svg>'
-
- const dragContainer = document.createElement('div');
- dragContainer.innerHTML = dragSvg;
- dragContainer.style.display = 'block';
- dragContainer.style.margin = '0 auto';
-
- const text = document.createElement('div');
- text.innerText = 'AI助手';
- text.style.color = '#00bebe';
- text.style.width = '16px';
- text.style.display = 'block';
- text.style.textAlign = 'center';
-
- button.appendChild(dragContainer);
- button.appendChild(text);
- // 添加拖拽功能
- let isDragging = false;
- let currentX;
- let currentY;
- let initialX;
- let initialY;
- let xOffset = 0;
- let yOffset = 0;
- let hasMoved = false;
- button.addEventListener('mousedown', dragStart, { passive: false, capture: true });
- document.addEventListener('mousemove', drag, { passive: false, capture: true });
- document.addEventListener('mouseup', dragEnd);
- function dragStart(e) {
- e.preventDefault();
- e.stopPropagation();
- initialX = e.clientX - xOffset;
- initialY = e.clientY - yOffset;
- hasMoved = false;
- if (e.target === button || button.contains(e.target)) {
- isDragging = true;
- button.style.backgroundColor = 'rgba(255, 255, 255, 0.9)';
- button.style.boxShadow = '0 0 15px rgba(0, 190, 190, 0.3)';
- button.style.border = '1px solid #00bebe';
- }
- }
- function drag(e) {
- if (isDragging) {
- e.preventDefault();
- e.stopPropagation();
- currentX = e.clientX - initialX;
- currentY = e.clientY - initialY;
- if (Math.abs(currentX) > 5 || Math.abs(currentY) > 5) {
- hasMoved = true;
- }
- xOffset = currentX;
- yOffset = currentY;
- setTranslate(currentX, currentY, button);
- }
- }
- function setTranslate(xPos, yPos, el) {
- el.style.transform = `translate3d(${xPos}px, ${yPos}px, 0)`;
- }
- function dragEnd(e) {
- if (e) {
- e.preventDefault();
- }
- initialX = currentX;
- initialY = currentY;
- isDragging = false;
- button.style.backgroundColor = '#fff';
- button.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
- button.style.border = 'none';
- }
-
- // Add event listener to the button to show the modal
- button.addEventListener('click', () => {
- if (!hasMoved) {
- modal.style.display = 'block';
- }
- });
- }
-
- // Create a modal container
- const modal = document.createElement('div');
- modal.style.position = 'fixed';
- modal.style.bottom = '0px';
- modal.style.right = '0px';
- modal.style.width = '480px';
- modal.style.height = '100vh';
- modal.style.backgroundColor = 'white';
- modal.style.border = '1px solid #e7e9e8';
- modal.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
- modal.style.zIndex = '1000';
- modal.style.display = 'none'; // Initially hidden
-
- // Create a head container
- const head = document.createElement('div');
- head.style.display = 'flex';
- head.style.justifyContent = 'space-between';
- head.style.alignItems = 'center';
- head.style.height = '48px';
- head.style.padding = '0 12px';
- head.style.borderBottom = '1px solid #e7e9e8';
- head.style.backgroundColor = '#fafafa';
-
- // Create a title for the modal
- const title = document.createElement('span');
- title.innerText = 'AI助手';
- title.style.color = '#00bebe';
- title.style.fontSize = '16px';
- title.style.fontWeight = '500';
- head.appendChild(title);
-
- // Create a close button and append it to the head
- const closeButton = document.createElement('span');
- closeButton.innerText = '关闭';
- closeButton.style.color = '#00bebe';
- closeButton.style.cursor = 'pointer';
- head.appendChild(closeButton);
-
- // Append the head to the modal
- modal.appendChild(head);
-
- // Create an iframe and append it to the modal
- const iframe = document.createElement('iframe');
- iframe.src = 'https://robot.guandata.com/galaxy' + '?cid=' + window.location.host + '&uid=' + userInfo.uId;
- iframe.style.width = '100%';
- iframe.style.height = 'calc(100vh - 48px)'; // Adjust height to account for head
- modal.appendChild(iframe);
-
- // Append the modal to the document body
- document.body.appendChild(modal);
-
- // Add event listener to the close button to hide the modal
- closeButton.addEventListener('click', () => {
- modal.style.display = 'none';
- });
- })
复制代码
5、通过点击【本地调试】进行本地浏览器测试,测试通过后切换【应用状态】到开启(绿色)即可发布
6、效果如图所示,如果页面上没有出现,可以强制刷新、清理缓存或者重启浏览器
7、有任何问题或者建议都可以通过点击此处进行反馈
|