|
1 | | -export function insertInfoBox(text) { |
2 | | - let infobox_container = document.querySelector('div#ffibv1'); |
| 1 | +//Constants needed for bypassing |
| 2 | +export const ODP = (t, p, o) => { |
| 3 | + try { |
| 4 | + Object.defineProperty(t, p, o) |
| 5 | + } catch (e) { |
| 6 | + console.trace("[FastForward] Couldn't define", p) |
| 7 | + } |
| 8 | +} |
| 9 | +export const setTimeout = window.setTimeout |
| 10 | +export const setInterval = window.setInterval |
| 11 | +export const URL = window.URL |
| 12 | +export const docSetAttribute = document.documentElement.setAttribute.bind( |
| 13 | + document.documentElement |
| 14 | +) |
| 15 | +let navigated = false |
| 16 | +//Functions used in bypassing |
| 17 | +export function insertInfoBox (text) { |
| 18 | + let infobox_container = document.querySelector('div#ffibv1') |
3 | 19 |
|
4 | | - if (!infobox_container) { |
5 | | - infobox_container = document.createElement('div'); |
6 | | - infobox_container.setAttribute('id', 'ffibv1'); |
7 | | - infobox_container.setAttribute('style', ` |
| 20 | + if (!infobox_container) { |
| 21 | + infobox_container = document.createElement('div') |
| 22 | + infobox_container.setAttribute('id', 'ffibv1') |
| 23 | + infobox_container.setAttribute( |
| 24 | + 'style', |
| 25 | + ` |
8 | 26 | z-index: 99999999; position: fixed; bottom: 0; line-height:normal; |
9 | 27 | right: 0; padding: 20px; color:#111; font-size:21px; |
10 | 28 | font-family:-apple-system,BlinkMacSystemFont,segoe ui,Roboto,helvetica neue,Arial,sans-serif,apple color emoji,segoe ui emoji,segoe ui symbol; |
11 | 29 | max-width:500px; display: flex; flex-direction: column-reverse; |
12 | | - `); |
| 30 | + ` |
| 31 | + ) |
13 | 32 |
|
14 | | - document.body.appendChild(infobox_container); |
15 | | - } |
16 | | - const div = document.createElement("div"); |
17 | | - div.style = 'margin-left:20px; margin-bottom: 20px;background:#eee;border-radius:10px;padding:20px;box-shadow:#111 0px 5px 40px;cursor:pointer'; |
18 | | - div.innerHTML = `<img src="${window.x8675309bp}icon/48.png" style="width:24px;height:24px;margin-right:8px"><span style="display:inline"></span>`; |
19 | | - div.setAttribute("tabindex","-1"); |
20 | | - div.setAttribute("aria-hidden","true"); |
21 | | - const span = div.querySelector("span"); |
22 | | - span.textContent=text; |
23 | | - div.onclick= () => infobox_container.removeChild(div); |
24 | | - infobox_container.appendChild(div); |
25 | | - setTimeout(()=>infobox_container.removeChild(div), 7000); |
| 33 | + document.body.appendChild(infobox_container) |
| 34 | + } |
| 35 | + const div = document.createElement('div') |
| 36 | + div.style = |
| 37 | + 'margin-left:20px; margin-bottom: 20px;background:#eee;border-radius:10px;padding:20px;box-shadow:#111 0px 5px 40px;cursor:pointer' |
| 38 | + div.innerHTML = `<img src="${window.x8675309bp}icon/48.png" style="width:24px;height:24px;margin-right:8px"><span style="display:inline"></span>` |
| 39 | + div.setAttribute('tabindex', '-1') |
| 40 | + div.setAttribute('aria-hidden', 'true') |
| 41 | + const span = div.querySelector('span') |
| 42 | + span.textContent = text |
| 43 | + div.onclick = () => infobox_container.removeChild(div) |
| 44 | + infobox_container.appendChild(div) |
| 45 | + setTimeout(() => infobox_container.removeChild(div), 7000) |
26 | 46 | } |
27 | | - |
28 | | -export function unsafelyNavigate(target, referer=null) { |
29 | | - //The background script will intercept the request and redirect to html/before-navigate.html or to the target depending on the user's settings. |
30 | | - let url = `https://fastforward.team/bypassed?target=${encodeURIComponent(target)}`; |
31 | | - if (referer) |
32 | | - url += `&referer=${encodeURIComponent(referer)}`; |
33 | | - |
34 | | - switch(target)//All values here have been tested using "Take me to destinations after 0 seconds." |
35 | | - { |
36 | | - case (/(krnl\.place|hugegames\.io)/.exec(target)||{}).input: |
37 | | - url+="&safe_in=15" |
38 | | - break; |
39 | | - case (/(bowfile\.com)/.exec(target)||{}).input: |
40 | | - url+="&safe_in=20" |
41 | | - break; |
| 47 | +export function ensureDomLoaded (func) { |
| 48 | + if (['interactive', 'complete'].indexOf(document.readyState)) { |
| 49 | + func() |
| 50 | + } else { |
| 51 | + let triggered = false |
| 52 | + document.addEventListener('DOMContentLoaded', () => { |
| 53 | + if (!triggered) { |
| 54 | + triggered = true |
| 55 | + setTimeout(func, 1) |
| 56 | + } |
| 57 | + }) |
| 58 | + } |
| 59 | +} |
| 60 | +export function awaitElement (elem, func) { |
| 61 | + let time = setInterval(() => { |
| 62 | + let element = document.querySelector(elem) |
| 63 | + if (element) { |
| 64 | + func(element) |
| 65 | + clearInterval(time) |
42 | 66 | } |
| 67 | + }, 10) |
| 68 | + setInterval(() => { |
| 69 | + clearInterval(time) |
| 70 | + }, 30000) |
| 71 | +} |
| 72 | +export function crowdDomain (domain) { |
| 73 | + if (crowdBypassCheckbox.checked && domain) { |
| 74 | + docSetAttribute('{{channel.crowd_domain}}', domain) |
| 75 | + } |
| 76 | +} |
| 77 | +export function crowdPath (path) { |
| 78 | + if (crowdBypassCheckbox.checked && path) { |
| 79 | + docSetAttribute('{{channel.crowd_path}}', path) |
| 80 | + } |
| 81 | +} |
| 82 | +export function crowdReferer (query) { |
| 83 | + if (query) { |
| 84 | + docSetAttribute('{{channel.crowd_referer}}', query) |
| 85 | + } |
| 86 | +} |
| 87 | +export function crowdBypass (func, available) { |
| 88 | + if (!func) { |
| 89 | + func = () => {} |
| 90 | + } |
| 91 | + if (crowdBypassCheckbox.checked) { |
| 92 | + docSetAttribute('{{channel.crowd_query}}', '') |
| 93 | + let youSee = setInterval(() => { |
| 94 | + if (document.documentElement.getAttribute('{{channel.crowd_queried}}')) { |
| 95 | + document.documentElement.removeAttribute('{{channel.crowd_queried}}') |
| 96 | + insertInfoBox('{{msg.crowdWait}}') |
| 97 | + func() |
| 98 | + } |
| 99 | + }, 20) |
| 100 | + } else if (available) { |
| 101 | + func() |
| 102 | + } else { |
| 103 | + insertInfoBox('{{msg.crowdDisabled}}') |
| 104 | + } |
| 105 | +} |
| 106 | +export function crowdContribute (target, func) { |
| 107 | + if (typeof func != 'function') { |
| 108 | + func = () => {} |
| 109 | + } |
| 110 | + if (crowdBypassCheckbox.checked && isGoodLink(target)) { |
| 111 | + docSetAttribute('{{channel.crowd_contribute}}', target) |
| 112 | + setTimeout(func, 10) |
| 113 | + } else { |
| 114 | + func() |
| 115 | + } |
| 116 | +} |
| 117 | +export function contributeAndNavigate (target) { |
| 118 | + if (!navigated && isGoodLink(target)) { |
| 119 | + crowdContribute(target, () => unsafelyNavigate(target)) |
| 120 | + } |
| 121 | +} |
| 122 | +export function unsafelyNavigate (target, referer = null) { |
| 123 | + //The background script will intercept the request and redirect to html/before-navigate.html or to the target depending on the user's settings. |
| 124 | + if (navigated) { |
| 125 | + return |
| 126 | + } |
| 127 | + let url = `https://fastforward.team/bypassed?target=${encodeURIComponent( |
| 128 | + target |
| 129 | + )}` |
| 130 | + if (referer) url += `&referer=${encodeURIComponent(referer)}` |
43 | 131 |
|
44 | | - location.assign(url); |
| 132 | + switch ( |
| 133 | + target //All values here have been tested using "Take me to destinations after 0 seconds." |
| 134 | + ) { |
| 135 | + case (/(krnl\.place|hugegames\.io)/.exec(target) || {}).input: |
| 136 | + url += '&safe_in=15' |
| 137 | + break |
| 138 | + case (/(bowfile\.com)/.exec(target) || {}).input: |
| 139 | + url += '&safe_in=20' |
| 140 | + break |
| 141 | + case (/(flux\.li)/.exec(target) || {}).input: |
| 142 | + url += '&safe_in=25' |
| 143 | + break |
| 144 | + } |
| 145 | + unsafelyAssign(url) |
45 | 146 | } |
46 | 147 |
|
47 | 148 | export function parseTarget (target) { |
48 | | - return target instanceof HTMLAnchorElement ? target.href : target; |
| 149 | + return target instanceof HTMLAnchorElement ? target.href : target |
49 | 150 | } |
50 | 151 |
|
51 | | -export function safelyNavigate(target, drophash) { |
52 | | - target = parseTarget(target) |
53 | | - if(!isGoodLink(target)) |
54 | | - return false |
| 152 | +export function safelyNavigate (target, drophash) { |
| 153 | + target = parseTarget(target) |
| 154 | + if (!isGoodLink(target)) return false |
55 | 155 |
|
56 | | - // bypassed=true |
57 | | - let url = new URL(target) |
58 | | - if(!drophash&&(!url||!url.hash)) |
59 | | - target+=location.hash |
| 156 | + // bypassed=true |
| 157 | + let url = new URL(target) |
| 158 | + if (!drophash && (!url || !url.hash)) target += location.hash |
60 | 159 |
|
61 | | - unsafelyNavigate(target) |
62 | | - return true |
| 160 | + unsafelyNavigate(target) |
| 161 | + return true |
| 162 | +} |
| 163 | +export function unsafelyAssign (target) { |
| 164 | + navigated = true |
| 165 | + window.onbeforeunload = null |
| 166 | + location.assign(target) |
| 167 | +} |
| 168 | +export function safelyAssign (target) { |
| 169 | + target = parseTarget(target) |
| 170 | + if (navigated || !isGoodLink(target)) return false |
| 171 | + bypassed = true |
| 172 | + let url = new URL(target) |
| 173 | + if (!url || !url.hash) target += location.hash |
| 174 | + unsafelyAssign(target) |
| 175 | + return true |
63 | 176 | } |
64 | 177 |
|
65 | | -export function isGoodLink(link) { |
66 | | - if(typeof link !== "string" || link.split("#")[0] === location.href.split("#")[0]) |
67 | | - { |
68 | | - return false |
| 178 | +export function isGoodLink (link) { |
| 179 | + if ( |
| 180 | + typeof link !== 'string' || |
| 181 | + link.split('#')[0] === location.href.split('#')[0] |
| 182 | + ) { |
| 183 | + return false |
| 184 | + } |
| 185 | + try { |
| 186 | + let u = new URL(decodeURI(link).trim().toLocaleLowerCase()) |
| 187 | + //check if host is a private/internal ip |
| 188 | + if ( |
| 189 | + u.hostname === 'localhost' || |
| 190 | + u.hostname === '[::1]' || |
| 191 | + /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/.test(u.hostname) |
| 192 | + ) { |
| 193 | + return false |
69 | 194 | } |
70 | | - try |
71 | | - { |
72 | | - let u = new URL(decodeURI(link).trim().toLocaleLowerCase()) |
73 | | - //check if host is a private/internal ip |
74 | | - if (u.hostname === 'localhost' || u.hostname === '[::1]' || /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/.test(u.hostname)) { |
75 | | - return false |
76 | | - } |
77 | | - const parts = u.hostname.split('.'); |
78 | | - if (parts[0] === '10' || (parts[0] === '172' && (parseInt(parts[1], 10) >= 16 && parseInt(parts[1], 10) <= 31)) || (parts[0] === '192' && parts[1] === '168')) { |
79 | | - return false |
80 | | - } |
81 | | - // Check if protocol is safe |
82 | | - let safeProtocols = ["http:", "https:", "mailto:", "irc:", "telnet:", "tel:", "svn:"] |
83 | | - if (!safeProtocols.includes(u.protocol)) { |
84 | | - return false |
85 | | - } |
| 195 | + const parts = u.hostname.split('.') |
| 196 | + if ( |
| 197 | + parts[0] === '10' || |
| 198 | + (parts[0] === '172' && |
| 199 | + parseInt(parts[1], 10) >= 16 && |
| 200 | + parseInt(parts[1], 10) <= 31) || |
| 201 | + (parts[0] === '192' && parts[1] === '168') |
| 202 | + ) { |
| 203 | + return false |
86 | 204 | } |
87 | | - catch(e) |
88 | | - { |
89 | | - return false |
| 205 | + // Check if protocol is safe |
| 206 | + let safeProtocols = [ |
| 207 | + 'http:', |
| 208 | + 'https:', |
| 209 | + 'mailto:', |
| 210 | + 'irc:', |
| 211 | + 'telnet:', |
| 212 | + 'tel:', |
| 213 | + 'svn:' |
| 214 | + ] |
| 215 | + if (!safeProtocols.includes(u.protocol)) { |
| 216 | + return false |
90 | 217 | } |
91 | | - return true |
| 218 | + } catch (e) { |
| 219 | + return false |
| 220 | + } |
| 221 | + return true |
92 | 222 | } |
93 | 223 |
|
94 | | -export async function bypassRequests(execution_method) { |
95 | | - const rawOpen = XMLHttpRequest.prototype.open; |
96 | | - XMLHttpRequest.prototype.open = function () { |
97 | | - this.addEventListener('load', execution_method); |
98 | | - rawOpen.apply(this, arguments); |
99 | | - }; |
| 224 | +export async function bypassRequests (execution_method) { |
| 225 | + const rawOpen = XMLHttpRequest.prototype.open |
| 226 | + XMLHttpRequest.prototype.open = function () { |
| 227 | + this.addEventListener('load', execution_method) |
| 228 | + rawOpen.apply(this, arguments) |
| 229 | + } |
100 | 230 |
|
101 | | - const rawFetch = window.fetch; |
102 | | - window.fetch = async (requestInfo, init) =>{ |
103 | | - const result = await rawFetch(requestInfo, init); |
104 | | - execution_method(result); |
105 | | - return Promise.resolve(result); |
106 | | - }; |
| 231 | + const rawFetch = window.fetch |
| 232 | + window.fetch = async (requestInfo, init) => { |
| 233 | + const result = await rawFetch(requestInfo, init) |
| 234 | + execution_method(result) |
| 235 | + return Promise.resolve(result) |
| 236 | + } |
107 | 237 | } |
108 | 238 |
|
109 | 239 | export default { |
110 | | - insertInfoBox, |
111 | | - safelyNavigate, |
112 | | - unsafelyNavigate, |
113 | | - parseTarget, |
114 | | - isGoodLink, |
115 | | - bypassRequests, |
| 240 | + insertInfoBox, |
| 241 | + ensureDomLoaded, |
| 242 | + awaitElement, |
| 243 | + crowdDomain, |
| 244 | + crowdPath, |
| 245 | + crowdReferer, |
| 246 | + crowdBypass, |
| 247 | + crowdContribute, |
| 248 | + contributeAndNavigate, |
| 249 | + unsafelyNavigate, |
| 250 | + parseTarget, |
| 251 | + safelyNavigate, |
| 252 | + unsafelyAssign, |
| 253 | + safelyAssign, |
| 254 | + isGoodLink, |
| 255 | + bypassRequests, |
| 256 | + ODP, |
| 257 | + URL |
116 | 258 | } |
0 commit comments