Fixes saving chat log for 516 byond (#89864)

This commit is contained in:
Vallat
2025-03-10 20:21:45 +03:00
committed by Roxy
parent 9970f6047d
commit dbde71a43b
3 changed files with 38 additions and 2 deletions

5
tgui/global.d.ts vendored
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;
};
/**

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');
}
}

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 = {};
})();