Compare commits

..

No commits in common. "111057bd7b8c11f283c3d7b695a39a34d439ee41" and "c2159598c9da6cfd3a388a955460e411797bade3" have entirely different histories.

6 changed files with 86 additions and 5 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

@ -9,6 +9,7 @@
#include submitbox.js #include submitbox.js
#include title.js #include title.js
#include utility.js #include utility.js
#include mami/settings.js
var AmiChat = function(chat, title, parent) { var AmiChat = function(chat, title, parent) {
var container = $e({ attrs: { id: 'chat' } }); var container = $e({ attrs: { id: 'chat' } });
@ -75,6 +76,8 @@ var AmiChat = function(chat, title, parent) {
if(parent !== undefined) if(parent !== undefined)
pub.appendTo(parent); pub.appendTo(parent);
if(MamiSettings.isSupported())
optionIcons.create('export', 'Export modern client settings', 'export', () => MamiSettings.exportFile());
optionIcons.create('unembed', 'Unembed any embedded media', 'unembed', function() { optionIcons.create('unembed', 'Unembed any embedded media', 'unembed', function() {
var buttons = $c('js-unembed-btn'); var buttons = $c('js-unembed-btn');
while(buttons.length > 0) while(buttons.length > 0)

View file

@ -6,6 +6,7 @@
#include loadoverlay.js #include loadoverlay.js
#include mszauth.js #include mszauth.js
#include ts_chat.js #include ts_chat.js
#include mami/settings.js
(function() { (function() {
var loading = new AmiLoadingOverlay(document.body, true); var loading = new AmiLoadingOverlay(document.body, true);

View file

@ -0,0 +1,80 @@
#include utility.js
const MamiSettings = (function() {
const isSupported = () => {
if(navigator.userAgent.indexOf('MSIE') >= 0)
return false;
if(navigator.userAgent.indexOf('Trident/') >= 0)
return false;
if(!('Blob' in window) || !('prototype' in window.Blob)
|| window.Blob.prototype.constructor.name !== 'Blob')
return false;
if(!('AudioContext' in window) && !('webkitAudioContext' in window))
return false;
if(!('URL' in window) || !('createObjectURL' in window.URL)
|| window.URL.prototype.constructor.name !== 'URL')
return false;
if(!('localStorage' in window))
return false;
try {
var testVar = 'test';
localStorage.setItem(testVar, testVar);
if(localStorage.getItem(testVar) !== testVar)
throw '';
localStorage.removeItem(testVar);
} catch(e) {
return false;
}
try {
eval('const c = 1; let l = 2;');
} catch(e) {
return false;
}
try {
eval('for(const i of ["a", "b"]);');
} catch(e) {
return false;
}
return true;
}
const exportFile = () => {
const data = { a: 'Mami Settings Export', v: 1, d: [] };
for(let i = 0; i < localStorage.length; ++i) {
const key = localStorage.key(i);
if(key.substring(0, 4) !== 'umi-')
continue;
data.d.push({
i: key.substring(4),
v: JSON.parse(localStorage.getItem(key)),
});
}
const exp = $e('a', {
href: URL.createObjectURL(new Blob(
[btoa(JSON.stringify(data))],
{ type: 'application/octet-stream' }
)),
download: 'settings.mami',
target: '_blank',
style: { display: 'none' }
});
document.body.appendChild(exp);
exp.click();
$r(exp);
};
return {
isSupported: isSupported,
exportFile: exportFile,
};
})();

View file

@ -46,8 +46,8 @@ var Utils = (function () {
link.classList[holder.title == 'link' ? 'remove' : 'add']('js-unembed-btn'); link.classList[holder.title == 'link' ? 'remove' : 'add']('js-unembed-btn');
}; };
Utils.ToggleSpoiler = function(element) { Utils.ToggleSpoiler = function(element) {
var container = element.parentElement; var container = element.parentElement,
var target = container.getElementsByTagName("span")[0]; target = container.getElementsByTagName("span")[0];
if(container.dataset.revealed === 'yes') { if(container.dataset.revealed === 'yes') {
container.dataset.revealed = 'no'; container.dataset.revealed = 'no';
@ -58,9 +58,6 @@ var Utils = (function () {
target.textContent = container.dataset.shit; target.textContent = container.dataset.shit;
element.textContent = 'Hide'; element.textContent = 'Hide';
} }
element.classList[container.dataset.revealed == 'no' ? 'add' : 'remove']('js-embed-btn');
element.classList[container.dataset.revealed == 'no' ? 'remove' : 'add']('js-unembed-btn');
} }
Utils.SanitizeRegex = function (input) { Utils.SanitizeRegex = function (input) {
var out = ""; var out = "";