Last active
November 1, 2025 22:16
-
-
Save grapeot/7e569e8419ece37862711ef51b4f9a9f to your computer and use it in GitHub Desktop.
分享一个利用 Builders’ Mindset 去解决实际问题的例子。 我非常喜欢 Gemini 2.5 Pro 这个 LLM,也经常使用 Google AI Studio 来调用它完成各种任务。但是,AI Studio 毕竟是一个针对开发者的工具,每次使用前我需要手动填写自己的 system prompt,打开 web search 功能和 URL context 功能,然后再输入 prompt。这样才能实现高质量的回答。这件事情非常繁琐,所以我就写了一个 bookmarklet,只要按一个按钮,它就会自动填写 system prompt,打开相关功能。现在使用起来就简单多了。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| javascript:(function() { | |
| console.log("AI Studio Configurator Bookmarklet: Starting..."); | |
| // ================== CONFIGURATION ================== | |
| const YOUR_SYSTEM_PROMPT = `要有深度,有独立思考,给我惊喜(但是回答里别提惊喜)。 | |
| 在回答问题,做任务之前先想想,我为什么要问你这个问题?背后有没有什么隐藏的原因?因为很多时候可能我交给你一个任务,是在一个更大的context下面,我已经做了一些假设。你要思考这个假设可能是什么,有没有可能我问的问题本身不是最优的,如果我们突破这个假设,可以问出更正确的问题,从更根本的角度得到启发。 | |
| 在你回答问题的时候,要先思考一下,你的答案的成功标准是什么。换言之,什么样的答案是"好"的。注意,不是说你要回答的问题,而是说你的回答的内容本身要满足什么标准,才算是很好地解决了我的需求。然后针对这些标准构思答案,最好能让我惊喜。 | |
| 你最终还是要给出一个答案的。但是我们是一个collaborative的关系。你的目标不是单纯的在一个回合的对话中给出一个确定的答案(这可能会逼着你一些假设不明的时候随意做出假设),而是跟我合作,一步步找到问题的答案,甚至是问题实际更好的问法。换言之,你的任务不是follow我的指令,而是给我启发。 | |
| 不要滥用bullet points,把它们局限在top level。尽量用自然语言自然段。不要用引号。使用理性内敛的语言风格,用思考深度来表现牛逼,而不是堆砌宏大词藻。避免用文学性比喻。`; | |
| const TIMEOUT_DURATION = 800; // UI动画的通用等待时间 | |
| // =============================================== | |
| function findButtonByAriaLabel(ariaLabel) { | |
| return document.querySelector(`button[aria-label="${ariaLabel}"]`); | |
| } | |
| function enableIncognitoMode() { | |
| console.log("Attempting to enable incognito mode..."); | |
| const incognitoButton = document.querySelector('ms-incognito-mode-toggle button[iconname="incognito"]'); | |
| if (incognitoButton) { | |
| const isActive = incognitoButton.getAttribute('aria-pressed') === 'true'; | |
| if (!isActive) { | |
| console.log('正在启用临时聊天模式...'); | |
| incognitoButton.click(); | |
| } else { | |
| console.log('临时聊天模式已启用'); | |
| } | |
| } else { | |
| console.warn('未找到临时聊天按钮'); | |
| } | |
| } | |
| /** | |
| * @MODIFIED: 接受一个回调函数,在所有操作(包括关闭面板)完成后执行。 | |
| */ | |
| function setSystemPrompt(onCompleteCallback) { | |
| console.log("Step 1: Setting System Prompt..."); | |
| const systemInstructionsButton = findButtonByAriaLabel("System instructions"); | |
| if (!systemInstructionsButton) { | |
| console.error("'System instructions' button NOT FOUND."); | |
| if (onCompleteCallback) onCompleteCallback(); // 即使失败也要继续后续步骤 | |
| return; | |
| } | |
| console.log("'System instructions' button found. Clicking to open panel."); | |
| systemInstructionsButton.click(); | |
| setTimeout(() => { | |
| const textarea = document.querySelector('textarea[aria-label="System instructions"]'); | |
| if (!textarea) { | |
| console.error("System prompt textarea NOT FOUND after clicking."); | |
| if (onCompleteCallback) onCompleteCallback(); | |
| return; | |
| } | |
| console.log("Textarea found. Setting prompt."); | |
| textarea.value = YOUR_SYSTEM_PROMPT; | |
| textarea.dispatchEvent(new Event('input', { bubbles: true, cancelable: true })); | |
| console.log("System prompt set successfully."); | |
| setTimeout(() => { | |
| // @FIXED: 使用更精确的 'aria-label' 来定位关闭按钮 | |
| const closeButton = findButtonByAriaLabel("Close panel"); | |
| if (closeButton) { | |
| console.log("Found close button. Closing panel."); | |
| closeButton.click(); | |
| } else { | |
| console.warn("Could not find the close button for the system instructions panel."); | |
| } | |
| // 无论是否找到关闭按钮,都执行回调,以继续下一步 | |
| if (onCompleteCallback) { | |
| // 再给一点时间让关闭动画完成 | |
| setTimeout(onCompleteCallback, 300); | |
| } | |
| }, 200); | |
| }, TIMEOUT_DURATION); | |
| } | |
| function configureTogglesInPanel() { | |
| console.log("Step 3: Configuring toggles in Run settings panel..."); | |
| const urlContextToggle = document.querySelector('ms-run-settings button[role="switch"][aria-label="Browse the url context"]'); | |
| if (urlContextToggle && urlContextToggle.getAttribute('aria-checked') === 'false') { | |
| urlContextToggle.click(); | |
| console.log("URL context toggled ON."); | |
| } else { | |
| console.log(urlContextToggle ? "URL context already ON." : "URL context toggle not found."); | |
| } | |
| const groundingToggle = document.querySelector('ms-run-settings button[role="switch"][aria-label="Grounding with Google Search"]'); | |
| if (groundingToggle && groundingToggle.getAttribute('aria-checked') === 'false') { | |
| groundingToggle.click(); | |
| console.log("Grounding with Google Search toggled ON."); | |
| } else { | |
| console.log(groundingToggle ? "Grounding with Google Search already ON." : "Grounding toggle not found."); | |
| } | |
| } | |
| function openRunSettingsAndConfigure() { | |
| console.log("Step 2: Opening Run Settings..."); | |
| const runSettingsPanel = document.querySelector('ms-run-settings'); | |
| const isRunSettingsOpen = runSettingsPanel && runSettingsPanel.classList.contains('expanded'); | |
| if (isRunSettingsOpen) { | |
| console.log("Run settings panel already open."); | |
| configureTogglesInPanel(); | |
| return; | |
| } | |
| // @FIXED: 查找“tune”图标按钮来打开设置面板 | |
| const openSettingsButton = Array.from(document.querySelectorAll('ms-toolbar button, ms-header-root button')) | |
| .find(btn => btn.querySelector('span.material-symbols-outlined')?.textContent.trim() === 'tune'); | |
| if (openSettingsButton) { | |
| console.log("Run settings panel is closed. Opening..."); | |
| openSettingsButton.click(); | |
| setTimeout(configureTogglesInPanel, TIMEOUT_DURATION); | |
| } else { | |
| console.error("Button to open 'Run settings' (tune icon) NOT FOUND."); | |
| } | |
| } | |
| // --- NEW Execution Flow --- | |
| // 严格按照顺序执行,通过回调函数链接异步操作 | |
| enableIncognitoMode(); | |
| setSystemPrompt(function() { | |
| // 这个函数只会在 setSystemPrompt 完成(包括关闭面板)后被调用 | |
| console.log("System prompt process finished. Now proceeding to run settings."); | |
| openRunSettingsAndConfigure(); | |
| }); | |
| console.log("AI Studio Configurator Bookmarklet: Tasks initiated in sequence."); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment