Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Commit 68ae2d1

Browse files
committed
Highlight the URL on click
1 parent c96334e commit 68ae2d1

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

chromium/pages/cancel/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<h1 id="https-everywhere"><img src="../../images/banner-red.png" alt="HTTPS Everywhere" /></h1>
1313
<p data-i18n="cancel_he_blocking_explainer"></p>
1414
<p id="url-paragraph">
15-
<span id="url-label">URL: </span><a href="#" id="url-value">PLACEHOLDER</a>
15+
<span id="url-label">URL: </span><span id="url-value">PLACEHOLDER</span>
1616
</p>
1717
<form method="get" action="#" id="url-form">
1818
<button name="open" formaction="#" id="open-url-button">Open insecurely and do not ask again</button>

chromium/pages/cancel/style.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ form button{
2828
padding: 8px 16px;
2929
}
3030

31-
#open-url-button {
31+
#open-url-button{
3232
cursor: pointer;
3333
display: inline-block;
3434
margin: 0;
@@ -43,3 +43,8 @@ form button{
4343
border: 0;
4444
border-radius: 5px;
4545
}
46+
47+
#url-value{
48+
-moz-user-select: text;
49+
user-select: text;
50+
}

chromium/pages/cancel/ux.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ document.addEventListener("DOMContentLoaded", () => {
1616
displayURL();
1717
});
1818

19+
/**
20+
* Highlights the content (text, images, etc.) of an element
21+
* @param {Element}
22+
* @returns {void}
23+
*/
24+
function highlightElementContent(element) {
25+
if (window.getSelection) {
26+
var range = document.createRange();
27+
range.selectNode(element);
28+
window.getSelection().addRange(range);
29+
}
30+
}
31+
1932
function replaceLink(explainer) {
2033
observer.disconnect();
2134
const linkText = chrome.i18n.getMessage("cancel_he_blocking_network");
@@ -28,14 +41,17 @@ function replaceLink(explainer) {
2841
function displayURL() {
2942
const cancelURL = new URL(window.location.href);
3043
const originURL = decodeURI(cancelURL.searchParams.get('originURL'));
31-
const originURLLinkElement = document.getElementById('url-value');
44+
const originURLLink = document.getElementById('url-value');
3245
const originURLForm = document.getElementById('url-form');
3346
const openURLButton = document.getElementById('open-url-button');
3447

35-
originURLLinkElement.href = originURL;
36-
originURLLinkElement.innerText = originURL;
48+
originURLLink.innerHTML = originURL;
3749
openURLButton.formaction = originURL;
3850

51+
originURLLink.addEventListener("click", function(event) {
52+
highlightElementContent(event.target);
53+
});
54+
3955
originURLForm.addEventListener("submit", function(event) {
4056
event.preventDefault();
4157

0 commit comments

Comments
 (0)