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

Hide watch/blacklist buttons when action has already been taken #144

Merged
merged 1 commit into from
Dec 7, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions dist/fire_extra.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,11 @@
const container = document.createElement("div");
const watchButton = document.createElement("a");
watchButton.classList.add("fire-extra-watch");
watchButton.style.display = "none";
watchButton.innerHTML = "!!/watch";
const blacklistButton = document.createElement("a");
blacklistButton.classList.add("fire-extra-blacklist");
blacklistButton.style.display = "none";
blacklistButton.innerHTML = "!!/blacklist";
container.append(watchButton, blacklistButton);
return container;
Expand Down Expand Up @@ -547,15 +549,12 @@
const watch = {
human: helpers.getActionDone("watched", isWatched),
tooltip: helpers.getButtonsText("watch", term, isWatched || isBlacklisted, domainName),
suggested: qualifiesForWatch && !isWatched && !isBlacklisted,
// note the button should be disabled if the domain is blacklisted
class: `fire-extra-${isWatched || isBlacklisted ? "disabled" : "watch"}`
suggested: qualifiesForWatch && !isWatched && !isBlacklisted
};
const blacklist = {
human: helpers.getActionDone("blacklisted", isBlacklisted),
tooltip: helpers.getButtonsText("blacklist", term, isBlacklisted, domainName),
suggested: qualifiesForBlacklist && !isBlacklisted,
class: `fire-extra-${isBlacklisted ? "disabled" : "blacklist"}`
suggested: qualifiesForBlacklist && !isBlacklisted
};
const watchInfo = domainLi?.querySelector(".fire-extra-watch-info");
const blacklistInfo = domainLi?.querySelector(".fire-extra-blacklist-info");
Expand All @@ -573,8 +572,12 @@
watchButton.append(" ", getTick());
if (blacklist.suggested)
blacklistButton.append(" ", getTick());
watchButton.classList.add(watch.class);
blacklistButton.classList.add(blacklist.class);
if (!isBlacklisted) {
blacklistButton.style.display = "inline";
if (!isWatched) {
watchButton.style.display = "inline";
}
}
watchButton.setAttribute("fire-tooltip", watch.tooltip);
blacklistButton.setAttribute("fire-tooltip", blacklist.tooltip);
}
Expand Down
2 changes: 2 additions & 0 deletions src/dom_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ export function getWatchBlacklistButtons(): HTMLDivElement {

const watchButton = document.createElement('a');
watchButton.classList.add('fire-extra-watch');
watchButton.style.display = 'none';
watchButton.innerHTML = '!!/watch';

const blacklistButton = document.createElement('a');
blacklistButton.classList.add('fire-extra-blacklist');
blacklistButton.style.display = 'none';
blacklistButton.innerHTML = '!!/blacklist';

container.append(watchButton, blacklistButton);
Expand Down
18 changes: 10 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,12 @@ function updateEmojisInformation(term: string): void {
human: helpers.getActionDone('watched', isWatched),
tooltip: helpers.getButtonsText('watch', term, isWatched || isBlacklisted, domainName),
suggested: qualifiesForWatch && !isWatched && !isBlacklisted,
// note the button should be disabled if the domain is blacklisted
class: `fire-extra-${isWatched || isBlacklisted ? 'disabled' : 'watch'}`
};

const blacklist = {
human: helpers.getActionDone('blacklisted', isBlacklisted),
tooltip: helpers.getButtonsText('blacklist', term, isBlacklisted, domainName),
suggested: qualifiesForBlacklist && !isBlacklisted,
class: `fire-extra-${isBlacklisted ? 'disabled' : 'blacklist'}`
};

const watchInfo = domainLi?.querySelector('.fire-extra-watch-info');
Expand All @@ -158,8 +155,8 @@ function updateEmojisInformation(term: string): void {
watchInfo.replaceChildren('👀: ', isWatched ? getTick() : getCross());
blacklistInfo.replaceChildren('🚫: ', isBlacklisted ? getTick() : getCross());

const watchButton = domainLi?.querySelector('.fire-extra-watch');
const blacklistButton = domainLi?.querySelector('.fire-extra-blacklist');
const watchButton = domainLi?.querySelector<HTMLElement>('.fire-extra-watch');
const blacklistButton = domainLi?.querySelector<HTMLElement>('.fire-extra-blacklist');

// the buttons do not exist if a PR is pending
if (!watchButton || !blacklistButton) return;
Expand All @@ -168,9 +165,14 @@ function updateEmojisInformation(term: string): void {
if (watch.suggested) watchButton.append(' ', getTick());
if (blacklist.suggested) blacklistButton.append(' ', getTick());

// disable buttons if necessary
watchButton.classList.add(watch.class);
blacklistButton.classList.add(blacklist.class);
// show buttons if action has not been taken
if (!isBlacklisted){
blacklistButton.style.display = 'inline';

if (!isWatched){
watchButton.style.display = 'inline';
}
}

// add the tooltips (either !!/<action> example\.com or domain already <action>)
watchButton.setAttribute('fire-tooltip', watch.tooltip);
Expand Down