将文件中的自动填充数据导入Chrome [英] Import autofill data from a file into Chrome

查看:161
本文介绍了将文件中的自动填充数据导入Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户的CSV文件(带有电子邮件和姓名).Google Chrome存储了自动填充数据,您可以在此处手动添加它们:chrome://settings/addresses

是否可以从文件中自动导入数据?

解决方案

设置UI使用内部API chrome.autofillPrivate.saveAddress (

  for(document.querySelectorAll('body> input')的常量)el.remove();Object.assign(document.body.appendChild(document.createElement('input'))){类型:文件",风格:'position:absolute;顶部:2ex;对:0;z-index:999',onchange(e){如果(!this.files [0])返回;const fr = new FileReader();fr.readAsText(this.files [0],'UTF-8');fr.onload =()=>{对于(fr.result.split(/\ r?\ n/)的常量行){const [名称,电子邮件] = line.split(',');chrome.autofillPrivate.saveAddress({emailAddresses:[email],fullNames:[名称],});}};fr.onerror = console.error;},}); 

  • 要处理CSV中带引号和多行的字段,您应该修改此原始代码,有许多示例可以正确解析JavaScript中的CSV.
  • 您可以将代码保存在 devtools代码段中,以以后再使用.
  • 您不能在扩展程序中使用此私有API.
  • 受支持的字段及其类型列在 autofill_private.js中

I have a CSV file of users (with email and name). Google Chrome stores its autofill data and you can add them manually here: chrome://settings/addresses

Is it possible to import the data automatically from the file?

解决方案

The settings UI uses an internal API chrome.autofillPrivate.saveAddress (source).

  1. go to chrome://settings/addresses
  2. open devtools console
  3. paste and run the code below that adds an input button in the top right corner where you can select your CSV file:

for (const el of document.querySelectorAll('body > input'))
  el.remove();
Object.assign(document.body.appendChild(document.createElement('input')), {
  type: 'file',
  style: 'position:absolute; top:2ex; right:0; z-index:999',
  onchange(e) {
    if (!this.files[0])
      return;
    const fr = new FileReader();
    fr.readAsText(this.files[0], 'UTF-8');
    fr.onload = () => {

      for (const line of fr.result.split(/\r?\n/)) {
        const [name, email] = line.split(',');
        chrome.autofillPrivate.saveAddress({
          emailAddresses: [email],
          fullNames: [name],
        });
      }

    };
    fr.onerror = console.error;
  },
});

  • To process quoted and multi-line fields in CSV you should modify this primitive code, there are many examples of parsing CSV in JavaScript properly.
  • You can save the code in devtools snippets to reuse it later.
  • You can't use this private API in an extension.
  • Supported fields and their types are listed in autofill_private.js

这篇关于将文件中的自动填充数据导入Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆