Skip to content

Commit e39ee1a

Browse files
Merge pull request #18 from Ruby-Network/settings
Import/Export Settings
2 parents aa2dcfb + dad3e1c commit e39ee1a

File tree

5 files changed

+101
-155
lines changed

5 files changed

+101
-155
lines changed

'

Lines changed: 0 additions & 155 deletions
This file was deleted.

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @motortruck1221

src/public/js/notify.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,46 @@ function promptCloakingNotify(defaulFunc, secFunc) {
121121
}
122122
})
123123
}
124+
125+
function settingsImportExportChoice(exportFunc, importFunc) {
126+
Swal.fire({
127+
title: 'Import/Export',
128+
text: `Select Between the two options`,
129+
icon: 'warning',
130+
showCancelButton: true,
131+
confirmButtonColor: '#3085d6',
132+
cancelButtonColor: '#d33',
133+
color: 'var(--text-color)',
134+
background: 'var(--bg-color)',
135+
confirmButtonText: 'Export',
136+
cancelButtonText: 'Import',
137+
}).then((result) => {
138+
if (result.isConfirmed) {
139+
Swal.fire({
140+
title: 'Export',
141+
text: `Exporting settings...`,
142+
icon: 'success',
143+
color: 'var(--text-color)',
144+
background: 'var(--bg-color)',
145+
}).then(() => {
146+
exportFunc();
147+
})
148+
}
149+
else {
150+
Swal.fire({
151+
title: 'Import',
152+
text: 'Importing settings...',
153+
color: 'var(--text-color)',
154+
background: 'var(--bg-color)',
155+
icon: 'success',
156+
}).then(() => {
157+
try {
158+
importFunc();
159+
}
160+
catch {
161+
console.log('No default function found');
162+
}
163+
})
164+
}
165+
})
166+
}

src/public/js/settings.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,59 @@ function reset() {
133133
fullScreenChange('page');
134134
setItems();
135135
}
136+
function exportSettings() {
137+
let title = localStorage.getItem('title');
138+
let favicon = localStorage.getItem('favicon');
139+
let theme = localStorage.getItem('theme');
140+
let search = localStorage.getItem('searchEngine');
141+
let proxy = localStorage.getItem('proxy');
142+
let fullscreen = localStorage.getItem('fullScreen');
143+
let bare = localStorage.getItem('bare');
144+
let settings = {
145+
title: title,
146+
favicon: favicon,
147+
theme: theme,
148+
search: search,
149+
proxy: proxy,
150+
fullscreen: fullscreen,
151+
bare: bare
152+
}
153+
let a = document.createElement('a');
154+
let file = new Blob([JSON.stringify(settings)], { type: 'text/plain' });
155+
let url = URL.createObjectURL(file);
156+
a.href = url;
157+
a.download = 'ruby_settings.json';
158+
a.click();
159+
URL.revokeObjectURL(url);
160+
a.remove();
161+
}
162+
function importSettings() {
163+
let input = document.createElement('input');
164+
input.type = 'file';
165+
input.accept = '.json';
166+
input.onchange = function() {
167+
let file = input.files[0];
168+
let reader = new FileReader();
169+
reader.readAsText(file);
170+
reader.onload = function() {
171+
let settings = JSON.parse(reader.result);
172+
localStorage.setItem('title', settings.title);
173+
localStorage.setItem('favicon', settings.favicon);
174+
localStorage.setItem('theme', settings.theme);
175+
localStorage.setItem('searchEngine', settings.search);
176+
localStorage.setItem('proxy', settings.proxy);
177+
localStorage.setItem('fullScreen', settings.fullscreen);
178+
localStorage.setItem('bare', settings.bare);
179+
setItems();
180+
console.log('Imported settings');
181+
window.location.reload();
182+
}
183+
}
184+
input.click();
185+
}
186+
function importExportSettings() {
187+
settingsImportExportChoice(exportSettings, importSettings);
188+
}
136189

137190
function init() {
138191
let init = localStorage.getItem('init');

src/views/components/settings.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,9 @@
9494
<h2> Reset Settings </h2>
9595
<button id="resetButton" class="button" onclick="reset()">Reset</button>
9696
</div>
97+
<div id="tile">
98+
<h2> Import/Export Settings </h2>
99+
<button id="imExButton" class="button" onclick="importExportSettings()">Click Here</button>
100+
</div>
97101
</div>
98102
</div>

0 commit comments

Comments
 (0)