You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何编写Tampermonkey脚本修改按钮onclick事件URL以下载STP文件

Tampermonkey Script to Enable Direct STP Downloads from Fusion360 Buttons

Got it, let's tweak that "Open in Fusion360" button so it lets you download the STP file directly instead of launching the Fusion360 protocol. Here's a ready-to-use Tampermonkey script that handles all the heavy lifting automatically:

// ==UserScript==
// @name         Direct STP Download from Fusion360 Button
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Turns the "Open in Fusion360" button into a direct STP file download button
// @author       Your Name
// @match        https://your-target-website.com/* // Replace with the actual site domain
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Wait for the button to load (handles dynamic page content)
    const buttonChecker = setInterval(() => {
        const fusionButton = document.querySelector('button.event.btn.btn-default.btn-lg.btn-block[onclick*="fusion360://command=insert"]');
        if (fusionButton) {
            clearInterval(buttonChecker);

            // Extract the raw STP URL from the button's onclick code
            const onclickText = fusionButton.getAttribute('onclick');
            const stpUrlMatch = onclickText.match(/encodeURIComponent\("(.*?)"\)/);
            
            if (stpUrlMatch && stpUrlMatch[1]) {
                const stpFileUrl = decodeURIComponent(stpUrlMatch[1]);

                // Update the button to point directly to the STP file
                fusionButton.setAttribute('onclick', `window.location.href = "${stpFileUrl}";`);

                // Optional: Update button text to reflect the new function
                fusionButton.textContent = 'Download STP File';

                // Optional: Update accessibility label
                fusionButton.setAttribute('aria-label', 'Download STP File');
            }
        }
    }, 500); // Check every 500ms until the button is found
})();

Key Details & Setup Steps:

  • Update the @match line: Replace https://your-target-website.com/* with the actual domain of the site where this button appears. This ensures the script only runs where it's needed.
  • Dynamic content handling: The script uses setInterval to wait for the button to load, which works even if the button is added to the page dynamically (like via AJAX).
  • URL extraction: Instead of hardcoding the STP URL, it pulls the original link straight from the button's existing onclick code—so it'll work for any similar button on the site, not just the specific one you shared.
  • Optional tweaks: The script includes lines to change the button text and accessibility label, but you can comment those out if you prefer to keep the original button text.

How to Use:

  1. Install the Tampermonkey extension for your browser (Chrome, Firefox, Edge, etc.).
  2. Click the Tampermonkey icon and select "Create a new script".
  3. Replace the default template with the code above.
  4. Update the @match line to match your target site.
  5. Save the script (Ctrl+S or Cmd+S).
  6. Refresh the page with the Fusion360 button—you'll now see it lets you download the STP file directly when clicked!

内容的提问来源于stack exchange,提问作者pball

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:57:17