Chrome或Firefox浏览器扩展/自定义方案需求:实现按键跳转至文本中的***通配符位置
Chrome或Firefox浏览器扩展/自定义方案需求:实现按键跳转至文本中的***通配符位置
Hey there! I totally get wanting that seamless wildcard-jumping functionality like EPIC's F2 shortcut for your new EMR—super handy for speeding up note-taking. Since the EMR doesn’t have built-in support and you couldn’t find a ready-made extension, here’s a flexible custom solution using a user script (works for both Chrome and Firefox):
Option 1: Custom User Script with Tampermonkey
Tampermonkey is a popular browser extension that lets you run custom JavaScript on specific websites, perfect for adding this exact functionality.
Install Tampermonkey
- For Chrome: Search for "Tampermonkey" in the Chrome Web Store and install it.
- For Firefox: Grab it from Firefox Add-ons.
Create a New Script
- Click the Tampermonkey icon in your browser toolbar, then select "Create a new script".
- Replace the default template with the code below, and make sure to update the
@matchline to your EMR’s actual domain (e.g.,*://your-emr-website.com/*):
// ==UserScript== // @name EMR Wildcard Jumper // @namespace http://tampermonkey.net/ // @version 0.1 // @description Jump between *** wildcards in EMR notes using F2 // @author Your Name // @match *://your-emr-domain.com/* // Replace with your EMR's URL // @grant none // ==/UserScript== (function() { 'use strict'; let currentWildcardIndex = 0; document.addEventListener('keydown', function(e) { // Trigger on F2 press if (e.key === 'F2') { e.preventDefault(); const activeElement = document.activeElement; // Only target editable areas (textarea or contenteditable elements) if ((activeElement.tagName === 'TEXTAREA' || activeElement.isContentEditable)) { const content = activeElement.textContent || activeElement.value; const wildcardRegex = /\*\*\*/g; const matches = []; let match; // Collect all positions of *** in the content while ((match = wildcardRegex.exec(content)) !== null) { matches.push(match.index); } if (matches.length === 0) return; // Cycle through each wildcard position currentWildcardIndex = (currentWildcardIndex + 1) % matches.length; const targetPos = matches[currentWildcardIndex]; // Focus and select the wildcard to make replacing easy if (activeElement.tagName === 'TEXTAREA') { activeElement.focus(); activeElement.setSelectionRange(targetPos, targetPos + 3); } else if (activeElement.isContentEditable) { const range = document.createRange(); const selection = window.getSelection(); range.setStart(activeElement.firstChild, targetPos); range.setEnd(activeElement.firstChild, targetPos + 3); selection.removeAllRanges(); selection.addRange(range); activeElement.focus(); } } } }); })();
- Save and Test
- Save the script (Ctrl+S or Cmd+S), then navigate to your EMR. Open a note template with
***wildcards, click into the text area, and press F2—you should jump directly to the next wildcard, with it selected ready for your input.
- Save the script (Ctrl+S or Cmd+S), then navigate to your EMR. Open a note template with
Quick Notes for Troubleshooting
- If your EMR uses iframes for note-taking, you’ll need to update the
@matchline to include the iframe’s domain too. - If your wildcards use a different pattern (e.g.,
___or[wildcard]), just adjust thewildcardRegexline to match (e.g.,/___/g). - If the cursor doesn’t position correctly in contenteditable areas, some EMRs use nested elements—you might need to tweak the range selection logic a bit, but this basic script works for most standard setups.
Let me know if you hit any snags getting this up and running—I’m happy to help refine it for your specific EMR!
备注:内容来源于stack exchange,提问作者MoJamesM
相关产品推荐
相关产品推荐

