Skip to content

Commit 58d95d3

Browse files
zoraconpipboy96
andauthored
Feature: EASE Copy Url (EFForg#19568)
Feature: Ease - Copy URL Button Closes EFForg#19385 Adds feature to copy unencrypted link from EASE warning page * minor: Remove unneeded CSS id reference * Add in translation string * Update chromium/pages/cancel/ux.js Co-authored-by: pipboy96 <pipboy96@protonmail.com>
1 parent 13dfd7d commit 58d95d3

4 files changed

Lines changed: 60 additions & 2 deletions

File tree

chromium/pages/cancel/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ <h1 id="https-everywhere">
1818
<p id="url-paragraph">
1919
<span id="url-label">URL: </span><span id="url-value"></span>
2020
</p>
21+
<button id="copy-url" data-i18n="cancel_copy_url"></button>
2122

2223
<div class="actions">
2324
<button id="open-url-button" data-i18n="cancel_open_page"></button>

chromium/pages/cancel/style.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ h1 img {
2020
}
2121

2222
#url-paragraph {
23-
display: block;
23+
display: inline-flex;
2424
overflow: hidden;
2525
white-space: nowrap;
2626
text-overflow: ellipsis;
@@ -33,7 +33,6 @@ button {
3333
color: #fff;
3434
cursor: pointer;
3535
padding: 0.5em 1em;
36-
display: block;
3736
float: none;
3837
font-size: 12pt;
3938
margin: 8px 0;

chromium/pages/cancel/ux.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function displayURL() {
4545
const originURLLink = document.getElementById('url-value');
4646
const openURLButton = document.getElementById('open-url-button');
4747
const openHttpOnce = document.getElementById('http-once-button');
48+
const copyButton = document.getElementById('copy-url');
4849
const url = new URL(originURL);
4950

5051
originURLLink.innerText = originURL;
@@ -60,6 +61,61 @@ function displayURL() {
6061
return false;
6162
});
6263

64+
// Copy URL Feature on EASE
65+
66+
function copyLinkAlternate() {
67+
let isSuccessful = false;
68+
69+
const sel = window.getSelection();
70+
71+
try {
72+
sel.removeAllRanges();
73+
74+
const range = document.createRange();
75+
range.selectNode(originURLLink);
76+
77+
sel.addRange(range);
78+
79+
isSuccessful = document.execCommand("copy");
80+
81+
sel.removeAllRanges();
82+
83+
return isSuccessful;
84+
} catch (err) {
85+
console.error(err);
86+
87+
sel.removeAllRanges();
88+
89+
return false;
90+
}
91+
}
92+
93+
async function copyLink() {
94+
try {
95+
await navigator.clipboard.writeText(originURL);
96+
return true;
97+
} catch (err) {
98+
return copyLinkAlternate();
99+
}
100+
}
101+
102+
let restoreTimeout = null;
103+
104+
copyButton.addEventListener("click", async () => {
105+
if (await copyLink()) {
106+
copyButton.innerText = chrome.i18n.getMessage("cancel_copied_url");
107+
108+
if (restoreTimeout !== null) {
109+
clearTimeout(restoreTimeout);
110+
}
111+
112+
restoreTimeout = setTimeout(() => {
113+
copyButton.innerText = chrome.i18n.getMessage("cancel_copy_url");
114+
restoreTimeout = null;
115+
}, 1500);
116+
}
117+
});
118+
63119
openHttpOnce.addEventListener("click", function() {
64120
if (confirm(chrome.i18n.getMessage("chrome_disable_on_this_site") + '?')) {
65121
sendMessage("disable_on_site_once", url.host, () => {

src/chrome/locale/en/https-everywhere.dtd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
<!ENTITY https-everywhere.cancel.he_blocking_explainer "HTTPS Everywhere noticed you were navigating to a non-HTTPS page, and tried to send you to the HTTPS version instead. The HTTPS version is unavailable. Most likely this site does not support HTTPS, but it is also possible that an attacker is blocking the HTTPS version. If you wish to view the unencrypted version of this page, you can still do so by disabling the 'Encrypt All Sites Eligible' (EASE) option in your HTTPS Everywhere extension. Be aware that disabling this option could make your browser vulnerable to network-based downgrade attacks on websites you visit.">
4949
<!ENTITY https-everywhere.cancel.he_blocking_network "network-based downgrade attacks">
50+
<!ENTITY https-everywhere.cancel.copy_url "Copy URL">
51+
<!ENTITY https-everywhere.cancel.copied_url "Copied to Clipboard">
5052
<!ENTITY https-everywhere.cancel.open_page "Open insecure page">
5153
<!ENTITY https-everywhere.cancel.http_once "Open insecure page for this session only">
5254

0 commit comments

Comments
 (0)