Skip to content

Commit

Permalink
Merge pull request #165 from salcido/feature
Browse files Browse the repository at this point in the history
  • Loading branch information
salcido authored Oct 22, 2021
2 parents 7e8ee6c + 20be6f8 commit dee94f2
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 23 deletions.
2 changes: 2 additions & 0 deletions html/learn.html
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ <h2 id="releaseRatings">Marketplace Ratings</h2>

<p>To see ratings, simply click the link that says "Show Ratings". It will be located above the "View Release Page" link on each release listing.</p>

<p>You can click the rating and it will open up the stats for that release in a new page where you can see the number of ratings, the haves, the wants, and the rating distribution.</p>

<img src="../img/learn/release-rating-1.jpg" class="max-width" />
<img src="../img/learn/release-rating-2.jpg" class="max-width" />
</div>
Expand Down
12 changes: 6 additions & 6 deletions js/extension/features/quick-search-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
// CSS
// ========================================================
let rules = `
.de-one-click {
.de-quick-search {
cursor: pointer;
}
.de-one-click:hover {
.de-quick-search:hover {
text-decoration: underline;
}
.de-external {
Expand All @@ -69,7 +69,7 @@
opacity: 0;
position: absolute;
}
.de-one-click:hover + .de-external {
.de-quick-search:hover + .de-external {
opacity: 1;
text-decoration: none;
}
Expand All @@ -80,21 +80,21 @@
// ========================================================
let i = document.createElement('i'),
query = document.title.replace(re, ''),
releaseTitle = document.querySelector('#release-header h1');
releaseTitle = document.querySelector('h1[class*="title_"]');

// DOM manipulation
i.classList = 'icon icon-external-link de-external';

let regex = /(\– .+)+$/g,
titleText = releaseTitle.innerHTML.match(regex);

let newReleaseMarkup = releaseTitle.innerHTML.toString().replace(regex, `<span class="de-one-click">${titleText[0]}</span>`);
let newReleaseMarkup = releaseTitle.innerHTML.toString().replace(regex, `<span class="de-quick-search">${titleText[0]}</span>`);

releaseTitle.innerHTML = newReleaseMarkup;
releaseTitle.insertAdjacentElement('beforeend', i);

// Click handler
document.querySelector('.de-one-click').addEventListener('click', () => {
document.querySelector('.de-quick-search').addEventListener('click', () => {
window.open('https://www.google.com/search?q=' + encodeURIComponent(query) + additionalText);
});

Expand Down
8 changes: 4 additions & 4 deletions js/extension/features/quick-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
// CSS
// ========================================================
let rules = `
.de-one-click {
.de-quick-search {
cursor: pointer;
}
.de-one-click:hover {
.de-quick-search:hover {
text-decoration: underline;
}
.de-external {
Expand All @@ -69,7 +69,7 @@
opacity: 0;
position: absolute;
}
.de-one-click:hover + .de-external {
.de-quick-search:hover + .de-external {
opacity: 1;
text-decoration: none;
}
Expand All @@ -84,7 +84,7 @@

// DOM manipulation
i.classList = 'icon icon-external-link de-external';
releaseTitle.nextElementSibling.classList = 'de-one-click';
releaseTitle.nextElementSibling.classList = 'de-quick-search';
releaseTitle.nextElementSibling.insertAdjacentElement('afterend', i);
releaseTitle.nextElementSibling.textContent = releaseTitle.nextElementSibling.textContent.trim();

Expand Down
16 changes: 11 additions & 5 deletions js/extension/features/release-ratings.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,31 @@ rl.ready(() => {
* Gets the release rating and votes from a specified release
*
* @method getReleaseRating
* @param {String} id [the event's data-id attribute value]
* @param {String} url [the event's data-id attribute value]
* @param {object} parent [the parent of the event.target element]
* @return {object}
*/
async function getReleaseRating(id, parent) {
async function getReleaseRating(url, parent) {

try {

let response = await fetch(id),
let response = await fetch(url),
data = await response.text(),
div = document.createElement('div'),
id = parent.closest('tr').dataset.releaseId,
selector = '#release-stats div[class*="items_"] ul li:nth-child(4) a',
href = `/release/stats/${id}`,
rating;

div.innerHTML = data;
rating = div.querySelector('.statistics ul:first-of-type li:last-child').textContent;
rating = div.querySelector(selector).textContent;

parent.querySelector('.preloader').remove();

return parent.append(rating);
return parent.insertAdjacentHTML(
'afterbegin',
`Ratings: <a href="${href}" target="_blank">${rating}</a>`
);

} catch (err) {

Expand Down
2 changes: 1 addition & 1 deletion js/extension/features/release-scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ rl.ready(() => {

if ( rl.pageIs('artist', 'label') ) {

let selector = '.section_content.marketplace_box_buttons_count_1';
let selector = 'div[class*="marketplace_box_buttons_count_"]';

if ( document.querySelector(selector) ) {

Expand Down
18 changes: 15 additions & 3 deletions js/popup/change-log.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
module.exports = {
current: [
{
version: '2.25.8',
version: '2.25.10',
features: [
],
updates: [
{
name: 'Bugfix',
description: 'Updated the Marketplace Ratings feature to work with the new Release Page. Fixed Quick Search. And the Release Scanner will now add the scan button even when there are no items for sale.'
},
],
thanks: []
},
],
previous: [
{
version: '2.25.9',
features: [
],
updates: [
Expand All @@ -16,8 +30,6 @@ module.exports = {
],
thanks: ['A big thank you to Tobias B. for his kind donation! And shout out to Sonny C. for the bug report!']
},
],
previous: [
{
version: '2.25.7',
features: [
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Discogs Enhancer",
"short_name": "Discogs Enhancer",
"description": "Adds a dark theme, block sellers, price comparisons, currency converter, configurable quick search, & more to Discogs!",
"version": "2.25.9",
"version": "2.25.10",
"author": "Matthew Salcido",
"homepage_url": "https://www.discogs-enhancer.com",
"browser_action": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discogs-enhancer",
"version": "2.25.9",
"version": "2.25.10",
"description": "A Chrome extension that adds useful functionality to Discogs.com! https://www.discogs-enhancer.com",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions test/unauthenticated/quick-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ let test = async function(page) {
await toggleFeature('#toggleQuickSearch');
await Promise.all([
page.goto('https://www.discogs.com/Lou-Karsh-Phantom-Structures/release/13705345', { waitUntil: 'networkidle2' }),
page.waitFor('.de-one-click')
page.waitFor('.de-quick-search')
]);
let hasQuickSearch = await page.$eval('.de-one-click', elem => elem.classList.contains('de-one-click'));
let hasQuickSearch = await page.$eval('.de-quick-search', elem => elem.classList.contains('de-quick-search'));
assert.equal(hasQuickSearch, true, 'Quick Search span was not rendered');
};

Expand Down

0 comments on commit dee94f2

Please sign in to comment.