// ==UserScript== // @name New Userscript // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author euhat // @match https://www.sample.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=toutiao.com // @grant GM_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @grant GM_addStyle // @grant GM_setClipboard // @grant GM_download // @require https://unpkg.com/vue@2 // ==/UserScript== (function() { 'use strict'; var euForm = document.createElement("div"); euForm.innerHTML = ` <div id="euForm"> <b>Here:</b> <button @click="euDownAll">Download All Image</button> </div> `; document.querySelector("html").appendChild(euForm); GM_addStyle(` #euForm{ font-size : 15px; position: fixed; background-color: rgba(88, 88, 88, 0.9); color : #FF0000; text-align : center; padding: 10px; z-index : 9999; border:2px solid black; } `); document.getElementById("euForm").style.left = (200 || 20) + "px"; document.getElementById("euForm").style.top = (200 || 100) + "px"; function findAllLinks() { const allNodes = document.querySelectorAll('div.pgc-img > img'); var objList = []; var i = 0; allNodes.forEach((item) => { const obj = { id: i++, url: item.src }; objList.push(obj); }); return objList; } var vm = new Vue({ el: '#euForm', data: { version: "1.0.0", }, methods: { async euDownAll() { var objList = findAllLinks(); objList.forEach((item) => { const obj = { url: item.url, name: item.id + ".jpg", onload: function(e) { }, onerror: function(e) { console.log(e) }, onprogress: function(d) { } } GM_download(obj) }); }, } }); })(); |
refer to:
https://developer.mozilla.org/zh-CN/docs/Web/API/Document/querySelectorAll