Skip to content

Commit

Permalink
2.4.234
Browse files Browse the repository at this point in the history
  • Loading branch information
WebGL3D committed Jun 26, 2023
1 parent 29ba8ee commit ffefd38
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 454 deletions.
2 changes: 0 additions & 2 deletions background.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<script src="/js/vanilla/extension/event.js"></script>
<script src="/js/vanilla/extension/backgroundService.js"></script>
<script src="/js/vanilla/extension/reload.js"></script>
<script src="/js/vanilla/extension/notificationService.js"></script>
<script src="/js/vanilla/extension/storage.js"></script>
<script src="/js/vanilla/queuedPromise.js"></script>
<script src="/js/vanilla/cachedPromise.js"></script>
Expand All @@ -40,7 +39,6 @@
<script src="/js/rplus/premium.js"></script>

<!-- background scripts -->
<script src="/js/background/notifications.js"></script>
<script src="/js/background/background.js"></script>
</head>
<body></body>
Expand Down
93 changes: 91 additions & 2 deletions dist/service-worker.js

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

2 changes: 1 addition & 1 deletion dist/service-worker.js.map

Large diffs are not rendered by default.

78 changes: 0 additions & 78 deletions js/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,82 +46,4 @@ foreach(
}
);

/* Startup Notification */
Extension.Storage.Singleton.get('startupNotification')
.then((startnote) => {
if (!startnote || typeof startnote !== 'object') {
startnote = {
on: !Extension.Singleton.isIncognito,
visit: false,
names: {},
};

Extension.Storage.Singleton.blindSet('startupNotification', startnote);
}

const makenote = function () {
Roblox.users.getAuthenticatedUser().then(function (user) {
var username = user ? user.username : '';
for (var n in startnote.names) {
if (n.toLowerCase() === username.toLowerCase()) {
username = startnote.names[n];
break;
}
}

Extension.NotificationService.Singleton.createNotification({
id: `${Extension.Singleton.id}.startNotification`,
title: user
? `Hello, ${user.username}!`
: "You're currently signed out",
message: 'Made by WebGL3D',
context: `${Extension.Singleton.manifest.name} ${Extension.Singleton.manifest.version} started`,
expiration: 15 * 1000,
buttons: [
{
text: 'Problems? Suggestions? Post here!',
url: 'https://www.roblox.com/groups/2518656/ROBLOX-Fan-Group?rbxp=48103520',
},
],
metadata: {
url: `https://roblox.plus/about/changes?version=${Extension.Singleton.manifest.version}`,
},
});
});
};

startnote.names = type(startnote.names) == 'object' ? startnote.names : {};
if (startnote.on && !startnote.visit) {
makenote();
} else if (startnote.on) {
let createdListener;
let updatedListener;
const takeAction = (tab) => {
try {
const tabURL = new URL(tab.url);
if (!tabURL.hostname.endsWith('.roblox.com')) {
return;
}

chrome.tabs.onCreated.removeListener(createdListener);
chrome.tabs.onUpdated.removeListener(updatedListener);
makenote();
} catch {
// don't care for now
}
};
createdListener = (tab) => {
takeAction(tab);
};
updatedListener = (tabId, changes, tab) => {
takeAction(tab);
};
chrome.tabs.onCreated.addListener(createdListener);
chrome.tabs.onUpdated.addListener(updatedListener);
}
})
.catch((e) => {
console.warn('could not read startupNotification', e);
});

// WebGL3D
78 changes: 0 additions & 78 deletions js/background/notifications.js

This file was deleted.

1 change: 1 addition & 0 deletions js/service-worker/notifiers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import CatalogNotifier from './catalog';
import FriendPresenceNotifier from './friend-presence';
import GroupShoutNotifier from './group-shout';
import './startup';
import TradeNotifier from './trades';

// Registry of all the notifiers
Expand Down
86 changes: 86 additions & 0 deletions js/service-worker/notifiers/startup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { manifest } from '@tix-factory/extension-utils';
import { getSettingValue } from '../../../services/settings';
import { getAuthenticatedUser } from '../../../services/users';

const notificationId = 'startup-notification';

const displayStartupNotification = async (): Promise<void> => {
if (!manifest.icons) {
console.warn('Missing manifest icons');
return;
}

const authenticatedUser = await getAuthenticatedUser();
chrome.notifications.create(notificationId, {
type: 'basic',
iconUrl: chrome.extension.getURL(manifest.icons['128']),
title: 'Roblox+ Started',
message: authenticatedUser
? `Hello, ${authenticatedUser.displayName}`
: 'You are currently signed out',
contextMessage: `${manifest.name} ${manifest.version}, by WebGL3D`,
});
};

getSettingValue('startupNotification')
.then(async (setting) => {
if (typeof setting !== 'object') {
setting = {
on: !chrome.extension.inIncognitoContext,
visit: false,
};
}

if (!setting.on) {
return;
}

if (setting.visit) {
// Only show the startup notification after Roblox has been visited.
const updatedListener = (
_tabId: number,
_changes: chrome.tabs.TabChangeInfo,
tab: chrome.tabs.Tab
): Promise<void> => {
return takeAction(tab);
};

const takeAction = async (tab: chrome.tabs.Tab): Promise<void> => {
if (!tab.url) {
return;
}

try {
const tabURL = new URL(tab.url);
if (!tabURL.hostname.endsWith('.roblox.com')) {
return;
}

chrome.tabs.onCreated.removeListener(takeAction);
chrome.tabs.onUpdated.removeListener(updatedListener);
await displayStartupNotification();
} catch {
// don't care for now
}
};

chrome.tabs.onUpdated.addListener(updatedListener);
chrome.tabs.onCreated.addListener(takeAction);
} else {
await displayStartupNotification();
}
})
.catch((err) => {
console.warn('Failed to render startup notification', err);
});

chrome.notifications.onClicked.addListener((id) => {
if (id !== notificationId) {
return;
}

chrome.tabs.create({
url: `https://roblox.plus/about/changes?version=${manifest.version}`,
active: true,
});
});
Loading

0 comments on commit ffefd38

Please sign in to comment.