| 197 | // Bypass definition management |
| 198 | let updateStatus = "", injectionScript = "", preflightRules = {}, upstreamInjectionScript = "", upstreamCommit, channel = {}, optionsTab, optionsPort, bypassClipboard = "" |
| 199 | const updateBypassDefinitions = callback => { |
| 200 | if(updateStatus != "") |
| 201 | { |
| 202 | return |
| 203 | } |
| 204 | if(typeof callback != "function") |
| 205 | { |
| 206 | callback = () => {} |
| 207 | } |
| 208 | updateStatus = "checking" |
| 209 | sendToOptions({updateStatus}) |
| 210 | const finishDownload = () => { |
| 211 | channel = {} |
| 212 | let uniqueness = [] |
| 213 | ;["stop_watching","count_it","crowd_referer","crowd_domain","crowd_path","crowd_query","crowd_queried","crowd_contribute","adlinkfly_info","adlinkfly_target","bypass_clipboard"].forEach(name => { |
| 214 | let val |
| 215 | do |
| 216 | { |
| 217 | val = Math.random().toString().substr(2) |
| 218 | } |
| 219 | while(uniqueness.indexOf(val) != -1); |
| 220 | uniqueness.push(val) |
| 221 | upstreamInjectionScript = upstreamInjectionScript.split("{{channel."+name+"}}").join(channel[name] = "data-" + val) |
| 222 | }) |
| 223 | ;["infoLinkvertise","infoFileHoster","infoOutdated","crowdWait","crowdDisabled"].forEach(name => { |
| 224 | upstreamInjectionScript = upstreamInjectionScript.split("{{msg."+name+"}}").join(brws.i18n.getMessage(name).split("\\").join("\\\\").split("\"").join("\\\"")) |
| 225 | }) |
| 226 | upstreamInjectionScript = upstreamInjectionScript.split("{{icon/48.png}}").join(brws.runtime.getURL("icon/48.png")) |
| 227 | refreshInjectionScript() |
| 228 | updateStatus = "" |
| 229 | sendToOptions({upstreamCommit, updateStatus}) |
| 230 | } |
| 231 | let xhr = new XMLHttpRequest() |
| 232 | xhr.onload = () => { |
| 233 | updateStatus = "updating" |
| 234 | upstreamCommit = definitions_version |
| 235 | sendToOptions({upstreamCommit, updateStatus}) |
| 236 | callback(true) |
| 237 | upstreamInjectionScript = xhr.responseText |
| 238 | xhr = new XMLHttpRequest() |
| 239 | xhr.open("GET", brws.runtime.getURL("rules.json"), true) |
| 240 | xhr.onload = () => { |
| 241 | preflightRules = JSON.parse(xhr.responseText) |
| 242 | finishDownload() |
| 243 | } |
| 244 | xhr.send() |
| 245 | } |
| 246 | if(definitions_version==="") |
| 247 | { |
| 248 | xhr.onerror = () => { |
| 249 | let xhr = new XMLHttpRequest() |
| 250 | xhr.onload = () => { |
| 251 | const latestCommit = JSON.parse(xhr.responseText).sha |
| 252 | if(latestCommit == upstreamCommit) |
| 253 | { |
| 254 | updateStatus = "" |
| 255 | sendToOptions({updateStatus}) |
| 256 | callback(false) |
no test coverage detected