Skip to content

Instantly share code, notes, and snippets.

@hc0d3r
Last active July 22, 2019 06:55
Show Gist options
  • Save hc0d3r/623ed71a196af10301ec99648b30b5c0 to your computer and use it in GitHub Desktop.
Save hc0d3r/623ed71a196af10301ec99648b30b5c0 to your computer and use it in GitHub Desktop.
remove fbclid
function remove_fbclid(details){
let index, url = details.url, update = 0;
index = url.indexOf('facebook.com/l.php?u=');
if(index > -1 && index < 15){
url = url.substring(index+21, url.indexOf('&'));
if(url !== undefined){
url = decodeURIComponent(url);
update = 1;
}
}
if((index = url.indexOf('?')) != -1){
const query = url.substring(index+1);
let parameters = query.split('&');
for(let i = 0; i<parameters.length; i++){
let p = parameters[i];
if(p.indexOf('fbclid=') == 0){
if((pos = p.indexOf('#')) != -1){
parameters[i] = p.substring(pos, p.length);
} else {
parameters.splice(i, 1);
}
url = url.substring(0, index);
update = 1;
if(parameters.length)
url += '?' + parameters.join('&');
break;
}
};
}
if(update){
chrome.tabs.update(details.tabId, { url: url });
}
}
chrome.webNavigation.onBeforeNavigate.addListener(remove_fbclid);
{
"manifest_version": 2,
"name": "fbclid remove",
"version": "0.1.4",
"permissions": [
"webNavigation"
],
"background": {
"scripts": ["background.js"],
"persistent": false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment