Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用chrome扩展从网页提取和下载图像_Javascript_Html_Image_Google Chrome_Download - Fatal编程技术网

Javascript 使用chrome扩展从网页提取和下载图像

Javascript 使用chrome扩展从网页提取和下载图像,javascript,html,image,google-chrome,download,Javascript,Html,Image,Google Chrome,Download,我不想这么说,但自从我几个小时前开始学习扩展以来,我在开发扩展方面没有走多远( 如果此线程重复,我提前表示歉意,但老实说,我已经筋疲力尽;这是我的问题: 我想为自己开发一个扩展,从一个名为readcomiconline.to的网站上自动下载图像列表 我的第一个问题是,当我使用getElementById()时,它只在扩展弹出窗口中显示 我的第二个问题是,我还没有找到使用Javascript自动下载几个文件的方法 请记住,我不会理解任何关于扩展的高级术语,但是我对Javascript有相当扎实的理

我不想这么说,但自从我几个小时前开始学习扩展以来,我在开发扩展方面没有走多远(

如果此线程重复,我提前表示歉意,但老实说,我已经筋疲力尽;这是我的问题:

我想为自己开发一个扩展,从一个名为readcomiconline.to的网站上自动下载图像列表

我的第一个问题是,当我使用getElementById()时,它只在扩展弹出窗口中显示

我的第二个问题是,我还没有找到使用Javascript自动下载几个文件的方法

请记住,我不会理解任何关于扩展的高级术语,但是我对Javascript有相当扎实的理解

此外,使用JQuery也不是首选

我的代码:

Manifest.JSON

{
    "name": "Comic Downloader",
    "options_page": "options.html",
    "version": "1.0",
    "description": "Build an Extension!",
    "permissions": [ "tabs",
        "notifications",
        "http://*/",
        "https://*/", "downloads", "activeTab", "declarativeContent", "storage", "tabs", "<all_urls>"],
    "background": {
      "scripts": ["background.js"],
      "persistent": false
    },
    "page_action": {
      "default_popup": "popup.html",
      "default_icon": {
        "16": "images/get_started16.png",
        "32": "images/get_started32.png",
        "48": "images/get_started48.png",
        "128": "images/get_started128.png"
      }
    },
    "icons": {
      "16": "images/get_started16.png",
      "32": "images/get_started32.png",
      "48": "images/get_started48.png",
      "128": "images/get_started128.png"
    },
    "manifest_version": 2
  }
{
“名称”:“漫画下载器”,
“选项页面”:“options.html”,
“版本”:“1.0”,
“说明”:“生成扩展!”,
“权限”:[“选项卡”,
“通知”,
“http://*/”,
“https://*/”、“下载”、“活动选项卡”、“声明内容”、“存储”、“选项卡”、“文件夹”],
“背景”:{
“脚本”:[“background.js”],
“持续”:假
},
“页面操作”:{
“默认弹出窗口”:“popup.html”,
“默认_图标”:{
“16”:“images/get_started16.png”,
“32”:“images/get_started32.png”,
“48”:“images/get_started48.png”,
“128”:“images/get_started128.png”
}
},
“图标”:{
“16”:“images/get_started16.png”,
“32”:“images/get_started32.png”,
“48”:“images/get_started48.png”,
“128”:“images/get_started128.png”
},
“清单版本”:2
}
popup.JS:

// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

'use strict';

let changeColor = document.getElementById('changeColor');
chrome.storage.sync.get('color', function(data) {
  changeColor.style.backgroundColor = data.color;
  changeColor.setAttribute('value', data.color);
});

changeColor.onclick = function(element) {
    let color = element.target.value;
    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {

      chrome.tabs.executeScript(
          tabs[0].id,
          //{code: 'document.getElementById("divImage")'});
          {code: 'var filesForDownload = [];
                 filesForDownload( { path: "/path/file1.txt", name: "file1.txt" } );
                 filesForDownload( { path: "/path/file2.jpg", name: "file2.jpg" } );
                 filesForDownload( { path: "/path/file3.png", name: "file3.png" } );
                 filesForDownload( { path: "/path/file4.txt", name: "file4.txt" } );
                 $jq(\'input.downloadAll\').click( function( e ){
                     e.preventDefault();
                     var temporaryDownloadLink = document.createElement("a");
                     temporaryDownloadLink.style.display = \'none\';
                     document.body.appendChild( temporaryDownloadLink );
                    for( var n = 0; n < filesForDownload.length; n++ ) {
                        var download = filesForDownload[n];
                        temporaryDownloadLink.setAttribute( \'href\', download.path );
                        temporaryDownloadLink.setAttribute( \'download\', download.name );
                        temporaryDownloadLink.click();
                    }
                    document.body.removeChild( temporaryDownloadLink );
                }
            );'
        });
          //{code: 'document.body.style.backgroundColor = "' + color + '";'});
    });
  };
//Chromium作者版权所有。保留所有权利。
//此源代码的使用受BSD样式许可证的约束,该许可证可以
//在许可证文件中找到。
"严格使用",;
让changeColor=document.getElementById('changeColor');
chrome.storage.sync.get('color',函数(数据){
changeColor.style.backgroundColor=data.color;
changeColor.setAttribute('value',data.color);
});
changeColor.onclick=函数(元素){
让颜色=element.target.value;
chrome.tabs.query({active:true,currentWindow:true},函数(tabs){
chrome.tabs.executeScript(
选项卡[0]。id,
//{code:'document.getElementById(“divImage”)};
{code:'var filesForDownload=[];
filesForDownload({path:“/path/file1.txt”,名称:“file1.txt”});
filesForDownload({path:“/path/file2.jpg”,名称:“file2.jpg”});
filesForDownload({path:“/path/file3.png”,名称:“file3.png”});
filesForDownload({path:“/path/file4.txt”,名称:“file4.txt”});
$jq(\'input.downloadAll\')。单击(函数(e){
e、 预防默认值();
var temporaryDownloadLink=document.createElement(“a”);
temporaryDownloadLink.style.display=\'none\';
document.body.appendChild(临时下载链接);
对于(var n=0;n
请包含您所做工作的完整代码。好的,我已经添加了。