本帖最后由 ozon 于 2022-10-27 16:57 编辑
大佬如何读取文件上传,搜索了下资料说是要把file交给input
https://juejin.cn/post/6844904016560783374
https://zhuanlan.zhihu.com/p/31401799
`// ==UserScript==
// @name 上传图片到百度识图
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://image.baidu.com/
// ==/UserScript==
(function() {
'use strict';
const button = document.createElement('button');
button.innerText = "点我授权目录";
document.body.firstChild.after(button);
button.addEventListener('click', async function () {
async function getFile() {
// open directory picker
const dirHandle = await window.showDirectoryPicker({mode:"readwrite"});
console.log(dirHandle);
const button2 = document.createElement('button');
button2.innerText = "点我读取目录&写点东西";
document.body.firstChild.after(button2);
button2.addEventListener('click', async function () {
// 读取目录
for await (const item of dirHandle.values()) {
console.log(item)//打开的文件夹只放了一个图片
console.log(1)
$("#stfile").files=item//这里瞎写的,怎么把文件传值给input呢
}
// 写文件
// const fileHandle = await dirHandle.getFileHandle("hello-world.txt", { create: true });
// const writable = await fileHandle.createWritable();
// await writable.write("Hello World!");
// await writable.close();
});
}
getFile();
});
// Your code here...
})();`