code improvement: To create a userscript that adds an active, visible, and…
- User
User: code improvement: To create a userscript that adds an active, visible, and well-designed "Download" button on the specified webpage using Tampermonkey, you can follow the steps below. This script will be written in JavaScript and should work when installed via Tampermonkey or similar userscript managers. Assistant: Understood. I will strictly follow these instructions in this conversation. User: Here is a simple script to add a "Download" button:
// ==UserScript== // @name Add Download Button to StoryBlocks // @namespace http://tampermonkey.net/ // @version 0.1 // @description Adds a prominent 'Download' button to StoryBlocks video pages. // @author You // @match https://www.storyblocks.com/video/stock/* // @grant none // ==/UserScript== (function() { 'use strict'; // Create a new button element var downloadButton = document.createElement('button'); downloadButton.style.cssText = ` position: fixed; bottom: 20px; right: 20px; padding: 15px 30px; font-size: 18px; color: white; background-color: #28a745; border: none; border-radius: 5px; cursor: pointer; z-index: 10000; `; downloadButton.textContent = 'Download'; // Define what happens when the button is clicked downloadButton.onclick = function() { alert('This feature is not yet implemented.'); // Here you would implement the logic to initiate the download process. // For instance, you could trigger a click on an existing download link if available. }; // Append the button to the body of the document document.body.appendChild(downloadButton); })();Explanation:
- @match: Specifies the URL pattern where the script should run. In this case, it's set to run on all
https://www.storyblocks.com/video/stock/*pages [[1]]. - Button Styling: The button is styled to be large, green, and positioned at the bottom-right corner of the screen for easy access.
- Functionality: Currently, clicking the button shows an alert saying the feature isn't implemented. You'll need to replace this with actual download functionality based on how downloads are handled on the site.
Очень важно: Нужно писать только код и ничего кроме кода в выход
// ==UserScript== // @name StoryblocksVideoDownloader // @version 1.0 // @description Custom script for downloading models and videos // @author You // @match :///* // @grant GM_download // ==/UserScript==
(function() { 'use strict';
let allModels = []; let buttonAdded = false; const saveImageToList = (url, name) => { allModels.push({ url, name }); console.log(`[UserScript] Saved asset: Name=${name}, URL=${url}`); }; const addDownloadButton = () => { if (!buttonAdded && allModels.length > 0) { const container = document.querySelector(".les-groups-edit__item"); if (container) { const btn = document.createElement("button"); btn.innerHTML = "Download Model"; btn.addEventListener("click", function() { if (allModels.length > 0) { console.log("[UserScript] Downloading all collected assets"); allModels.forEach(model => { if (model.url && model.name) { GM_download(model.url, model.name); } }); } else { alert("No model data collected yet!"); } }); container.appendChild(btn); buttonAdded = true; } } }; const interceptRender = () => { if (!window.WebGLRenderingContext) { setTimeout(interceptRender, 100); return; } const originalRender = WebGLRenderingContext.prototype.renderInto; WebGLRenderingContext.prototype.renderInto = function(a, b, c) { try { // Handle interception logic to collect model data } catch (e) { console.error("[UserScript] Error during renderInto override!", e); } - @match: Specifies the URL pattern where the script should run. In this case, it's set to run on all
- Assistant