替换所选文本(Firefox)

A quick function to replace the selected text (in Firefox). Accepts:

替换所选文本的快速功能(在Firefox中)。 接受:

  • string to replace the selection, or

    字符串来替换选择,或者
  • callback function that takes the selected text and returns a string to replace the selection

    带有所选文本并返回字符串以替换所选内容的回调函数
function replaceSelection(t) {
  if (typeof t === 'function') {
    t = t(window.getSelection().toString());
  }
  var range = window.getSelection().getRangeAt(0);
  range.deleteContents();
  range.insertNode(document.createTextNode(t));
}

Usage:

用法:

1. Replace selected text with "dude" replaceSelection('dude'); 2. Uppercase the selected text replaceSelection(function(s){return s.toUpperCase()}); 3. Lowercase the selected text replaceSelection(function(s){return s.toLowerCase()});

1.将所选文本替换为“ dude” replaceSelection('dude'); 2.大写所选文本replaceSelection(function(s){return s.toUpperCase()}); 3.小写所选文本replaceSelection(function(s){return s.toLowerCase()});

Luckily I'm so close (and yet so far) to finishing this book, otherwise I won't be able to help myself but create a whole toolbar of bookmarklets for "power" Google doc users...

幸运的是,我已经很接近(到目前为止)完成本书,否则我将无法为自己服务,而是为“强大”的Google文档用户创建了一个完整的书签小工具栏...

Tell your friends about this post on Facebook and Twitter

FacebookTwitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/replace-selected-text-firefox/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值