import and export based on http://add0n.com/useragent-switcher.html#IDComment1079854533
This commit is contained in:
parent
00909fa7b9
commit
b99fd158bb
3 changed files with 56 additions and 1 deletions
|
@ -70,6 +70,11 @@
|
||||||
<td><textarea id="protected" rows="3" wrap="off"></textarea></td>
|
<td><textarea id="protected" rows="3" wrap="off"></textarea></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<button id="import">Import Settings</button>
|
||||||
|
<button id="export">Export Settings</button>
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<button id="help">FAQs Page (Help)</button>
|
<button id="help">FAQs Page (Help)</button>
|
||||||
<button id="donate">Support Development</button>
|
<button id="donate">Support Development</button>
|
||||||
|
|
|
@ -135,3 +135,53 @@ document.getElementById('help').addEventListener('click', () => {
|
||||||
url: chrome.runtime.getManifest().homepage_url
|
url: chrome.runtime.getManifest().homepage_url
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// export
|
||||||
|
document.getElementById('export').addEventListener('click', () => {
|
||||||
|
chrome.storage.local.get(null, prefs => {
|
||||||
|
const text = JSON.stringify(prefs, null, ' ');
|
||||||
|
const blob = new Blob([text], {type: 'application/json'});
|
||||||
|
const objectURL = URL.createObjectURL(blob);
|
||||||
|
Object.assign(document.createElement('a'), {
|
||||||
|
href: objectURL,
|
||||||
|
type: 'application/json',
|
||||||
|
download: 'useragent-switcher-preferences.json'
|
||||||
|
}).dispatchEvent(new MouseEvent('click'));
|
||||||
|
setTimeout(() => URL.revokeObjectURL(objectURL));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// import
|
||||||
|
document.getElementById('import').addEventListener('click', () => {
|
||||||
|
const input = document.createElement('input');
|
||||||
|
input.style.display = 'none';
|
||||||
|
input.type = 'file';
|
||||||
|
input.accept = '.json';
|
||||||
|
input.acceptCharset = 'utf-8';
|
||||||
|
|
||||||
|
document.body.appendChild(input);
|
||||||
|
input.initialValue = input.value;
|
||||||
|
input.onchange = readFile;
|
||||||
|
input.click();
|
||||||
|
|
||||||
|
function readFile() {
|
||||||
|
if (input.value !== input.initialValue) {
|
||||||
|
const file = input.files[0];
|
||||||
|
if (file.size > 100e6) {
|
||||||
|
console.warn('100MB backup? I don\'t believe you.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onloadend = event => {
|
||||||
|
input.remove();
|
||||||
|
const json = JSON.parse(event.target.result);
|
||||||
|
chrome.storage.local.clear(() => {
|
||||||
|
chrome.storage.local.set(json, () => {
|
||||||
|
window.close();
|
||||||
|
chrome.runtime.reload();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
reader.readAsText(file, 'utf-8');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
<td>userAgent</td>
|
<td>userAgent</td>
|
||||||
<td colspan="3">
|
<td colspan="3">
|
||||||
<div hbox>
|
<div hbox>
|
||||||
<input id="ua" type="text" placeholder="Your preferred user-agent string" title="To set blank user-agent string, use 'empty' keyword">
|
<input id="ua" type="text" placeholder="Your preferred user-agent string" title="To set a blank user-agent string, use the 'empty' keyword. To construct a custom user-agent string based on the current browser's navigator object, use ${} notation. Whatever is inside this notation is read from the 'navigator' object. For instance, to append a string to the default user-agent, use '${userAgent} THIS IS THE APPENDED STRING'">
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
Loading…
Reference in a new issue