Skip to content

Commit

Permalink
Merge pull request #135 from Serhii-DV/dev
Browse files Browse the repository at this point in the history
Version 0.18.0
  • Loading branch information
Serhii-DV authored Dec 24, 2024
2 parents d2f0c90 + cd762fd commit 6b33515
Show file tree
Hide file tree
Showing 51 changed files with 1,269 additions and 951 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Change log

## 0.18.0 (2024-12-YY)

### Features

- discogs: Removed extension link from the release notes
- discogs: Set default release country to `Worldwide`
- popup: Added Bandcamp wishlist and feed links to the main navigation
- popup: Added Discogs Drafts page link to the main navigation
- popup: Small improvements on the release card tab for release urls
- popup: Use one tab for the latest viewed releases, release card and releases
- core: Improved initialization of console log commands
- core: Removed CSV data tab. Data is available through console
- core: Introduced Bandcamp URL class
- bandcamp: Improved styling for albums filter widget
- bandcamp: Added clear filter button to the albums filter widget

### Fixed

- discogs: Fixed extracting track time with hours on draft page

## 0.17.0 (2024-10-30)

### Features
Expand Down
745 changes: 368 additions & 377 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"version": "0.17.0",
"version": "0.18.0",
"devDependencies": {
"@github/relative-time-element": "^4.4.3",
"@swc/html": "^1.7.40",
"@types/chrome": "^0.0.279",
"@github/relative-time-element": "^4.4.4",
"@swc/html": "^1.10.1",
"@types/chrome": "^0.0.287",
"@types/isotope-layout": "^3.0.13",
"@types/mustache": "^4.2.5",
"@types/uuid": "^10.0.0",
Expand All @@ -12,24 +12,24 @@
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^7.1.2",
"css-minimizer-webpack-plugin": "^7.0.0",
"eslint": "^9.13.0",
"eslint": "^9.17.0",
"eslint-webpack-plugin": "^4.2.0",
"html-loader": "^5.1.0",
"html-minimizer-webpack-plugin": "^5.0.0",
"html-webpack-plugin": "^5.6.3",
"isotope-layout": "^3.0.6",
"json-minimizer-webpack-plugin": "^5.0.0",
"mini-css-extract-plugin": "^2.9.1",
"mini-css-extract-plugin": "^2.9.2",
"mustache": "^4.2.0",
"prettier": "^3.3.3",
"prettier": "^3.4.2",
"source-map-loader": "^5.0.0",
"terser-webpack-plugin": "^5.3.10",
"terser-webpack-plugin": "^5.3.11",
"ts-loader": "^9.5.1",
"typescript": "^5.6.3",
"uuid": "^10.0.0",
"webpack": "^5.95.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4",
"typescript": "^5.7.2",
"uuid": "^11.0.3",
"webpack": "^5.97.1",
"webpack-cli": "^6.0.1",
"webpack-dev-server": "^5.2.0",
"webpack-merge": "^6.0.1"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/app/artistItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ArtistItem extends BandcampItem {
toStorageData(): StorageData {
const self = this;
return {
url: self.url,
url: self.url.toString(),
name: self.name,
image: self.image,
visit: self.visit?.toISOString(),
Expand Down
18 changes: 6 additions & 12 deletions src/app/bandcampItem.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
import { removeBandcampMusicPath } from '../bandcamp/modules/url';
import { generateKeyForUrl } from '../utils/key-generator';
import {
getUrlHostname,
getUrlHostnameUrl,
removeQueryParams
} from '../utils/url';
import { BandcampURL } from './core/bandcampUrl';

export abstract class BandcampItem {
public url: string;
public url: BandcampURL;
public uuid: string;
public image?: string;
public visit?: Date;
public id?: number;

constructor(url: string, image?: string, visit?: Date, id?: number) {
this.url = removeQueryParams(url);
this.url = removeBandcampMusicPath(this.url);
this.uuid = generateKeyForUrl(this.url);
this.url = new BandcampURL(url);
this.uuid = generateKeyForUrl(this.url.toString());
this.image = image;
this.visit = visit;
this.id = id;
}

get artistHostname() {
return getUrlHostname(this.url);
return this.url.hostname;
}

get artistUrl() {
return getUrlHostnameUrl(this.url);
return this.url.hostnameWithProtocol;
}
}

Expand Down
108 changes: 108 additions & 0 deletions src/app/core/bandcampUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
const bandcampHost = 'bandcamp.com';
const bandcampDomain = 'https://' + bandcampHost;

export class BandcampURL {
public url: URL;

constructor(url: string) {
if (!isValidBandcampURL(url)) {
throw new Error(`Wrong Bandcamp URL: ${url}`);
}

try {
url = removeQueryParams(url);
url = removeBandcampMusicPath(url);
this.url = new URL(url);
} catch (error) {
throw new Error(`Invalid URL: ${url}`);
}
}

get hostname(): string {
return this.url.hostname;
}

/**
* Returns the protocol and hostname of the URL.
*/
get hostnameWithProtocol(): string {
return `${this.url.protocol}//${this.url.hostname}`;
}

/**
* Returns the subdomain of the URL's hostname or an empty string if none exists.
*/
get subdomain(): string {
const parts = this.url.hostname.split('.');
if (parts.length > 2) {
return parts.slice(0, -2).join('.');
}
return '';
}

/**
* Returns the URL without the protocol.
*/
get withoutProtocol(): string {
return `${this.url.hostname}${this.url.pathname}${this.url.search}${this.url.hash}`;
}

/**
* Returns the URL without query parameters.
*/
get withoutQueryParams(): string {
const urlCopy = new URL(this.url.toString());
urlCopy.search = '';
return urlCopy.toString();
}

/**
* Returns the pathname of the URL.
*/
get pathname(): string {
return this.url.pathname;
}

get isRegular(): boolean {
return this.toString().includes(bandcampDomain);
}

get isMusic(): boolean {
const path = this.pathname;
return path === '/' || path === '/music';
}

get isAlbum(): boolean {
return this.toString().includes(bandcampHost + '/album/');
}

/**
* Returns the full URL as a string.
* @returns The string representation of the URL.
*/
toString(): string {
return this.url.toString();
}
}

export function isValidBandcampURL(url: string): boolean {
return url.includes(bandcampHost);
}

function removeQueryParams(url: string): string {
const urlObj = new URL(url);
urlObj.search = '';
return urlObj.toString();
}

function removeBandcampMusicPath(url: string): string {
const urlObj = new URL(url);
const segments = urlObj.pathname.split('/').filter(Boolean);

if (segments[segments.length - 1] === 'music') {
segments.pop();
urlObj.pathname = '/' + segments.join('/');
}

return urlObj.toString();
}
6 changes: 6 additions & 0 deletions src/app/core/messageType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum MessageType {
BandcampData = 'B2D_BC_DATA',
DiscogsEditPageData = 'B2D_DISCOGS_EDIT_PAGE_DATA',
Metadata = 'B2D_METADATA',
Search = 'B2D_SEARCH'
}
4 changes: 4 additions & 0 deletions src/app/core/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { Music } from '../music';
import { hasOwnProperty, isObject } from '../../utils/utils';
import { validate as isUUID } from 'uuid';

export enum StorageKey {
BANDCAMP_DATA = 'bandcamp_data'
}

export class Storage {
private storage: chrome.storage.StorageArea;

Expand Down
13 changes: 4 additions & 9 deletions src/app/release.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import {
getUrlHostname,
getUrlHostnameUrl,
removeProtocol
} from '../utils/url';
import { ReleaseItem } from './releaseItem';
import TrackTime from './trackTime.js';

Expand Down Expand Up @@ -97,7 +92,7 @@ export class Release {
}

get releaseHostname() {
return removeProtocol(this.releaseItem.url);
return this.releaseItem.url.withoutProtocol;
}

get title() {
Expand All @@ -113,18 +108,18 @@ export class Release {
}

get artistHostname() {
return getUrlHostname(this.releaseItem.url);
return this.releaseItem.artistHostname;
}

get artistUrl() {
return getUrlHostnameUrl(this.releaseItem.url);
return this.releaseItem.artistUrl;
}

toStorageObject() {
return {
artist: this.releaseItem.artist,
title: this.releaseItem.title,
url: this.releaseItem.url,
url: this.releaseItem.url.toString(),
label: this.label,
published: this.published.toISOString(),
modified: this.modified.toISOString(),
Expand Down
2 changes: 1 addition & 1 deletion src/app/releaseItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ReleaseItem extends BandcampItem {
toStorageData(): StorageData {
const self = this;
return {
url: self.url,
url: self.url.toString(),
artist: self.artist,
title: self.title,
label: self.label,
Expand Down
42 changes: 41 additions & 1 deletion src/bandcamp/css/b2d.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
:root {
--bs-secondary-rgb: 108, 117, 125;
--bs-border-radius: 0.375rem;
}

.b2d-widget-container {
display: flex;
flex-direction: row;
Expand All @@ -10,7 +15,42 @@
background-image: url('../../../images/b2d_logo_16.png');
}

.b2d-badge {
--bs-badge-padding-x: 0.65em;
--bs-badge-padding-y: 0.35em;
--bs-badge-font-size: 0.75em;
--bs-badge-font-weight: 700;
--bs-badge-color: #fff;
--bs-badge-border-radius: var(--bs-border-radius);
display: inline-block;
padding: var(--bs-badge-padding-y) var(--bs-badge-padding-x);
font-size: var(--bs-badge-font-size);
font-weight: var(--bs-badge-font-weight);
line-height: 1;
color: var(--bs-badge-color);
text-align: center;
white-space: nowrap;
vertical-align: baseline;
border-radius: var(--bs-badge-border-radius);
}

.b2d-albumAmount .b2d-visible,
.b2d-albumAmount .b2d-total {
font-size: 130%;
font-size: 120%;
}

input#b2dArtistFilter {
field-sizing: content;
min-width: 10em;
border: 1px solid;
padding: 2px 5px;
}

button#b2dArtistFilterClear {
background: transparent;
color: inherit;
border: none;
margin: 0 0 0 3px;
padding: 0;
vertical-align: middle;
}
13 changes: 9 additions & 4 deletions src/bandcamp/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
* Injected script into Bandcamp page.
* We can send any window data to our content.js script.
*/
window.postMessage({
type: 'BANDCAMP_DATA',
bandData: window.BandData
});
(function () {
const pageData = JSON.parse(document.getElementById('pagedata').dataset.blob);

window.postMessage({
type: 'BANDCAMP_DATA',
bandData: window.BandData,
pageData
});
})();
Loading

0 comments on commit 6b33515

Please sign in to comment.