【发布时间】:2017-07-06 19:54:39
【问题描述】:
我正在尝试使用我构建的小型 chrome 扩展来迁移图像。该扩展由 5 个文件组成:
popup.html - 插件 html 文档
Has some html buttons
also has script link to my settings.js file that listens for the image downlaod button to be clicked and send a message to my content script : run.js to find the images
run.js - 内容脚本(可以访问网页 DOM)。
This script recieves the message from run.js which then finds all the images names and image links i want to download. It puts them into an object and sends them via message to the backgorund script : bootstrap.js
bootstrap.js - 运行后台页面并可以访问 chrome api。
var Downloads = [];
chrome.extension.onMessage.addListener(function(request, sender, sendResponse)
{
if(request.message.method == 'download'){
for( var d = 0; d <= request.message.imageLinks.length; d++ ){
chrome.downloads.download( {url: request.message.imageLinks[d],
filename: request.message.imageName[d]}, function(id){
});
sendResponse('done');
}
}
});
这一切都很好而且花花公子。它遍历图像并下载它们。 我现在需要做的是:获取我刚刚下载的图像,并将它们插入到具有相同字段名称等的其他网站(我在另一个选项卡中打开)上的文件上传字段中。 我看到 chrome 有一个
//Initiate dragging the downloaded file to another application. Call in a javascript ondragstart handler.
chrome.downloads.drag(integer downloadId)
起初我认为这可能有效,因为您可以手动将下载的图像拖到 html 文件上传字段中,而无需单击并选择文件。但我找不到任何文档/示例。
有谁知道使用 javascript / chrome api 可以实现这一点?
【问题讨论】:
标签: javascript google-chrome plugins