Bopimo Item Data Downloader

Adds a button to download item textures from Bopimo.com

  1. // ==UserScript==
  2. // @name Bopimo Item Data Downloader
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Adds a button to download item textures from Bopimo.com
  6. // @author Teemsploit, Variant Tombstones, Evelyn
  7. // @license MIT
  8. // @match https://www.bopimo.com/items/*
  9. // @run-at document-start
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. function injectUI() {
  17. var buttonPanel = document.createElement('div');
  18. buttonPanel.id = "custom-download-panel";
  19. buttonPanel.className = "shop-card";
  20. buttonPanel.style = "position: fixed; z-index: 1000; padding: 1rem;";
  21. buttonPanel.style.bottom = "1rem";
  22. buttonPanel.style.right = "1rem";
  23. buttonPanel.innerHTML = `
  24. <button class="button" id="download-texture-btn">Download Texture</button>
  25. <button class="button" id="download-mesh-btn" style="margin-left: 10px;">Download Mesh</button>
  26. <p>Credits: Teemsploit & Variant Tombstones</p>
  27. `;
  28. document.body.appendChild(buttonPanel);
  29. }
  30.  
  31. function makeButtonsDoStuffIGuess() {
  32. const textureButton = document.getElementById("download-texture-btn");
  33. const meshButton = document.getElementById("download-mesh-btn");
  34.  
  35. if (textureButton) {
  36. textureButton.addEventListener("click", () => download('image'));
  37. }
  38.  
  39. if (meshButton) {
  40. meshButton.addEventListener("click", () => download('mesh'));
  41. }
  42. }
  43.  
  44. function download(type) {
  45. try {
  46. var imageUrl = document.querySelector('meta[property="og:image"]').getAttribute('content');
  47. if (!imageUrl) {
  48. alert('Image link not found.');
  49. return;
  50. }
  51. var assetUrl = imageUrl.replace("renders/thumbnail", "assets");
  52.  
  53. // Fix: Proper comparison for the type
  54. if (type === 'mesh') {
  55. assetUrl = assetUrl.replace(".png", ".obj");
  56. }
  57.  
  58. var parts = assetUrl.split("/");
  59. var fileName = parts[parts.length - 1];
  60. var link = document.createElement("a");
  61. link.setAttribute("href", assetUrl);
  62. link.setAttribute("download", fileName);
  63. document.body.appendChild(link);
  64. link.click();
  65. document.body.removeChild(link);
  66. } catch (err) {
  67. alert('An error occurred: ' + err);
  68. }
  69. }
  70.  
  71. function waitForDomReady() {
  72. if (document.readyState === 'loading') {
  73. document.addEventListener('DOMContentLoaded', makeButtonsDoStuffIGuess);
  74. } else {
  75. makeButtonsDoStuffIGuess();
  76. }
  77. }
  78.  
  79. injectUI();
  80.  
  81. waitForDomReady();
  82. })();