MCPcopy Index your code
hub / github.com/ClearURLs/Addon / clearUrl

Function clearUrl

clearurls.js:608–685  ·  view source on GitHub ↗

* Function which called from the webRequest to * remove the tracking fields from the url. * * @param {requestDetails} request webRequest-Object * @return {Array} redirectUrl or none

(request)

Source from the content-addressed store, hash-verified

606 * @return {Array} redirectUrl or none
607 */
608 function clearUrl(request) {
609 const URLbeforeReplaceCount = countFields(request.url);
610
611 //Add Fields form Request to global url counter
612 increaseTotalCounter(URLbeforeReplaceCount);
613
614 if (storage.globalStatus) {
615 let result = {
616 "changes": false,
617 "url": "",
618 "redirect": false,
619 "cancel": false
620 };
621
622 if (storage.pingBlocking && storage.pingRequestTypes.includes(request.type)) {
623 pushToLog(request.url, request.url, translate('log_ping_blocked'));
624 increaseBadged(false, request);
625 increaseTotalCounter(1);
626 return {cancel: true};
627 }
628
629 /*
630 * Call for every provider the removeFieldsFormURL method.
631 */
632 for (let i = 0; i < providers.length; i++) {
633 if (!providers[i].matchMethod(request)) continue;
634 if (providers[i].matchURL(request.url)) {
635 result = removeFieldsFormURL(providers[i], request.url, false, request);
636 }
637
638 /*
639 * Expand urls and bypass tracking.
640 * Cancel the active request.
641 */
642 if (result.redirect) {
643 if (providers[i].shouldForceRedirect() &&
644 request.type === 'main_frame') {
645 browser.tabs.update(request.tabId, {url: result.url}).catch(handleError);
646 return {cancel: true};
647 }
648
649 return {
650 redirectUrl: result.url
651 };
652 }
653
654 /*
655 * Cancel the Request and redirect to the site blocked alert page,
656 * to inform the user about the full url blocking.
657 */
658 if (result.cancel) {
659 if (request.type === 'main_frame') {
660 const blockingPage = browser.runtime.getURL("html/siteBlockedAlert.html?source=" + encodeURIComponent(request.url));
661 browser.tabs.update(request.tabId, {url: blockingPage}).catch(handleError);
662
663 return {cancel: true};
664 } else {
665 return {

Callers 1

promiseFunction · 0.85

Calls 6

countFieldsFunction · 0.85
increaseTotalCounterFunction · 0.85
pushToLogFunction · 0.85
increaseBadgedFunction · 0.85
removeFieldsFormURLFunction · 0.85
translateFunction · 0.50

Tested by

no test coverage detected