// ==UserScript== // @name 算法思维树 // @namespace http://falcon.ictbda.cn:89/yoriko/ // @version 0.1 // @description 添加快捷指令(prompts)【打开 prompt 面板】:单击侧边栏的 “Algorithm Tree” 按钮,或者用快捷键 `command+shift+F` (Windows 用户使用 `ctrl+shift+F`)。 【输入 prompt】: 单击想要输入的 prompt 即可。prompt 会添加在输入框之前。 // @author TAIST // @match https://poe.com/* // @match https://chat.openai.com/* // @match http://falcon.ictbda.cn:89/yoriko/* // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @license MIT // @grant GM_addStyle // @downloadURL none // ==/UserScript== (function() { 'use strict'; var isDragging = false; var offsetX, offsetY; // Define the prompts var prompts = [ {'label': "提出一个数学(算法) 问题", 'content': "我想让你充当数学和算法研究专家。当我问你一个数学(算法)问题,而你的工作就是想出为我解决问题的策略。这可能包括建议代码、代码逻辑思路策略和数学推导,你可以帮助我解决问题吗?" }, {'label': "请给出这个问题的精确解",'content': "请给出这个问题的精确解,若无精确解,回答不存在精确解 " }, {'label': "该问题是否是优化问题", 'content': "该问题是否是优化问题?"}, {'label': "请写出这个问题的子问题",'content':"请写出这个问题的子问题。"}, {'label': '该问题有相互独立的子问题,还是有重叠的子问题', 'content': "该问题有相互独立的子问题吗,还是有重叠的子问题吗?"}, {'label': '请使用分治算法解决', 'content': "请使用分治算法解决。"}, {'label': '请写出这个问题的最优子结构', 'content': "请写出这个问题的最优子结构。"}, {'label': '该问题的最优解能通过局部最优选择来达成吗', 'content': "该问题的最优解能通过局部最优选择来达成吗?"}, {'label':'请使用动态规划算法解决','content': `请使用动态规划算法解决。在使用动态规划算法解题时,请先回答以下7个问题,然后根据问题答案给出一个最优的动态规划算法: (1)请写出这个问题在算法中的子问题。 (2)根据这个子问题写出状态转移方程。 (3)写出算法中最优决策项之间的联系。 (4)用以算代存的方法节省存储空间修改算法。 (5)这个算法可以节省时间吗? (6)请写出OPT表中的回溯路径。 (7) 请写出OPT表中的值的规律。是稀疏的吗? (8)请将根据最优关系的规律将动态规划算法改写为贪心算法`}, {'label':"请使用贪心算法解决", 'content':`请使用贪心算法解决 (1) 请将算法目标拆分为多步小目标 (2)求出每个小目标的局部最优解 (3)将局部最优解合成为原问题的解`}, {'label': '请分解解的邻域', 'content': '请分解解的邻域'}, {'label': '请求出尽量逼近正解的解的邻域', 'content': '请求出尽量逼近正解的解的邻域'}, {'label':"请使用线性规划算法解决",'content':`请使用线性规划算法解决。 (1)请将原问题按照if x=1 OR z=0 then y=1的形式描述为自然语言 (2)将自然语言表述为线性不等式。 (3)在目标函数中添加配合项`}, {'label': '权衡问题,是否有好求解的近似解', 'content': '请你权衡问题,是否有好求解的近似解?'}, {'label': '请使用算法解出一个相对好的近似解', 'content': '请使用算法解出一个相对好的近似解。'}, {'label': '请将求最优的问题转化为接近最优的并写出算法', 'content': '请将求最优的问题转化为接近最优的并写出算法。'}, {'label': '请将确定性的问题转化为随机的并写出算法', 'content': '请将确定性的问题转化为随机的并写出算法。'}, {'label': '请将最坏的案例转化为具体的案例并写出算法', 'content': '请将最坏的案例转化为具体的案例并写出算法。'}, {'label': '请将求确定理论规则的问题转化为启发式的并写出算法', 'content': '请将求确定理论规则的问题转化为启发式的并写出算法。'}, {'label': '(按可行方式)求解问题', 'content': '请你写出你认为可行的方式求解此问题'} ]; //创建文本容器 var container = document.createElement('div'); container.style.position = 'fixed'; container.style.top = '50%'; container.style.right = '20px'; container.style.transform = 'translateY(-60%)'; container.style.width = '250px'; container.style.height = '500px'; container.style.background = '#E8E8E8'; container.style.borderRadius = '5px'; container.style.padding = '10px'; container.style.display = 'none'; container.style.overflow = 'auto'; container.style.zIndex = '9999'; document.body.appendChild(container); GM_addStyle(` .custom-button { width: 250px; /* 设置统一的宽度,根据需要调整 */ } `); // 创建文本块 prompts.forEach(function(prompt) { var promptButton = document.createElement('button'); promptButton.textContent = prompt.label; promptButton.className = 'custom-button'; promptButton.style.display = 'block'; promptButton.style.marginBottom = '5px'; promptButton.style.background = '#A8A8A8 '; promptButton.style.color = 'white'; promptButton.style.border = 'none'; promptButton.style.borderRadius = '5px'; promptButton.style.padding = '5px'; promptButton.style.cursor = 'pointer'; promptButton.addEventListener('click', function() { insertPrompt(prompt.content); }); container.appendChild(promptButton); }); //插入文本框 function insertPrompt(content) { var inputBox = document.querySelector('input[type="text"], textarea'); if (inputBox) { var startPos = inputBox.selectionStart; var endPos = inputBox.selectionEnd; var text = inputBox.value; var newText = text.substring(0, startPos) + content + text.substring(endPos, text.length); inputBox.value = newText; inputBox.setSelectionRange(startPos + content.length, startPos + content.length); inputBox.style.textAlign = 'left'; inputBox.style.height = inputBox.scrollHeight + 'px'; // 添加定时器 setTimeout(function () { const isAutoSend = document.getElementById('isAutoSend').checked; if (isAutoSend) { const keyEvent = new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true, keyCode: 13, }); inputBox.dispatchEvent(keyEvent); } else { inputBox.focus(); } }, 1000); // 1 秒延迟 } } // 创建按钮Algorithm Tree var button = document.createElement('textarea'); button.style.position = 'fixed'; button.style.bottom = '60px'; button.style.right = '20px'; button.style.width = '200px'; button.style.height = '30px'; button.style.background = ' #E8E8E8'; button.style.color = 'black'; button.style.border = 'none'; button.style.borderRadius = '5px'; button.style.padding = '10px'; button.style.resize = 'none'; button.readOnly = true; button.style.font = '16px Bodoni'; button.style.textAlign = 'center'; //button.placeholder = ' -- Algorithm Tree --'; button.textContent = ' -- Algorithm Tree --'; button.style.zIndex = '9999'; document.body.appendChild(button); // 添加鼠标悬停事件监听器 button.addEventListener('mouseenter', function() { button.style.cursor = 'move'; // 鼠标形状变为移动行 }); button.addEventListener('mouseleave', function() { button.style.cursor = 'default'; // 鼠标形状恢复默认 }); // 点击按钮 button.addEventListener('click', function() { if (container.style.display === 'none') { container.style.display = 'block'; } else { container.style.display = 'none'; } }); // 移动按钮 button.addEventListener('mousedown', function (event) { isDragging = true; offsetX = event.clientX - button.getBoundingClientRect().left; offsetY = event.clientY - button.getBoundingClientRect().top; }); document.addEventListener('mousemove', function (event) { if (isDragging) { button.style.left = event.clientX - offsetX + 'px'; button.style.top = event.clientY - offsetY + 'px'; } }); document.addEventListener('mouseup', function () { isDragging = false; }); // 使用 Ctrl+Shift+F 或 Cmd+Shift+F 打开或关闭 document.addEventListener('keydown', function(event) { if ((event.ctrlKey || event.metaKey) && event.shiftKey && event.key === 'F') { event.preventDefault(); if (container.style.display === 'none') { container.style.display = 'block'; } else { container.style.display = 'none'; } } }); })();