|
| 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(); |
0 commit comments