Fixes saving chat log for 516 byond (#89864)

This commit is contained in:
Vallat
2025-03-10 10:21:45 -07:00
committed by GitHub
parent b63e95f5d0
commit 4f7253eab2
3 changed files with 38 additions and 2 deletions
+5
View File
@@ -178,6 +178,11 @@ type ByondType = {
* Maps icons to their ref
*/
iconRefMap: Record<string, string>;
/**
* Downloads a blob, platform-agnostic
*/
saveBlob(blob: Blob, filename: string, ext: string): void;
};
/**
+2 -2
View File
@@ -624,13 +624,13 @@ class ChatRenderer {
'</body>\n' +
'</html>\n';
// Create and send a nice blob
const blob = new Blob([pageHtml]);
const blob = new Blob([pageHtml], { type: 'text/plain' });
const timestamp = new Date()
.toISOString()
.substring(0, 19)
.replace(/[-:]/g, '')
.replace('T', '-');
window.navigator.msSaveBlob(blob, `ss13-chatlog-${timestamp}.html`);
Byond.saveBlob(blob, `ss13-chatlog-${timestamp}.html`, '.html');
}
}
+31
View File
@@ -345,6 +345,37 @@
loadAsset({ url: url, sync: sync, type: 'css' });
};
Byond.saveBlob = function (blob, filename, ext) {
if (window.navigator.msSaveBlob) {
window.navigator.msSaveBlob(blob, filename);
} else if (window.showSaveFilePicker) {
var accept = {};
accept[blob.type] = [ext];
var opts = {
suggestedName: filename,
types: [
{
description: 'SS13 file',
accept: accept,
},
],
};
window
.showSaveFilePicker(opts)
.then(function (file) {
return file.createWritable();
})
.then(function (file) {
return file.write(blob).then(function () {
return file.close();
});
})
.catch(function () {});
}
};
// Icon cache
Byond.iconRefMap = {};
})();