Skip to content

Commit

Permalink
Unread Mentions Counter 1.1.2
Browse files Browse the repository at this point in the history
* Changed: Removed settings namespace as class property
* Changed: Moved settings initialization to a dedicated class method
* Changed: Removed disclaimer about Firefox from the "Interact To Close" setting description as it appears to no longer be true
  • Loading branch information
argowizbang authored Nov 18, 2023
1 parent 717963a commit f425b0a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
42 changes: 24 additions & 18 deletions src/unread-mentions-counter/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
class UnreadMentionsCounter extends Addon {
constructor(...args) {
super(...args);
constructor( ...args ) {
super( ...args );

this.settingsNamespace = 'addon.unread-mentions-counter';
this.mentionCounterRegExp = /\(@[0-9]*\)/;
this.titleObserver = new MutationObserver( this.monitorTitle );
this.counterLocation = this.settings.get( `${this.settingsNamespace}.counter-location` ) || 'icon';
this.counterLocation = this.settings.get( 'addon.unread-mentions-counter.counter-location' ) || 'icon';
this.favicon = {
element: {
16: document.querySelector( 'link[rel="icon"][sizes="16x16"]' ),
Expand All @@ -22,7 +21,14 @@ class UnreadMentionsCounter extends Addon {

this.inject( 'chat' );

this.settings.add( `${this.settingsNamespace}.counter-location`, {
this.initializeSettings();
}

/**
* Initialize add-on settings
*/
initializeSettings() {
this.settings.add( 'addon.unread-mentions-counter.counter-location', {
default: 'icon',
ui: {
path: 'Add-Ons > Unread Mentions Counter >> Behavior',
Expand All @@ -37,7 +43,7 @@ class UnreadMentionsCounter extends Addon {
}
} );

this.settings.add( `${this.settingsNamespace}.ping-types`, {
this.settings.add( 'addon.unread-mentions-counter.ping-types', {
default: [ 'mention' ],
type: 'basic_array_merge',
ui: {
Expand All @@ -50,7 +56,7 @@ class UnreadMentionsCounter extends Addon {
}
} );

this.settings.add( `${this.settingsNamespace}.browser-notifications.enabled`, {
this.settings.add( 'addon.unread-mentions-counter.browser-notifications.enabled', {
default: false,
ui: {
path: 'Add-Ons > Unread Mentions Counter >> Browser Notifications',
Expand All @@ -61,17 +67,17 @@ class UnreadMentionsCounter extends Addon {
}
} );

this.settings.add( `${this.settingsNamespace}.browser-notifications.interact-to-close`, {
this.settings.add( 'addon.unread-mentions-counter.browser-notifications.interact-to-close', {
default: false,
ui: {
path: 'Add-Ons > Unread Mentions Counter >> Browser Notifications',
title: 'Interact To Close',
description: 'If enabled, notifications will only close when you manually close them. Otherwise, notifications will automatically close after several seconds.\n\n**NOTE:** Firefox does not yet properly support this setting and will automatically behave as if it is disabled.',
description: 'If enabled, notifications will only close when you manually close them. Otherwise, notifications will automatically close after several seconds.',
component: 'setting-check-box'
}
} );

this.settings.add( `${this.settingsNamespace}.browser-notifications.icon-photo`, {
this.settings.add( 'addon.unread-mentions-counter.browser-notifications.icon-photo', {
default: 'channel',
ui: {
path: 'Add-Ons > Unread Mentions Counter >> Browser Notifications',
Expand All @@ -85,7 +91,7 @@ class UnreadMentionsCounter extends Addon {
}
} );

this.settings.add( `${this.settingsNamespace}.icon.bg-color`, {
this.settings.add( 'addon.unread-mentions-counter.icon.bg-color', {
default: 'rgba(255, 0, 0, 1.0)',
ui: {
path: 'Add-Ons > Unread Mentions Counter >> Icon Counter Appearance',
Expand All @@ -98,7 +104,7 @@ class UnreadMentionsCounter extends Addon {
changed: () => { this.insertIconCounter(); }
} );

this.settings.add( `${this.settingsNamespace}.icon.text-color`, {
this.settings.add( 'addon.unread-mentions-counter.icon.text-color', {
default: 'rgba(255, 255, 255, 1.0)',
ui: {
path: 'Add-Ons > Unread Mentions Counter >> Icon Counter Appearance',
Expand All @@ -117,9 +123,9 @@ class UnreadMentionsCounter extends Addon {
*/
countMentions( event ) {
const msg = event.message,
pingTypes = this.settings.get( `${this.settingsNamespace}.ping-types` ),
pingTypes = this.settings.get( 'addon.unread-mentions-counter.ping-types' ),
matchedPings = pingTypes.filter( ( value ) => msg.highlights?.has( value ) ),
notificationIcon = this.settings.get( `${this.settingsNamespace}.browser-notifications.icon-photo` ) === 'channel' ? msg.roomID : msg.user.id;
notificationIcon = this.settings.get( 'addon.unread-mentions-counter.browser-notifications.icon-photo' ) === 'channel' ? msg.roomID : msg.user.id;

let pingAction = 'Mention';

Expand All @@ -137,11 +143,11 @@ class UnreadMentionsCounter extends Addon {
pingAction = 'Ping';
}

if ( this.settings.get( `${this.settingsNamespace}.browser-notifications.enabled` ) ) {
if ( this.settings.get( 'addon.unread-mentions-counter.browser-notifications.enabled' ) ) {
const notification = new Notification( `${pingAction}ed by ${msg.user.displayName} in ${msg.roomLogin}'s chat`, {
body: `${msg.user.displayName}: ${msg.message}`,
icon: `https://cdn.frankerfacez.com/avatar/twitch/${notificationIcon}`,
requireInteraction: this.settings.get( `${this.settingsNamespace}.browser-notifications.interact-to-close` )
requireInteraction: this.settings.get( 'addon.unread-mentions-counter.browser-notifications.interact-to-close' )
} );
}
}
Expand All @@ -164,14 +170,14 @@ class UnreadMentionsCounter extends Addon {
// Icon Counter Background
context.beginPath();
context.arc( canvas.width - size / 3, size / 3, size / 3, 0, 2 * Math.PI );
context.fillStyle = this.settings.get( `${this.settingsNamespace}.icon.bg-color` );
context.fillStyle = this.settings.get( 'addon.unread-mentions-counter.icon.bg-color' );
context.fill();

// Icon Counter Text
context.font = Math.ceil( size / 1.78 ) + 'px Inter, "Helvetica Neue", Helvetica, Arial, sans-serif';
context.textAlign = 'center';
context.textBaseline = 'middle';
context.fillStyle = this.settings.get( `${this.settingsNamespace}.icon.text-color` );
context.fillStyle = this.settings.get( 'addon.unread-mentions-counter.icon.text-color' );
context.fillText( this.mentionCount, canvas.width - size / 3, size / 2.75 );

this.favicon.element[ size ].href = canvas.toDataURL();
Expand Down
4 changes: 2 additions & 2 deletions src/unread-mentions-counter/manifest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"enabled": true,
"requires": [],
"version": "1.1.1",
"version": "1.1.2",
"short_name": "UnreadMentionsCounter",
"name": "Unread Mentions Counter",
"author": "ArgoWizbang",
"description": "Adds an unread mentions/pings counter in the inactive browser tab of stream chats.\n\nBe able to see if anyone has mentioned/pinged you in chat while you were viewing a different tab in your browser!",
"settings": "add_ons.unread_mentions_counter",
"created": "2022-09-14T08:48:21.047Z",
"updated": "2023-01-05T20:45:14.375Z"
"updated": "2023-11-18T20:31:30.697Z"
}

0 comments on commit f425b0a

Please sign in to comment.