Skip to content

Commit

Permalink
Merge pull request #283 from salcido/quick-search-tracklists
Browse files Browse the repository at this point in the history
New Feature: Quick Search Tracklists
  • Loading branch information
salcido authored Jul 11, 2024
2 parents 3529c7b + a7cff8a commit 63c6755
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 11 deletions.
11 changes: 10 additions & 1 deletion html/learn.html
Original file line number Diff line number Diff line change
Expand Up @@ -609,12 +609,21 @@ <h2 id="force-dashboard">Original Dashboard Link</h2>
<!-- quick search -->
<div class="feature-block">

<h2 id="quick-search">Quick Search</h2>
<h2 id="quick-search">Quick Search Releases</h2>

<p>Lets you search for the release on Google in a new tab by clicking the release's title.</p>
<img src="../img/learn/quick-search.jpg" class="max-width" />
</div>

<!-- quick search -->
<div class="feature-block">

<h2 id="quick-search-tracklists">Quick Search Tracklists</h2>

<p>Lets you search for the track on Google in a new tab by clicking the release's track title.</p>
<img src="../img/learn/quick-search-tracklists.png" class="max-width" />
</div>

<!-- Random Item -->
<div class="feature-block">

Expand Down
28 changes: 26 additions & 2 deletions html/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -940,9 +940,9 @@ <h2>&#x1F44B; Heads up!</h2>
</div> <!-- /.help -->
</div>

<!-- Quick Search -->
<!-- Quick Search Releases -->
<div class="toggle-group">
<p class="label">Quick Search</p>
<p class="label">Quick Search Releases</p>
<div class="meta hide">Quick Search Releases Google Title clicking</div>

<div class="onoffswitch">
Expand All @@ -964,6 +964,30 @@ <h2>&#x1F44B; Heads up!</h2>
</div> <!-- /.help -->
</div>

<!-- Quick Search tracklists -->
<div class="toggle-group">
<p class="label">Quick Search Tracklists</p>
<div class="meta hide">Quick Search tracklists Google clicking</div>

<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="toggleQuickSearchTracklists" checked>
<label class="onoffswitch-label" for="toggleQuickSearchTracklists">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>

<div class="help quick-search-tracklists">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-help-circle" color="#384047"><circle cx="12" cy="12" r="10"></circle><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"></path><line x1="12" y1="17" x2="12" y2="17"></line></svg>
<div class="help-bubble">
<div class="help-text">
Lets you search for the track on Google in a new tab by clicking the tracklist title.
</div>
<div class="arrow-right stroke"></div><div class="arrow-right"></div>
</div>
</div> <!-- /.help -->
</div>

<!-- Random Item -->
<div class="toggle-group">
<p class="label">Random Item Button</p>
Expand Down
Binary file added img/learn/quick-search-tracklists.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions js/extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ let prefs = {
inventoryScanner: false,
notesCount: true,
quickSearch: false,
quickSearchTracklists: false,
randomItem: false,
ratingPercent: false,
readability: false,
Expand Down
2 changes: 1 addition & 1 deletion js/extension/features/notes-counter-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
&& focus.classList
&& focus.classList.contains('notes_textarea') ) {

let notesCount = focus.parentElement.querySelector('.de-notes-count');
let notesCount = focus?.parentElement?.querySelector('.de-notes-count');

// update count value
count = focus.value.length;
Expand Down
2 changes: 1 addition & 1 deletion js/extension/features/notes-counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ rl.ready(() => {
&& focus.classList
&& focus.classList.contains('notes_textarea') ) {

let notesCount = focus.parentElement.querySelector('.de-notes-count');
let notesCount = focus?.parentElement?.querySelector('.de-notes-count');

// update count value
count = focus.value.length;
Expand Down
104 changes: 104 additions & 0 deletions js/extension/features/quick-search-tracklists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
*
* Discogs Enhancer
*
* @author: Matthew Salcido
* @website: http://www.msalcido.com
* @github: https://github.com/salcido
*
* --------------------------------------------------------
* Lets you search for the track on Google in a new tab
* by clicking the release tracklist.
* --------------------------------------------------------
*/
rl.ready(() => {

let variousArtists = document.querySelectorAll('td[class*=artist_] span'),
subtracks = document.querySelectorAll('[class*="subtrack_"]');

// Wrap track titles in spans when subtracks are present so that click events are fired correctly
if (subtracks) {
rl.waitForElement('[class*="trackTitle_"]').then(() => {
document.querySelectorAll('[class*="subtrack_"] td[class*="trackTitle_"]').forEach((elem) => {
let text = elem.firstChild.textContent;
elem.firstChild.textContent = '';
elem.insertAdjacentHTML('afterbegin', `<span class="trackTitle_">${text}</span>`);
});
});
}

// VARIOUS ARTISTS PAGES
if (variousArtists.length) {
// RELEASE PAGES WITH ARTISTS
document.body.addEventListener('click', (event) => {
if ( event?.target?.classList.length
&& event?.target?.classList[0]?.includes('trackTitle_')) {

let artist = event.target.parentElement.previousElementSibling,
artistText = artist?.textContent?.replace('–', '').replaceAll('*', ''),
trackTitle = event.target.textContent;
// Only fire if track title span is clicked on
if ( artistText && event.target.tagName === 'SPAN' ) {

let searchString = encodeURIComponent(`${artistText} - ${trackTitle}`);

window.open('https://www.google.com/search?udm=14&q=' + searchString);
}
}

// MASTER RELEASE PAGES
if ( event?.target?.classList.length
&& event?.target?.classList[0]?.includes('trackTitleWithArtist_')
|| event?.target.tagName === 'SPAN'
&& event?.target?.parentElement?.classList[0]?.includes('trackTitleWithArtist_')) {

let artist = event.target.parentElement.previousElementSibling,
artistText = artist?.textContent?.replace('–', '').replaceAll('*', ''),
trackTitle = event.target.textContent;
// Only fire if track title span is clicked on
if ( artistText && event?.target.tagName === 'SPAN' ) {

let searchString = encodeURIComponent(`${artistText} - ${trackTitle}`);

window.open('https://www.google.com/search?udm=14&q=' + searchString);
}
}

});
// ARTISTS PAGES
} else {
// Tracklists without Artists
document.body.addEventListener('click', (event) => {
// Only fire if track title span is clicked on
if ( event?.target?.classList.length
&& event?.target?.classList[0]?.includes('trackTitle_')
&& event.target.tagName === 'SPAN') {
// Get artist name from document title to avoid including descriminators
let artist = document.title.split(' –')[0],
searchString = encodeURIComponent(`${artist} - ${event.target.textContent}`);

window.open('https://www.google.com/search?udm=14&q=' + searchString);
}
// MASTER RELEASE PAGES
if ( event?.target.tagName === 'SPAN'
&& event?.target?.parentElement?.classList[0]?.includes('trackTitleNoArtist_')) {
// Get artist name from document title to avoid including descriminators
let artist = document.title.split(' -')[0],
searchString = encodeURIComponent(`${artist} - ${event.target.textContent}`);

window.open('https://www.google.com/search?udm=14&q=' + searchString);
}
});
}

let rules = /*css*/`
span[class*="trackTitle_"]:hover,
td[class*="trackTitleWithArtist_"]:hover,
td[class*="trackTitleNoArtist_"] span:hover {
text-decoration: underline;
cursor: pointer;
}
`;

rl.attachCss('quick-search-tracks', rules);
});
12 changes: 12 additions & 0 deletions js/extension/user-preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,18 @@ appendFragment([resourceLibrary])
elems.push(quickSearchReact);
}

if (prefs.quickSearchTracklists) {

// quick-search.js
let quickSearchTracklists = document.createElement('script');

quickSearchTracklists.type = 'text/javascript';
quickSearchTracklists.src = chrome.runtime.getURL('js/extension/features/quick-search-tracklists.js');
quickSearchTracklists.className = 'de-init';

elems.push(quickSearchTracklists);
}

if (prefs.inventoryRatings) {

// inventory-ratings.js
Expand Down
6 changes: 3 additions & 3 deletions js/popup/change-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module.exports = {
current: [
{
features: [{
name: 'Collection Box Location',
description: 'Threw together a quick feature that moves the "In Collection" and "In Wantlist" boxes back to their original locations on the Release Page.',
link: '#collectionBoxFix',
name: 'Quick Search Tracklists',
description: 'Allows you to search Google for the artist + trackname by clicking on the track title on a Master Release or Release page. I tested this against my own collection and it seems to work well but please get in touch if you find any issues with it: [email protected]',
link: '#quick-search-tracklists',
}],
removedFeatures: [],
updates: [
Expand Down
3 changes: 3 additions & 0 deletions js/popup/popup-logic/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ window.addEventListener('load', () => {
toggleNotesCount = document.getElementById('toggleNotesCount'),
togglePrices = document.getElementById('togglePrices'),
toggleQuickSearch = document.getElementById('toggleQuickSearch'),
toggleQuickSearchTracklists = document.getElementById('toggleQuickSearchTracklists'),
toggleRandomItem = document.getElementById('toggleRandomItem'),
toggleRatingPercent = document.getElementById('toggleRatingPercent'),
toggleReadability = document.getElementById('toggleReadability'),
Expand Down Expand Up @@ -306,6 +307,7 @@ window.addEventListener('load', () => {
toggleNotesCount.addEventListener('change', triggerSave);
togglePrices.addEventListener('change', suggestedPrices.validateAndSave);
toggleQuickSearch.addEventListener('change', triggerSave);
toggleQuickSearchTracklists.addEventListener('change', triggerSave);
toggleRandomItem.addEventListener('change', triggerSave);
toggleRatingPercent.addEventListener('change', triggerSave);
toggleReadability.addEventListener('change', triggerSave);
Expand Down Expand Up @@ -493,6 +495,7 @@ window.addEventListener('load', () => {
toggleNotesCount.checked = prefs.notesCount;
togglePrices.checked = prefs.suggestedPrices;
toggleQuickSearch.checked = prefs.quickSearch;
toggleQuickSearchTracklists.checked = prefs.quickSearchTracklists;
toggleRandomItem.checked = prefs.randomItem;
toggleRatingPercent.checked = prefs.ratingPercent;
toggleReadability.checked = prefs.readability;
Expand Down
1 change: 1 addition & 0 deletions js/popup/popup-logic/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export function applySave(message, event, currencyTarget = 'currency') {
inventoryScanner: document.getElementById('toggleInventoryScanner').checked,
notesCount: document.getElementById('toggleNotesCount').checked,
quickSearch: document.getElementById('toggleQuickSearch').checked,
quickSearchTracklists: document.getElementById('toggleQuickSearchTracklists').checked,
randomItem: document.getElementById('toggleRandomItem').checked,
ratingPercent: document.getElementById('toggleRatingPercent').checked,
readability: document.getElementById('toggleReadability').checked,
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": "3.6.21",
"version": "3.7.0",
"author": "Matthew Salcido",
"homepage_url": "https://www.discogs-enhancer.com",
"action": {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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": "3.6.21",
"version": "3.7.0",
"description": "A Chrome extension that adds useful functionality to Discogs.com! https://www.discogs-enhancer.com",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 63c6755

Please sign in to comment.