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