Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions fURL/Chrome Extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
"32": "icons/icon-32.png",
"128": "icons/icon-128.png"
},
"background": {
"service_worker": "service-worker.js"
},
"permissions": [
"tabs",
"activeTab",
Expand All @@ -27,5 +24,9 @@
"default_icon": "icons/icon-38.png",
"default_title": "fURL",
"default_popup": "popup/popup.html"
}
},
"web_accessible_resources": [{
"matches": ["<all_urls>"],
"resources": ["modules/copyURL.js"]
}]
}
59 changes: 59 additions & 0 deletions fURL/Chrome Extension/modules/copyURL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export function copy(url){
console.log("starting copyurl")
console.log(url);
// add URL element and confirming that we have a valid URL
let copyFrom = document.createElement('input');
copyFrom.type = 'url';
copyFrom.value = url;
if (!copyFrom.checkValidity()) {
console.log("copied value isn't a url: " + copyFrom.value);
return;
} else {
console.log("copied value is a url: " + copyFrom.value)
}
// trim the url of any utm elements
copyFrom.value = trimURL(url);
console.log("trimmed_url is " + copyFrom.value);

// Stage 2 Using Clipboard API, copy to clipboard

document.body.appendChild(copyFrom);
copyFrom.select()
document.execCommand('copy');
copyFrom.blur();
document.body.removeChild(copyFrom);

}

export function trimURL(url){
// search for query parameters
const utm_params = new Set(["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "fbclid"]);

let path_split = url.split('?')
console.log("path split is: " + path_split);
let updated_params = "";
if (path_split.length > 1) {
let query_params = path_split[1].split('&');
console.log("query params are: " + query_params);

for (let i=0; i < query_params.length; i++) {
let [key, value] = query_params[i].split('=');
console.log("key: " + key + "| value: " + value);
if (key && !(utm_params.has(key))) {
// re-adding the parameter if it's not in our utm list
updated_params += key + '=' + value;
}
}
} else {
console.log("no query parameters found")
}
console.log("updated params: " + updated_params);

if (updated_params){
updated_params = "?" + updated_params
}
return path_split[0] + updated_params;

}

console.log("copying address bar");
66 changes: 10 additions & 56 deletions fURL/Chrome Extension/scripts/copy_address_bar.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,16 @@
function copyURL2(){
function copy_address(){

let url = window.location.href;

// add URL element and confirming that we have a valid URL
let copyFrom = document.createElement('input');
copyFrom.type = 'url';
copyFrom.value = url;
if (!copyFrom.checkValidity()) {
console.log("copied value isn't a url: " + copyFrom.value);
return;
} else {
console.log("copied value is a url: " + copyFrom.value)
}
// trim the url of any utm elements
copyFrom.value = trimURL(url);
console.log("trimmed_url is " + copyFrom.value);

// Stage 2 Using Clipboard API, copy to clipboard

document.body.appendChild(copyFrom);
copyFrom.select()
document.execCommand('copy');
copyFrom.blur();
document.body.removeChild(copyFrom);

}

function trimURL(url){
// search for query parameters
const utm_params = new Set(["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "fbclid"]);


let path_split = url.split('?')
console.log("path split is: " + path_split);
let updated_params = "";
if (path_split.length > 1) {
let query_params = path_split[1].split('&');
console.log("query params are: " + query_params);

for (let i=0; i < query_params.length; i++) {
let [key, value] = query_params[i].split('=');
console.log("key: " + key + "| value: " + value);
if (key && !(utm_params.has(key))) {
// re-adding the parameter if it's not in our utm list
updated_params += key + '=' + value;
}
}
} else {
console.log("no query parameters found")
}
console.log("updated params: " + updated_params);

if (updated_params){
updated_params = "?" + updated_params
}
return path_split[0] + updated_params;
console.log(url);
// import copyURL and run
(async () => {
const src = chrome.runtime.getURL("modules/copyURL.js");
const copyURL = await import(src);
console.log(copyURL);
copyURL.copy(url);
})();

}

console.log("copying address bar");
copyURL2();
copy_address();
6 changes: 0 additions & 6 deletions fURL/Chrome Extension/service-worker.js

This file was deleted.