This repository has been archived on 2026-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
polyplus/js/library-download.js
Index 55ad153d2b 33 files changed - update + hoarders list
- Added new feature: "Collectibles' Hoarders List"

[ IMPROVEMENTS ]

- Reorganized resources folder to be in the root directory rather than a sub-folder of the javascript folder

- Added a new feature: "Quick Library Downloads"

- Basically finished the "Event Items Store Category" feature

- Added more manifest.json information
2024-04-25 17:04:38 -05:00

59 lines
No EOL
2.4 KiB
JavaScript

const AssetID = window.location.pathname.split('/')[2]
const LibraryType = document.querySelectorAll('ol a')[1].innerText
const LibraryTypes = [
"Models",
"Audio",
"Decal",
"Mesh"
]
var Success = true;
if (LibraryTypes.indexOf(LibraryType) !== -1) {
chrome.storage.sync.get(['PolyPlus_Settings'], function(result){
Settings = result.PolyPlus_Settings || {};
if (Settings.LibraryDownloadsOn === false) { return }
const Dropdown = document.querySelector('#app div[style] .dropdown-menu li')
const DownloadLink = document.createElement('a')
DownloadLink.classList = 'dropdown-item text-warning'
DownloadLink.href = '#'
DownloadLink.innerHTML = `<i class="fa-duotone fa-download"></i> Download`
Dropdown.insertBefore(DownloadLink, Dropdown.children[Dropdown.children.length-1])
switch(LibraryType) {
case 'Models':
DownloadLink.href = 'https://api.polytoria.com/v1/models/get-model?id=' + AssetID
break
case 'Audio':
const AudioBlob = new Blob([document.getElementsByTagName('audio')[0]], {type: 'octet-steam'})
DownloadLink.href = URL.createObjectURL(AudioBlob)
DownloadLink.download = document.getElementsByTagName('h1')[0].innerText + '.mp3'
case 'Decal':
const DecalBlob = new Blob([document.getElementsByClassName('store-thumbnail')[0]], {type: 'image/png'})
DownloadLink.href = URL.createObjectURL(DecalBlob)
DownloadLink.download = document.getElementsByTagName('h1')[0].innerText + '.png'
break
}
if (LibraryType === 'Mesh') {
let MeshURL = null
DownloadLink.addEventListener('click', async function(){
if (MeshURL !== null) { return }
MeshURL = await fetch('https://api.polytoria.com/v1/assets/serve-mesh/' + AssetID)
MeshURL = await MeshURL.json()
if (MeshURL.success === true) {
DownloadLink.href = MeshURL.url
DownloadLink.download = document.getElementsByTagName('h1')[0].innerText + '.glb'
DownloadLink.click()
} else {
alert('Failure to fetch .glb file for mesh')
}
})
}
});
}