Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: sharing via clipboard for no https/localhost environments #5606

Merged
merged 5 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 31 additions & 5 deletions p/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1087,11 +1087,31 @@ function init_stream(stream) {
}

el = ev.target.closest('.item.share > button[data-type="clipboard"]');
if (el && navigator.clipboard) { // Clipboard
navigator.clipboard.writeText(el.dataset.url);
el.classList.remove('ok');
el.dataset.foo = el.offsetWidth; // it does nothing, but it is needed. See https://github.com/FreshRSS/FreshRSS/pull/5295
el.classList.add('ok');
if (el) { // Clipboard
if (navigator.clipboard) {
navigator.clipboard.writeText(el.dataset.url)
.then(() => {
toggleClass(el, 'error');
})
.catch(e => {
console.log(e);
toggleClass(el, 'error');
});
} else {
Alkarex marked this conversation as resolved.
Show resolved Hide resolved
// fallback, if navigator.clipboard is not available f.e. if access is not via https or localhost
const inputElement = document.createElement('input');
inputElement.value = el.dataset.url;
document.body.appendChild(inputElement);
inputElement.select();
if (document.execCommand && document.execCommand('copy')) {
toggleClass(el, 'ok');
} else {
console.log('document.execCommand("copy") failed');
toggleClass(el, 'error');
}
inputElement.remove();
}

return false;
}

Expand Down Expand Up @@ -1225,6 +1245,12 @@ function init_stream(stream) {
};
}

function toggleClass(el, cssclass) {
el.classList.remove(cssclass);
el.dataset.foo = el.offsetWidth; // it does nothing, but it is needed. See https://github.com/FreshRSS/FreshRSS/pull/5295
el.classList.add(cssclass);
}

function init_nav_entries() {
const nav_entries = document.getElementById('nav_entries');
if (nav_entries) {
Expand Down
10 changes: 10 additions & 0 deletions p/themes/base-theme/frss.css
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,16 @@ html.slider-active {
animation-name: easeOut;
}

.item.share button.error::before {
content: "❌";
position: absolute;
left: 0.25rem;
}

.item.share button.error {
text-decoration: line-through;
}

@keyframes easeOut {
0% {opacity: 1;}

Expand Down
10 changes: 10 additions & 0 deletions p/themes/base-theme/frss.rtl.css
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,16 @@ html.slider-active {
animation-name: easeOut;
}

.item.share button.error::before {
content: "❌";
position: absolute;
right: 0.25rem;
}

.item.share button.error {
text-decoration: line-through;
}

@keyframes easeOut {
0% {opacity: 1;}

Expand Down