()
| 297 | * ################################################################## |
| 298 | */ |
| 299 | function fetchFromURL() { |
| 300 | const response = fetch(storage.ruleURL).then(async response => { |
| 301 | return { |
| 302 | data: (await response.clone().text()).trim(), |
| 303 | hash: await sha256((await response.text()).trim()), |
| 304 | status: response.status |
| 305 | } |
| 306 | }) |
| 307 | |
| 308 | response.then(result => { |
| 309 | if (result.status === 200 && result.data) { |
| 310 | if (result.hash === dataHash.trim()) { |
| 311 | storage.ClearURLsData = result.data; |
| 312 | storage.dataHash = result.hash; |
| 313 | storeHashStatus(2); |
| 314 | } else { |
| 315 | storeHashStatus(3); |
| 316 | console.error("The hash does not match. Expected `" + result.hash + "` got `" + dataHash.trim() + "`"); |
| 317 | } |
| 318 | storage.ClearURLsData = JSON.parse(storage.ClearURLsData); |
| 319 | toObject(storage.ClearURLsData); |
| 320 | saveOnDisk(['ClearURLsData', 'dataHash', 'hashStatus']); |
| 321 | } else { |
| 322 | throw "The status code was not okay or the given rules were empty." |
| 323 | } |
| 324 | }).catch(error => { |
| 325 | console.error("[ClearURLs]: Could not download the rules from the given URL due to the following error: ", error); |
| 326 | deactivateOnFailure(); |
| 327 | }); |
| 328 | } |
| 329 | |
| 330 | // ################################################################## |
| 331 |
no test coverage detected