Skip to content

Commit

Permalink
Add Hide New Sellers option
Browse files Browse the repository at this point in the history
  • Loading branch information
salcido committed May 31, 2023
1 parent f19ebab commit a605c4d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
Binary file added img/learn/hide-new-sellers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion js/extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ let prefs = {
blockSellers: true,
confirmBeforeRemoving: false,
collectionUi: false,
commentScanner: false,
converter: true,
darkTheme: false,
darkThemeVariant: '',
Expand Down Expand Up @@ -134,6 +133,7 @@ let featureDefaults = {
sellerRep: 99,
sellerRepColor: 'darkorange',
sellerRepFilter: false,
sellerRepFilterNewSellers: false,
sleeveCondition: { value: 7, generic: false, noCover: false },
usDateFormat: false,
};
Expand Down
18 changes: 13 additions & 5 deletions js/extension/features/seller-rep.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
rl.ready(() => {

let featureData = rl.getPreference('featureData'),
{ sellerRep: threshold, sellerRepFilter } = featureData;
{ sellerRep: threshold, sellerRepFilter, sellerRepFilterNewSellers } = featureData;

if ( !threshold ) return;

Expand All @@ -28,7 +28,7 @@ rl.ready(() => {
// Functions
// ========================================================
/**
* Finds all the seller's reputation scores in the DOM and
* Finds all the seller's ratings in the DOM and
* adds a `de-seller-rep` class to them if necessary. Also
* injects the seller-rep icon into the DOM.
* @method sellersRep
Expand All @@ -37,15 +37,18 @@ rl.ready(() => {
window.sellersRep = function sellersRep() {

let ratingVals = [...document.getElementsByClassName('seller_info')],
ratings = ratingVals.map(val => Number( val.textContent.match(/\d+\.+\d/g) ) );
ratings = ratingVals.map(val => Number( val.textContent.match(/\d+\.+\d/g) ));

// Tag any sellers below threshold
ratings.forEach((rating, i) => {

let seller_info = document.getElementsByClassName('seller_info');

// if you want to tag new sellers as well change this to:
// if ( rating < threshold ) {
// Hide new sellers
if (sellerRepFilterNewSellers && rating === 0) {
seller_info[i].closest('tr.shortcut_navigable').classList.add('de-new-seller-hide');
}

if ( rating
&& rating < threshold
&& !seller_info[i].querySelector('.de-seller-rep-icon')) {
Expand All @@ -58,6 +61,7 @@ rl.ready(() => {
icon.rel = 'tooltip';
icon.title = `${name}'s seller reputation is below ${threshold}%`;

// Hide sellers when below minimum
if (sellerRepFilter) {
seller_info[i].closest('tr.shortcut_navigable').classList.add('de-seller-rep-hide');
}
Expand Down Expand Up @@ -99,6 +103,10 @@ rl.ready(() => {
.de-seller-rep-hide {
display: none;
}
.de-new-seller-hide {
display: none;
}
`;
// ========================================================
// DOM manipulation
Expand Down
23 changes: 19 additions & 4 deletions js/popup/popup-logic/features/seller-rep.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { applySave, optionsToggle, setEnabledStatus, sendEvent } from '../utils'
export function init() {

document.querySelector('.toggle-group.seller-rep').addEventListener('click', function () {
optionsToggle('.hide-percentage', this, '.seller-rep', 230);
optionsToggle('.hide-percentage', this, '.seller-rep', 270);
});

// Swatches
Expand All @@ -26,6 +26,16 @@ export function init() {
});
});
});

// New Sellers checkbox
document.getElementById('hide-new-sellers').addEventListener('change', (event) => {
chrome.storage.sync.get(['featureData']).then(({ featureData }) => {
featureData.sellerRepFilterNewSellers = event.target.checked;
chrome.storage.sync.set({ featureData }).then(() => {
applySave('refresh', event);
});
});
});
}
/**
* Saves the sellerRep percentage
Expand Down Expand Up @@ -94,8 +104,9 @@ export function saveSellerRep() {
export function setSellerRep() {
chrome.storage.sync.get(['featureData']).then(({ featureData }) => {

let checkbox = document.getElementById('filter-seller-rep'),
{ sellerRepFilter, sellerRep: percent, sellerRepColor } = featureData,
let filterSellerRepCheckbox = document.getElementById('filter-seller-rep'),
hideNewSellersCheckbox = document.getElementById('hide-new-sellers'),
{ sellerRepFilter, sellerRepFilterNewSellers, sellerRep: percent, sellerRepColor } = featureData,
input = document.getElementById('percent'),
color = sellerRepColor.match(/\w/g).join(''),
repValue = document.getElementsByClassName('rep-value')[0],
Expand All @@ -106,7 +117,11 @@ export function setSellerRep() {
if ( percent !== null ) { input.value = percent; }

if (sellerRepFilter) {
checkbox.checked = true;
filterSellerRepCheckbox.checked = true;
}

if (sellerRepFilterNewSellers) {
hideNewSellersCheckbox.checked = true;
}

swatch.className += ' selected';
Expand Down

0 comments on commit a605c4d

Please sign in to comment.