28 lines
756 B
JavaScript
28 lines
756 B
JavaScript
function copyToClipboard(text) {
|
|
const input = document.createElement('input');
|
|
input.style.position = 'fixed';
|
|
input.style.opacity = 0;
|
|
input.value = text;
|
|
document.body.appendChild(input);
|
|
input.select();
|
|
document.execCommand('Copy');
|
|
document.body.removeChild(input);
|
|
};
|
|
|
|
chrome.browserAction.onClicked.addListener(function() {
|
|
var toClipboard = ""
|
|
var separator = "";
|
|
chrome.tabs.query({}, function(tabs) {
|
|
$.each(tabs, function() {
|
|
var url = new URL(this.url);
|
|
var domain = url.hostname;
|
|
if ((domain == "geocaching.com" || domain == "www.geocaching.com") && url.pathname.startsWith("/geocache")) {
|
|
toClipboard += separator + this.title.split(" ")[0];
|
|
separator = ",";
|
|
}
|
|
});
|
|
copyToClipboard(toClipboard);
|
|
});
|
|
});
|
|
|