diff --git a/install-usercss/install-usercss.js b/install-usercss/install-usercss.js index 3d347955..0d69222b 100644 --- a/install-usercss/install-usercss.js +++ b/install-usercss/install-usercss.js @@ -276,7 +276,7 @@ data.version, ])) ).then(ok => ok && - BG.usercssHelper.save(BG.deepCopy(Object.assign(style, {reason: 'update'}))) + BG.usercssHelper.save(BG.deepCopy(Object.assign(style, dup && {reason: 'update'}))) .then(r => install(deepCopy(r))) .catch(err => messageBox.alert(t('styleInstallFailed', err))) ); diff --git a/js/usercss.js b/js/usercss.js index b3a8a07d..4800221d 100644 --- a/js/usercss.js +++ b/js/usercss.js @@ -393,6 +393,7 @@ var usercss = (() => { }; const style = { + reason: 'install', enabled: true, sourceCode, sections: [], diff --git a/manage/import-export.js b/manage/import-export.js index a4c91a70..865915c9 100644 --- a/manage/import-export.js +++ b/manage/import-export.js @@ -34,7 +34,17 @@ function importFromFile({fileTypeFilter, file} = {}) { const fReader = new FileReader(); fReader.onloadend = event => { fileInput.remove(); - importFromString(event.target.result).then(numStyles => { + const text = event.target.result; + const maybeUsercss = !/^[\s\r\n]*\[/.test(text) && + (text.includes('==UserStyle==') || /==UserStyle==/i.test(text)); + (!maybeUsercss ? + importFromString(text) : + getOwnTab().then(tab => { + tab.url = URL.createObjectURL(new Blob([text], {type: 'text/css'})); + return BG.usercssHelper.openInstallPage(tab, {direct: true}) + .then(() => URL.revokeObjectURL(tab.url)); + }) + ).then(numStyles => { document.body.style.cursor = ''; resolve(numStyles); });