sudodoki / copy-to-clipboard

Copy stuff into clipboard from your browser using JS
http://sudodoki.github.io/copy-to-clipboard/example/
MIT License
1.28k stars 132 forks source link

哥们,你的 options 的 format 必须传值才走复制的代码,format 传为 text/plain,你下个版本修复下? #103

Open JayWongwz opened 3 years ago

JayWongwz commented 3 years ago
function copy(text, options) {
  var debug,
    message,
    reselectPrevious,
    range,
    selection,
    mark,
    success = false;
  if (!options) {
    options = {};
  }
  ...
  mark.addEventListener("copy", function(e) {
      e.stopPropagation();
      // 这里必须传默认值,否则根本不执行复制逻辑,并且你的 options 并未给 format 默认值
      if (options.format) {
        e.preventDefault();
        if (typeof e.clipboardData === "undefined") { // IE 11
          debug && console.warn("unable to use e.clipboardData");
          debug && console.warn("trying IE specific stuff");
          window.clipboardData.clearData();
          var format = clipboardToIE11Formatting[options.format] || clipboardToIE11Formatting["default"]
          window.clipboardData.setData(format, text);
        } else { // all other browsers
          e.clipboardData.clearData();
          e.clipboardData.setData(options.format, text);
        }
      }
      if (options.onCopy) {
        e.preventDefault();
        options.onCopy(e.clipboardData);
      }
    });
}
leegsen7 commented 1 year ago

自己二次封装下吧,也简单,他最近都没维护更新了。

sudodoki commented 1 year ago

I don't know what this issue is about, so not sure how to address this one. Care to translate? If format not passed, we just have execCommand('copy') and default format being set, with format option making difference only if we are able to manipulate clipboard content

aaronzyf commented 1 year ago

@sudodoki What he means is to say options.format does not provide a default value, so

copy(' test plain text'), // doesn't work copy('test plain text',{format: 'text/plain'}) // work fine

in your code , you only do copy when options.format is provided

sorry for my bad english

aaronzyf commented 1 year ago

you can see the author's profile, he is from Ukraine With a war going on in Ukraine, it is understandable that there is no time for updates

他乌克兰人 , 打仗呢 , 多理解下

sudodoki commented 1 year ago

@aaronzyf thanks for translation. Yeah, I have enough time now to take care of the package at pre-war level (which is quite low, frankly speaking), but seems to be similar to what we have in https://github.com/sudodoki/copy-to-clipboard/pull/122