// ==UserScript== // @name hho-amazon-extension // @namespace https://www.amazon* // @version 0.1 // @description amazon! // @author miaomiao // @match https://www.amazon.co.jp/* // @icon https://www.google.com/s2/favicons?domain=amazon.co.jp // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js,https://layui.itze.cn/layui-v2.6.8/layui/layui.js // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; var $ = window.$ $(document).ready(function() { // 添加按钮 const button = '' $('body').append(button); }) // 点击 一键上架 $(document).on('click',"#hhoBtn", function(){ saveHtml(); }); function saveHtml() { // 获取 html 数据 const arr = decodeURIComponent(location.pathname).split('/') const index = arr.indexOf('dp') if (index < 0) { alert('监测到不是亚马逊详情页哦,如果确认是详情页请联系管理员') } else { // 是详情页 const filename = arr[index + 1] // 点击所有缩略图 $('#altImages li').each(function() { $(this).click() }) // 滚动到底部 var h = $(document).height() - $(window).height() $(document).scrollTop(h); console.log(`${filename} is downloading ...`) $('#hhoBtn').text('正在上传') var myBlob = new Blob([document.documentElement.innerHTML], { "type" : "text\/html" }); var formData = new FormData() formData.append('source', 'amazon') formData.append('filename', filename) formData.append('file', myBlob) // 发送请求 $.post({ url: "https://192.168.1.23/upload/amazon", processData: false, contentType: false, data: formData, success: function(data) { if (data.success) { $('#hhoBtn').text('上传成功') setTimeout(() => { $('#hhoBtn').text('一键上架') }, 2000) console.log(`${filename} is completed`) } else { $('#hhoBtn').text('上传失败') setTimeout(() => { $('#hhoBtn').text('一键上架') }, 2000) } }, fail: function(err) { $('#hhoBtn').text('上传失败') setTimeout(() => { $('#hhoBtn').text('一键上架') }, 2000) console.error(`${filename} is download failed, ${err}`) } }) } } })();