Skip to content

Commit

Permalink
Fixed blog error
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmesh-hemaram committed Oct 24, 2023
1 parent 22e4087 commit 3a5d046
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 38 deletions.
9 changes: 5 additions & 4 deletions apps/acf-extension/src/background/check-blog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TabsMessenger } from './tab';

const LOCAL_STORAGE_VERSION = 'version';
const BLOG_VERSION = 'blog-version';
export class Blog {
static async check(optionsPageUrl?: string) {
if (optionsPageUrl) {
Expand All @@ -10,15 +10,16 @@ export class Blog {
const regexResult = /\d+\.\d+\.\d+/.exec(response);
if (regexResult) {
const version = regexResult[0];
const { version: storageVersion } = await chrome.storage.local.get(LOCAL_STORAGE_VERSION);
const { [BLOG_VERSION]: storageVersion } = await chrome.storage.local.get(BLOG_VERSION);
if (storageVersion === undefined) {
Blog.update(version);
} else if (storageVersion !== version) {
Blog.show(optionsPageUrl, version);
Blog.update(version);
}
}
});
})
.catch(console.error);
}
}

Expand All @@ -27,6 +28,6 @@ export class Blog {
}

static update(version: string) {
chrome.storage.local.set({ [LOCAL_STORAGE_VERSION]: version });
chrome.storage.local.set({ [BLOG_VERSION]: version });
}
}
1 change: 1 addition & 0 deletions apps/acf-extension/src/background/context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function registerContextMenus(optionsPageUrl?: string) {
if (menuItemId === CONTEXT_MENU_CONFIG_PAGE_ID) {
chrome.tabs.create({ url: optionsPageUrl });
} else if (menuItemId === ACTION_POPUP) {
console.info(tab);
tab?.id && chrome.tabs.sendMessage(tab.id, { action: ACTION_POPUP });
} else if (menuItemId === CONTEXT_MENU_ELEMENT_ID) {
const url = new URL(optionsPageUrl);
Expand Down
36 changes: 21 additions & 15 deletions apps/acf-extension/src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable no-new */
import { DateUtil } from '@dhruv-techapps/core-common';
import { LOCAL_STORAGE_KEY, RUNTIME_MESSAGE_ACF } from '@dhruv-techapps/acf-common';
import { RUNTIME_MESSAGE_ACF } from '@dhruv-techapps/acf-common';
import { Runtime } from '@dhruv-techapps/core-extension';

import registerContextMenus from './context-menu';
Expand All @@ -16,25 +15,23 @@ import GoogleOauth2 from './google-oauth2';
import DiscordMessaging from './discord-messaging';
import { sentryInit } from '../common/sentry';

const EXTENSION_VERSION = 'extension-version';

try {
sentryInit('background');

/**
* Browser Action set to open option page / configuration page
*/
chrome.action.onClicked.addListener(async (tab) => {
chrome.action.onClicked.addListener((tab) => {
tab.id && chrome.tabs.sendMessage(tab.id, { action: ACTION_POPUP });
});

/**
* On initial install setup basic configuration
*/
chrome.runtime.onInstalled.addListener(async () => {
const result = await chrome.storage.local.get(LOCAL_STORAGE_KEY.INSTALL_DATE);
if (!result[LOCAL_STORAGE_KEY.INSTALL_DATE]) {
chrome.storage.local.set({ [LOCAL_STORAGE_KEY.INSTALL_DATE]: DateUtil.getDateWithoutTime().toJSON() });
TabsMessenger.optionsTab({ url: OPTIONS_PAGE_URL });
}
chrome.runtime.onInstalled.addListener(() => {
TabsMessenger.optionsTab({ url: OPTIONS_PAGE_URL });
});

/**
Expand All @@ -56,16 +53,25 @@ try {

/**
* On start up check for rate
* TODO Need to implement rate us feature
*/
chrome.runtime.onStartup.addListener(async () => {
const result = await chrome.runtime.requestUpdateCheck();
if (result.status === 'update_available') {
chrome.runtime.reload();
}
chrome.runtime.onStartup.addListener(() => {
chrome.storage.local.get(EXTENSION_VERSION).then(({ [EXTENSION_VERSION]: version }) => {
const manifestVersion = chrome.runtime.getManifest().version;
if (version !== undefined && version !== manifestVersion) {
chrome.storage.local.remove(EXTENSION_VERSION);
chrome.runtime.reload();
}
});
Blog.check(OPTIONS_PAGE_URL);
});

/**
* If an update is available it will auto update
*/
chrome.runtime.onUpdateAvailable.addListener(({ version }) => {
chrome.storage.local.set({ [EXTENSION_VERSION]: version });
});

/**
* Setup on Message Listener
*/
Expand Down
3 changes: 3 additions & 0 deletions apps/acf-extension/src/background/release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Bug Fix

- Fixed error chrome.runtime.requestUpdateCheck as its supported by latest version of chrome browser.
46 changes: 44 additions & 2 deletions apps/acf-extension/src/common/sentry.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,53 @@
import * as Sentry from '@sentry/browser';
import { NX_RELEASE_VERSION, VARIANT } from './environments';

import { NX_RELEASE_VERSION, VARIANT } from './environments';
export const sentryInit = (page: string) => {
Sentry.init({
dsn: 'https://23ec1ed44876c4cbe18082f514cc5901@o4506036997455872.ingest.sentry.io/4506037629943808',
environment: VARIANT,

ignoreErrors: [
// Random plugins/extensions
'top.GLOBALS',
// See: http://blog.errorception.com/2012/03/tale-of-unfindable-js-error.html
'originalCreateNotification',
'canvas.contentDocument',
'MyApp_RemoveAllHighlights',
'http://tt.epicplay.com',
"Can't find variable: ZiteReader",
'jigsaw is not defined',
'ComboSearch is not defined',
'TypeError sentryWrapped',
'TypeError: Illegal invocation',
'UnhandledRejection: Non-Error promise rejection captured with value: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received',
'http://loading.retry.widdit.com/',
'atomicFindClose',
// Facebook borked
'fb_xd_fragment',
// ISP "optimizing" proxy - `Cache-Control: no-transform` seems to
// reduce this. (thanks @acdha)
// See http://stackoverflow.com/questions/4113268
'bmi_SafeAddOnload',
'EBCallBackMessageReceived',
// See http://toolbar.conduit.com/Developer/HtmlAndGadget/Methods/JSInjection.aspx
'conduitPage',
],
denyUrls: [
// Facebook flakiness
/graph\.facebook\.com/i,
// Facebook blocked
/connect\.facebook\.net\/en_US\/all\.js/i,
// Woopra flakiness
/eatdifferent\.com\.woopra-ns\.com/i,
/static\.woopra\.com\/js\/woopra\.js/i,
// Chrome extensions
/extensions\//i,
/^chrome:\/\//i,
// Other plugins
/127\.0\.0\.1:4001\/isrunning/i, // Cacaoweb
/webappstoolbarba\.texthelp\.com\//i,
/metrics\.itunes\.apple\.com\.edgesuite\.net\//i,
],
allowUrls: [new RegExp(`chrome-extension://${chrome.runtime.id}`, 'i')],
// Alternatively, use `process.env.npm_package_version` for a dynamic release version
// if your build tool supports it.
release: `acf-extension@${NX_RELEASE_VERSION?.replace('v', '')}`,
Expand Down
17 changes: 11 additions & 6 deletions apps/acf-extension/src/content_scripts/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,19 @@ const AddonProcessor = (() => {
if (/than/gi.test(condition) && (Number.isNaN(Number(nodeValue)) || Number.isNaN(Number(value)))) {
throw new ConfigError(`Greater || Less can only compare number '${nodeValue}' '${value}'`, 'Wrong Comparison');
}
if (typeof nodeValue === 'boolean') {
if (nodeValue && condition === ADDON_CONDITIONS['✓ Is Checked ']) {
return true;
} else if (!nodeValue && condition === ADDON_CONDITIONS['✕ Is Not Checked ']) {
return true;
if (typeof nodeValue === 'boolean' || condition === ADDON_CONDITIONS['✓ Is Checked '] || condition === ADDON_CONDITIONS['✕ Is Not Checked ']) {
if (typeof nodeValue === 'boolean') {
if (nodeValue && condition === ADDON_CONDITIONS['✓ Is Checked ']) {
return true;
} else if (!nodeValue && condition === ADDON_CONDITIONS['✕ Is Not Checked ']) {
return true;
}
return false;
} else {
throw new ConfigError('Element Finder need to point checkbox', 'Wrong Element Finder / Addon Condition');
}
return false;
}

switch (condition) {
case ADDON_CONDITIONS['= Equals']:
return new RegExp(`^${value}$`, 'gi').test(nodeValue);
Expand Down
4 changes: 3 additions & 1 deletion apps/acf-extension/src/content_scripts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const ConfigProcessor = (() => {
]);
}
}
} else {
console.error(error.title, '\n', error.message);
}
} else {
throw e;
Expand Down Expand Up @@ -100,7 +102,7 @@ const ConfigProcessor = (() => {
Logger.colorDebug('Config Start Manually');
ActionService.setBadgeText(chrome.runtime.id, { text: 'Manual' });
ActionService.setTitle(chrome.runtime.id, { title: 'Start Manually' });
Hotkey.setup(config.hotkey, start.bind(this, config));
Hotkey.setup(start.bind(this, config), config.hotkey);
} else {
Logger.colorDebug('Config Start Automatically');
ActionService.setBadgeText(chrome.runtime.id, { text: 'Auto' });
Expand Down
4 changes: 2 additions & 2 deletions apps/acf-extension/src/content_scripts/hotkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { Logger } from '@dhruv-techapps/core-common';
const LOGGER_LETTER = 'Hotkey';

export const Hotkey = (() => {
const setup = (hotkey: string = defaultHotkey, start: () => void) => {
const setup = (start: () => void, hotkey: string = defaultHotkey) => {
Logger.colorDebug(LOGGER_LETTER, hotkey);
document.addEventListener('keydown', ({ ctrlKey, shiftKey, altKey, code }) => {
const key = hotkey.split('+').pop()?.trim();
if (code.replace(/key/gi, '') === key) {
if (code !== undefined && code.replace(/key/gi, '') === key) {
if (/ctrl/gi.test(hotkey) === ctrlKey && /alt/gi.test(hotkey) === altKey && /shift/gi.test(hotkey) === shiftKey) {
start();
}
Expand Down
20 changes: 12 additions & 8 deletions apps/acf-extension/src/wizard/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ export const Popup = (() => {

const setHover = (xpath: string, operation: 'add' | 'remove') => {
xpath = WizardElementUtil.clearXpath(xpath);
const nodes = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if (nodes.snapshotLength !== 0) {
let i = 0;
while (i < nodes.snapshotLength) {
(nodes.snapshotItem(i) as HTMLElement).classList[operation]('auto-clicker-hover');
i += 1;
if (xpath) {
const nodes = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if (nodes.snapshotLength !== 0) {
let i = 0;
while (i < nodes.snapshotLength) {
(nodes.snapshotItem(i) as HTMLElement).classList[operation]('auto-clicker-hover');
i += 1;
}
}
}
};
Expand All @@ -40,8 +42,10 @@ export const Popup = (() => {
}) as EventListener);
popupContainer.addEventListener('element-focus', ((e: CustomEvent) => {
const xpath = WizardElementUtil.clearXpath(e.detail.xpath);
const result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
(<HTMLInputElement>result.singleNodeValue).focus();
if (xpath) {
const result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
(<HTMLInputElement>result.singleNodeValue).focus();
}
}) as EventListener);
};

Expand Down

0 comments on commit 3a5d046

Please sign in to comment.