Skip to content

Commit aa2dcfb

Browse files
Blob cloaking
1 parent 99b1813 commit aa2dcfb

File tree

4 files changed

+223
-2
lines changed

4 files changed

+223
-2
lines changed

'

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
localforage.config({
2+
driver : localforage.INDEXEDDB,
3+
name : 'Ruby',
4+
version : 1.0,
5+
storeName : 'ruby_config', // Should be alphanumeric, with underscores.
6+
description : 'Ruby Config for things in sw',
7+
});
8+
function bare(value) {
9+
if (!value.endsWith('/')) { value = value + '/'; }
10+
if (!value.startsWith('http://') && !value.startsWith('https://') && value !== '/bare/' && value !== '/bare') { value = 'https://' + value; }
11+
if ( value !== '/bare/' && value !== '/bare' ) {
12+
fetch(value).then(function(response) {
13+
if (response.status !== 200) { return false; }
14+
bareChange(value)
15+
localStorage.setItem('bare', value);
16+
}).catch(function(err) {
17+
console.log('Fetch Error :-S', err);
18+
bareChange('/bare/');
19+
});
20+
}
21+
else {
22+
bareChange(value);
23+
}
24+
}
25+
function setTitle(value) {
26+
localStorage.setItem('title', value);
27+
document.title = value;
28+
}
29+
function favicon(value) {
30+
localStorage.setItem('favicon', value);
31+
document.getElementById('favicon').href = value;
32+
}
33+
function theme(value) {
34+
localStorage.setItem('theme', value);
35+
document.documentElement.className = value;
36+
}
37+
function searchSettings(value) {
38+
localStorage.setItem('searchEngine', value);
39+
}
40+
function proxyChange(value) {
41+
const setValue = function() {
42+
localStorage.setItem('proxy', value);
43+
}
44+
const defaultFUNC = function() {
45+
setItems();
46+
}
47+
if (value === 'dynamic') {
48+
notifyBeta('Dynamic', setValue, defaultFUNC);
49+
}
50+
if (value === 'rammerhead') {
51+
notifyWithConfirm('Rammerhead', 'is a server based proxy so it MAY run slower, as well as breaking the URL bar of the browser. Are you sure you want to use Rammerhead?', setValue, defaultFUNC);
52+
}
53+
else {
54+
setValue();
55+
}
56+
}
57+
function aboutBlank() {
58+
window.location.replace('https://google.com');
59+
const win = window.open();
60+
win.document.body.style.margin = '0';
61+
win.document.body.style.height = '100vh';
62+
const iframe = win.document.createElement('iframe');
63+
iframe.style.border = 'none';
64+
iframe.style.width = '100%';
65+
iframe.style.height = '100%';
66+
iframe.style.margin = '0';
67+
const url = window.location.href;
68+
iframe.src = url;
69+
win.document.body.appendChild(iframe);
70+
}
71+
function jsBLOB() {
72+
const htmlContent = `
73+
<!DOCTYPE html>
74+
<html>
75+
<head>
76+
<style type="text/css">
77+
body, html { margin: 0; padding: 0; height: 100%; overflow: hidden; }
78+
</style>
79+
</head>
80+
<body>
81+
<iframe style="border: none; width: 100%; height: 100vh;" src="${window.location.href}"></iframe>
82+
</body>
83+
</html>
84+
`;
85+
86+
window.location.replace('https://google.com');
87+
const blob = new Blob([htmlContent], { type: 'text/html' });
88+
const blobURL = URL.createObjectURL(blob);
89+
const newWindow = window.open(blobURL, '_blank');
90+
}
91+
function promptCloaking() {
92+
promptCloakingNotify(aboutBlank, jsBLOB);
93+
}
94+
95+
function fullScreenChange(value) {
96+
localStorage.setItem('fullScreen', value);
97+
}
98+
99+
function setItems() {
100+
let titleInput = document.getElementById('titleInput');
101+
let faviconInput = document.getElementById('faviconInput');
102+
let themeSelect = document.getElementById('themeSelect');
103+
let searchInput = document.getElementById('searchInput');
104+
let proxySelect = document.getElementById('proxySelect');
105+
let fullscreenSelect = document.getElementById('fullscreenSelect');
106+
let bareInput = document.getElementById('bareInput');
107+
let title = localStorage.getItem('title');
108+
let favicon = localStorage.getItem('favicon');
109+
let theme = localStorage.getItem('theme');
110+
let search = localStorage.getItem('searchEngine');
111+
let proxy = localStorage.getItem('proxy');
112+
let fullscreen = localStorage.getItem('fullScreen');
113+
let bare = localStorage.getItem('bare');
114+
titleInput.value = title;
115+
faviconInput.value = favicon;
116+
themeSelect.value = theme;
117+
searchInput.value = search;
118+
proxySelect.value = proxy;
119+
fullscreenSelect.value = fullscreen;
120+
if (bare === window.location.origin + '/bare/') { bareInput.value = '/bare/'; } else { bareInput.value = bare; }
121+
document.documentElement.className = localStorage.getItem('theme');
122+
document.title = title;
123+
document.getElementById('favicon').href = favicon;
124+
}
125+
function reset() {
126+
localStorage.clear();
127+
bareChange(window.location.origin + '/bare/');
128+
setTitle('Ruby');
129+
favicon('/favicon.ico');
130+
theme('default');
131+
searchSettings('https://www.google.com/search?q=%s');
132+
proxyChange('uv');
133+
fullScreenChange('page');
134+
setItems();
135+
}
136+
137+
function init() {
138+
let init = localStorage.getItem('init');
139+
if (init === null || init === undefined || init === 'false') {
140+
bareInit();
141+
localStorage.setItem('init', true);
142+
localStorage.setItem('title', 'Ruby');
143+
localStorage.setItem('favicon', '/favicon.ico');
144+
localStorage.setItem('theme', 'default');
145+
localStorage.setItem('searchEngine', 'https://www.google.com/search?q=%s');
146+
localStorage.setItem('proxy', 'uv');
147+
localStorage.setItem('bare', window.location.origin + '/bare/');
148+
localStorage.setItem('fullScreen', 'page');
149+
setItems();
150+
}
151+
else {
152+
setItems();
153+
}
154+
}
155+
init();

src/public/js/notify.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,46 @@ function notifyWithConfirm(value, text, functionToRun, defaulFunction) {
7878
}
7979
})
8080
}
81+
82+
function promptCloakingNotify(defaulFunc, secFunc) {
83+
Swal.fire({
84+
title: 'About Blank/Blob Cloaking',
85+
text: `Select Between the two options`,
86+
icon: 'warning',
87+
showCancelButton: true,
88+
confirmButtonColor: '#3085d6',
89+
cancelButtonColor: '#d33',
90+
color: 'var(--text-color)',
91+
background: 'var(--bg-color)',
92+
confirmButtonText: 'About:Blank',
93+
cancelButtonText: 'Blob',
94+
}).then((result) => {
95+
if (result.isConfirmed) {
96+
Swal.fire({
97+
title: 'About Blank',
98+
text: `About Blank Cloaking is now enabled.`,
99+
icon: 'success',
100+
color: 'var(--text-color)',
101+
background: 'var(--bg-color)',
102+
}).then(() => {
103+
defaulFunc();
104+
})
105+
}
106+
else {
107+
Swal.fire({
108+
title: 'Blob',
109+
text: 'Blob Cloaking is now enabled',
110+
color: 'var(--text-color)',
111+
background: 'var(--bg-color)',
112+
icon: 'success',
113+
}).then(() => {
114+
try {
115+
secFunc();
116+
}
117+
catch {
118+
console.log('No default function found');
119+
}
120+
})
121+
}
122+
})
123+
}

src/public/js/settings.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,29 @@ function aboutBlank() {
6868
iframe.src = url;
6969
win.document.body.appendChild(iframe);
7070
}
71+
function jsBLOB() {
72+
const htmlContent = `
73+
<!DOCTYPE html>
74+
<html>
75+
<head>
76+
<style type="text/css">
77+
body, html { margin: 0; padding: 0; height: 100%; overflow: hidden; }
78+
</style>
79+
</head>
80+
<body>
81+
<iframe style="border: none; width: 100%; height: 100vh;" src="${window.location.href}"></iframe>
82+
</body>
83+
</html>
84+
`;
85+
86+
window.location.replace('https://google.com');
87+
const blob = new Blob([htmlContent], { type: 'text/html' });
88+
const blobURL = URL.createObjectURL(blob);
89+
const newWindow = window.open(blobURL, '_blank');
90+
}
91+
function promptCloaking() {
92+
promptCloakingNotify(aboutBlank, jsBLOB);
93+
}
7194

7295
function fullScreenChange(value) {
7396
localStorage.setItem('fullScreen', value);

src/views/components/settings.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
8383
</select>
8484
</div>
8585
<div id="tile">
86-
<h2> About Blank Cloaking </h2>
87-
<button id="blankButton" class="button" onclick="aboutBlank()">Toggle</button>
86+
<h2> About Blank/Blob Cloaking </h2>
87+
<button id="blankButton" class="button" onclick="promptCloaking()">Toggle</button>
8888
</div>
8989
<div id="tile">
9090
<h2> Update Service Workers </h2>

0 commit comments

Comments
 (0)