-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
OctoSpacc
committed
May 20, 2024
1 parent
5d9d561
commit d566887
Showing
7 changed files
with
225 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
window.idbBackupAndRestore = { | ||
|
||
/* <https://gist.github.com/loilo/ed43739361ec718129a15ae5d531095b/> */ | ||
|
||
/** | ||
* Export all data from an IndexedDB database | ||
* | ||
* @param {IDBDatabase} idbDatabase The database to export from | ||
* @return {Promise<string>} | ||
*/ | ||
exportToJson: function (idbDatabase) { | ||
return new Promise((resolve, reject) => { | ||
const exportObject = {} | ||
if (idbDatabase.objectStoreNames.length === 0) { | ||
resolve(JSON.stringify(exportObject)) | ||
} else { | ||
const transaction = idbDatabase.transaction( | ||
idbDatabase.objectStoreNames, | ||
'readonly' | ||
) | ||
|
||
transaction.addEventListener('error', reject) | ||
|
||
for (const storeName of idbDatabase.objectStoreNames) { | ||
const allObjects = [] | ||
transaction | ||
.objectStore(storeName) | ||
.openCursor() | ||
.addEventListener('success', event => { | ||
const cursor = event.target.result | ||
if (cursor) { | ||
// Cursor holds value, put it into store data | ||
allObjects.push(cursor.value) | ||
cursor.continue() | ||
} else { | ||
// No more values, store is done | ||
exportObject[storeName] = allObjects | ||
|
||
// Last store was handled | ||
if ( | ||
idbDatabase.objectStoreNames.length === | ||
Object.keys(exportObject).length | ||
) { | ||
resolve(JSON.stringify(exportObject)) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
}) | ||
}, | ||
|
||
/** | ||
* Import data from JSON into an IndexedDB database. | ||
* This does not delete any existing data from the database, so keys may clash. | ||
* | ||
* @param {IDBDatabase} idbDatabase Database to import into | ||
* @param {string} json Data to import, one key per object store | ||
* @return {Promise<void>} | ||
*/ | ||
importFromJson: function (idbDatabase, json) { | ||
return new Promise((resolve, reject) => { | ||
const transaction = idbDatabase.transaction( | ||
idbDatabase.objectStoreNames, | ||
'readwrite' | ||
) | ||
transaction.addEventListener('error', reject) | ||
|
||
var importObject = JSON.parse(json) | ||
for (const storeName of idbDatabase.objectStoreNames) { | ||
let count = 0 | ||
for (const toAdd of importObject[storeName]) { | ||
const request = transaction.objectStore(storeName).add(toAdd) | ||
request.addEventListener('success', () => { | ||
count++ | ||
if (count === importObject[storeName].length) { | ||
// Added all objects for this store | ||
delete importObject[storeName] | ||
if (Object.keys(importObject).length === 0) { | ||
// Added all object stores | ||
resolve() | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
}) | ||
}, | ||
|
||
/** | ||
* Clear a database | ||
* | ||
* @param {IDBDatabase} idbDatabase The database to delete all data from | ||
* @return {Promise<void>} | ||
*/ | ||
clearDatabase: function (idbDatabase) { | ||
return new Promise((resolve, reject) => { | ||
const transaction = idbDatabase.transaction( | ||
idbDatabase.objectStoreNames, | ||
'readwrite' | ||
) | ||
transaction.addEventListener('error', reject) | ||
|
||
let count = 0 | ||
for (const storeName of idbDatabase.objectStoreNames) { | ||
transaction | ||
.objectStore(storeName) | ||
.clear() | ||
.addEventListener('success', () => { | ||
count++ | ||
if (count === idbDatabase.objectStoreNames.length) { | ||
// Cleared all object stores | ||
resolve() | ||
} | ||
}) | ||
} | ||
}) | ||
}, | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,70 @@ | ||
(function(){ | ||
var bin1Path = 'https://gamingshitposting.github.io/ext-bin-1'; | ||
var thisElement = document.querySelector(`script[src="${SalaMuseoGames.site.baseurl}/assets/js/software-embed.js"]`); | ||
var data = SalaMuseoGames.page.software_data; | ||
var platform = data.platform; | ||
var core = data.core; | ||
var backend = data.backend; | ||
var romUrl = (data.rom_url || `${bin1Path}/roms/${data.rom_index}.7z`); | ||
var frameUrl = (data.frame_url || `${bin1Path}/${data.frame_index}`); | ||
|
||
function button (name, onclick) { return `<button name="${name.split(' ')[0]}" onclick="(${onclick})(this)">${name}</button>` } | ||
var bin1Path = 'https://gamingshitposting.github.io/ext-bin-1'; | ||
var thisElement = document.querySelector(`script[src="${SalaMuseoGames.site.baseurl}/assets/js/software-embed.js"]`); | ||
var data = SalaMuseoGames.page.software_data; | ||
var platform = data.platform; | ||
var core = data.core; | ||
var backend = data.backend; | ||
var romUrl = (data.rom_url || `${bin1Path}/roms/${data.rom_index}.7z`); | ||
var frameUrl = (data.frame_url || `${bin1Path}/${data.frame_index}`); | ||
|
||
function diyEmbedHtml (frameUrl) { return ( | ||
button('Focus 🔳️', function(ctx){ | ||
ctx.parentElement.scrollIntoView(); | ||
ctx.parentElement.querySelector('iframe#software-embed-frame').focus(); | ||
}) + ' ' + | ||
button('Fullscreen 🖼️', function(ctx){ | ||
ctx.parentElement.querySelector('iframe#software-embed-frame').requestFullscreen(); | ||
}) + ' ' + | ||
button('Enlarge ↔️', function(ctx){ | ||
document.body.classList[ | ||
!document.body.className.split(' ').includes('cinema-view') ? 'add' : 'remove' | ||
]('cinema-view'); | ||
}) + ' ' + | ||
button('Reload ♻️', function(ctx){ | ||
var frame = ctx.parentElement.querySelector('iframe#software-embed-frame'); | ||
var src = frame.src; | ||
frame.src = ''; | ||
frame.src = src; | ||
}) + ' ' + | ||
`<iframe id="software-embed-frame" class="software-embed-frame" src="${frameUrl}"></iframe>` | ||
) } | ||
function button (name, onclick) { return `<button name="${name.split(' ')[0]}" onclick="(${onclick})(this)">${name}</button>` } | ||
|
||
// TODO set any overrides if specified ... | ||
var buttonEnlarge = button('Enlarge ↔️', function(){ | ||
document.body.classList[ | ||
!document.body.className.split(' ').includes('cinema-view') ? 'add' : 'remove' | ||
]('cinema-view'); | ||
}); | ||
|
||
if (platform === 'web') { | ||
function diyEmbedHtml (frameUrl) { return ( | ||
button('Focus 🔳️', function(ctx){ | ||
ctx.parentElement.scrollIntoView(); | ||
ctx.parentElement.querySelector('iframe#software-embed-frame').focus(); | ||
}) + ' ' + | ||
button('Fullscreen 🖼️', function(ctx){ | ||
ctx.parentElement.querySelector('iframe#software-embed-frame').requestFullscreen(); | ||
}) + ' ' + | ||
buttonEnlarge + ' ' + | ||
button('Reload ♻️', function(ctx){ | ||
var frame = ctx.parentElement.querySelector('iframe#software-embed-frame'); | ||
var src = frame.src; | ||
frame.src = ''; | ||
frame.src = src; | ||
}) + ' ' + | ||
`<iframe id="software-embed-frame" class="software-embed-frame" src="${frameUrl}"></iframe>` | ||
) } | ||
|
||
// TODO set any overrides if specified ... | ||
|
||
if (platform === 'web') { | ||
thisElement.outerHTML = diyEmbedHtml(frameUrl); | ||
} else switch (backend) { | ||
default: | ||
case 'cuttingedge': | ||
case 'emulatorjs': | ||
window.EJS_player = '#software-embed-frame'; | ||
window.EJS_pathtodata = 'https://gamingshitposting.github.io/ext-bin-1/EmulatorJS/data/'; | ||
window.EJS_core = (core || platform); | ||
window.EJS_gameUrl = romUrl; | ||
window.EJS_screenRecording = { videoBitrate: 150000000 }; | ||
thisElement.parentElement.appendChild(SMG.Util.elementFromHtml(buttonEnlarge)); | ||
thisElement.parentElement.appendChild(SMG.Util.makeElement('div', { | ||
style: 'width: 640px; height: 480px; max-width: 100%;', | ||
innerHTML: '<div id="software-embed-frame"></div>', | ||
})); | ||
document.body.appendChild(SMG.Util.makeElement('script', { src: `${EJS_pathtodata}loader.js` })); | ||
break; | ||
case 'standalone': | ||
var frameUrl = ''; | ||
if (platform === 'nds' || core === 'desmume') { | ||
frameUrl = `https://octospacc.gitlab.io/Web-Archives-Misc/Repo/DeSmuME/#RomUrl=${romUrl}`; | ||
} | ||
else if (platform === 'dos') { | ||
frameUrl = `https://gamingshitposting.github.io/ext-bin-1/dos.zone/${data.rom_index}/index.html`; | ||
} | ||
thisElement.outerHTML = diyEmbedHtml(frameUrl); | ||
} else switch (backend) { | ||
default: | ||
case 'cuttingedge': | ||
case 'emulatorjs': | ||
window.EJS_player = '#software-embed-frame'; | ||
window.EJS_pathtodata = 'https://gamingshitposting.github.io/ext-bin-1/EmulatorJS/data/'; | ||
window.EJS_core = (core || platform); | ||
window.EJS_gameUrl = romUrl; | ||
window.EJS_screenRecording = { videoBitrate: 150000000 }; | ||
var frameElement = document.createElement('div'); | ||
frameElement.style = 'width: 640px; height: 480px; max-width: 100%;'; | ||
frameElement.innerHTML = '<div id="software-embed-frame"></div>'; | ||
thisElement.parentElement.appendChild(frameElement); | ||
var scriptElement = document.createElement('script'); | ||
scriptElement.src = EJS_pathtodata+'loader.js'; | ||
document.body.appendChild(scriptElement); | ||
break; | ||
case 'standalone': | ||
var frameUrl = ''; | ||
if (platform === 'nds' || core === 'desmume') { | ||
frameUrl = `https://octospacc.gitlab.io/Web-Archives-Misc/Repo/DeSmuME/#RomUrl=${romUrl}`; | ||
} | ||
else if (platform === 'dos') { | ||
frameUrl = `https://gamingshitposting.github.io/ext-bin-1/dos.zone/${data.rom_index}/index.html`; | ||
} | ||
thisElement.outerHTML = diyEmbedHtml(frameUrl); | ||
break; | ||
} | ||
break; | ||
} | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(function(){ | ||
|
||
var Util = window.SalaMuseoGames.Util = {}; | ||
|
||
Util.makeElement = (function(tag, attrs){ | ||
return Object.assign(document.createElement('tag'), attrs); | ||
}); | ||
|
||
Util.elementFromHtml = (function(html){ | ||
return Util.makeElement('div', { innerHTML: html.trim() }).children[0]; | ||
}); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters