Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manifest 3 #91

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
698 changes: 460 additions & 238 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"devDependencies": {
"eslint": "^8.5.0",
"eslint": "^8.32.0",
"eslint-config-google": "^0.14.0"
}
}
31 changes: 26 additions & 5 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
'use strict';

import {isNewDay, getDebugInfo} from './utility.js';
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
import {setBadge, isCurrentBadge, GreyBadge, BusyBadge, DoneBadge, ErrorBadge} from './badge.js';
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
import {handleException} from './exception.js';
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
import {GoogleTrend} from './GoogleTrend.js';
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
import {DailyRewardStatus} from './status/dailyRewardStatus.js';
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
import {checkQuizAndDaily} from './quest/quizDailyQuest.js';
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
import {SearchQuest} from './quest/searchQuest.js';
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
import {STATUS_BUSY} from '../constants.js';
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved

function onExtensionLoad() {
setBadge(new GreyBadge());
loadSavedSettings();
Expand Down Expand Up @@ -64,7 +73,11 @@ async function doBackgroundWork() {

setBadge(new BusyBadge());

checkNewDay();
if (isNewDay()) {
searchQuest.reset();
googleTrend.reset();
}

await checkDailyRewardStatus();

if (isCurrentBadge('busy')) {
Expand Down Expand Up @@ -117,12 +130,20 @@ async function doSearchQuests() {
const WORKER_ACTIVATION_INTERVAL = 7200000; // Interval at which automatic background works are carried out, in ms.
const WAIT_FOR_ONLINE_TIMEOUT = 60000;


export let developer = false;
// eslint-disable-next-line prefer-const
export let userAgents;
userAgents = {
'pc': '',
'mb': '',
'pcSource': '',
'mbSource': '',
};
export let _compatibilityMode = false;
export const userDailyStatus = new DailyRewardStatus();
const googleTrend = new GoogleTrend();
const userDailyStatus = new DailyRewardStatus();
const searchQuest = new SearchQuest(googleTrend);
let developer = false;
let userAgents;
let _compatibilityMode;

chrome.runtime.onInstalled.addListener(function (details) {
if (details.reason == 'install') {
Expand Down
24 changes: 12 additions & 12 deletions src/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Badge {
}

setIcon() {
chrome.browserAction.setIcon({
chrome.action.setIcon({
path: this.icon,
});
}
Expand All @@ -43,7 +43,7 @@ class Badge {
txt = '';
}

chrome.browserAction.setBadgeText({
chrome.action.setBadgeText({
text: txt,
});
}
Expand All @@ -52,61 +52,61 @@ class Badge {
if (!this.backgroundColor) {
return;
}
chrome.browserAction.setBadgeBackgroundColor({
chrome.action.setBadgeBackgroundColor({
'color': this.backgroundColor,
});
}
}

class GreyBadge extends Badge {
export class GreyBadge extends Badge {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor() {
super('grey', 'img/[email protected]');
}
}

class BusyBadge extends Badge {
export class BusyBadge extends Badge {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor() {
super('busy', 'img/[email protected]');
}
}

class DoneBadge extends Badge {
export class DoneBadge extends Badge {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor() {
super('done', 'img/[email protected]');
}
}

class WarningBadge extends Badge {
export class WarningBadge extends Badge {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor() {
super('warn', 'img/[email protected]');
}
}

class QuizAndDailyBadge extends Badge {
export class QuizAndDailyBadge extends Badge {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor(text) {
super('quiz', 'img/[email protected]', text, [255, 201, 71, 100]);
}
}

class ErrorBadge extends Badge {
export class ErrorBadge extends Badge {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor() {
super('error', 'img/[email protected]', 'err', [255, 51, 51, 100]);
}
}

class NoneBadge extends Badge {
export class NoneBadge extends Badge {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor() {
super('none', 'img/[email protected]');
}
}

let _currentBadge = null;
function setBadge(badge) {
export function setBadge(badge) {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
badge.set();
_currentBadge = badge;
}

function isCurrentBadge(badgeType) {
export function isCurrentBadge(badgeType) {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
if (typeof badgeType == 'object') {
badgeType = badgeType.type;
}
Expand Down
11 changes: 11 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const STATUS_NONE = 0;
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
export const STATUS_BUSY = 1;
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
export const STATUS_DONE = 20;
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
export const STATUS_WARNING = 30;
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
export const STATUS_ERROR = 3;
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved

export const USER_STATUS_BING_URL = 'https://www.bing.com/rewardsapp/flyout?channel=0';
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
export const USER_STATUS_DETAILED_URL = 'https://rewards.bing.com/';
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved


// import {STATUS_NONE, STATUS_BUSY, STATUS_DONE, STATUS_ERROR, USER_STATUS_BING_URL, USER_STATUS_DETAILED_URL} from '../constants.js';
22 changes: 12 additions & 10 deletions src/exception.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
function handleException(ex) {
import {setBadge, ErrorBadge} from './badge.js';
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved

export function handleException(ex) {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
setBadge(new ErrorBadge());
console.log('Error History:');
logException(ex);
throw ex;
}

function logException(ex) {
export function logException(ex) {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
if (ex.innerException) {
logException(ex.innerException);
}
console.log(`Source: ${ex.source}\n`, ex);
}

class ErrorWithSourceInnerException extends Error {
export class ErrorWithSourceInnerException extends Error {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor(source, innerException, message) {
message = message + '\nInnerEx: ' + (innerException ? innerException.stack : 'null');
super(message);
Expand All @@ -21,7 +23,7 @@ class ErrorWithSourceInnerException extends Error {
}
}

class FetchFailedException extends ErrorWithSourceInnerException {
export class FetchFailedException extends ErrorWithSourceInnerException {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor(source, innerException, message) {
if (innerException == undefined) {
innerException = {
Expand All @@ -38,7 +40,7 @@ class FetchFailedException extends ErrorWithSourceInnerException {
}
}

class ResponseUnexpectedStatusException extends ErrorWithSourceInnerException {
export class ResponseUnexpectedStatusException extends ErrorWithSourceInnerException {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor(source, ex, message) {
if (!message) {
message = `Expected response status is within 200-299. Received response: ${ex}`;
Expand All @@ -48,7 +50,7 @@ class ResponseUnexpectedStatusException extends ErrorWithSourceInnerException {
}
}

class GoogleTrendPageNumberOverflowException extends ErrorWithSourceInnerException {
export class GoogleTrendPageNumberOverflowException extends ErrorWithSourceInnerException {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor(source, innerException, message) {
if (!message) {
message = 'Failed to get more Google trend words because all pages have been used.';
Expand All @@ -58,7 +60,7 @@ class GoogleTrendPageNumberOverflowException extends ErrorWithSourceInnerExcepti
}
}

class ParseJSONFailedException extends ErrorWithSourceInnerException {
export class ParseJSONFailedException extends ErrorWithSourceInnerException {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor(source, innerException, message) {
if (!message) {
message = 'Failed to parse the JSON file.';
Expand All @@ -68,7 +70,7 @@ class ParseJSONFailedException extends ErrorWithSourceInnerException {
}
}

class FetchTimeoutException extends ErrorWithSourceInnerException {
export class FetchTimeoutException extends ErrorWithSourceInnerException {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor(source, innerException, message) {
if (!message) {
message = 'Fetch timeout.';
Expand All @@ -78,14 +80,14 @@ class FetchTimeoutException extends ErrorWithSourceInnerException {
}
}

class UserAgentInvalidException extends Error {
export class UserAgentInvalidException extends Error {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor(message) {
super(message);
this.name = 'UserAgentInvalid';
}
}

class NotRewardUserException extends Error {
export class NotRewardUserException extends Error {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor(message) {
super(message);
this.name = 'UserNotLoggedIn';
Expand Down
19 changes: 10 additions & 9 deletions src/googleTrend.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class GoogleTrend {
import {FetchFailedException} from './exception.js';
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved

export class GoogleTrend {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
constructor() {
this.reset();
}
Expand Down Expand Up @@ -29,36 +31,35 @@ class GoogleTrend {
if (this._isGoogleTrendUpToDate()) {
return;
}
if (this._loadLocalWords()) {
if (await this._loadLocalWords()) {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
return;
}

const dates = this._getPastThreeDays();
for (let i = 0; i<3; i++) {
await this._fetchGoogleTrend(this._getGoogleTrendUrl(dates[i]));
}
this._saveWordsToLocal();
await this._saveWordsToLocal();
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
}

_isGoogleTrendUpToDate(date=this._googleTrendWords_.date) {
return date == this._getyyyymmdd(new Date());
}

_saveWordsToLocal() {
localStorage.setItem('googleTrend', this._googleTrendWords_.words.join('|'));
localStorage.setItem('googleTrendDate', this._googleTrendWords_.date);
async _saveWordsToLocal() {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
await chrome.storage.local.set({'googleTrend': this._googleTrendWords_.words.join('|'), 'googleTrendDate': this._googleTrendWords_.date});
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
}

_loadLocalWords() {
const date = localStorage.getItem('googleTrendDate');
async _loadLocalWords() {
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
const date = await chrome.storage.local.get('googleTrendDate');
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
if (date == undefined) {
return false;
}
if (!this._isGoogleTrendUpToDate(date)) {
return false;
}
this._googleTrendWords_.date = date;
this._googleTrendWords_.words = localStorage.getItem('googleTrend').split('|');
this._googleTrendWords_.words = await chrome.storage.local.get('googleTrend').split('|');
AnthonyZJiang marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

Expand Down
75 changes: 31 additions & 44 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,32 @@
{
"manifest_version": 2,
"name": "Microsoft Rewards Bot",
"version": "2.24.1.2",
"icons": {
"16": "img/[email protected]",
"24": "img/[email protected]",
"32": "img/[email protected]",
"48": "img/[email protected]",
"128": "img/[email protected]"
},
"description": "A Chrome extension for Microsoft Rewards that automatically clears PC, mobile and EDGE search quests and displays daily point countdown.",

"background": {
"persistent": true,
"scripts": [
"status/DailyQuest.js",
"status/DailyRewardStatus.js",
"quest/searchQuest.js",
"quest/quizDailyQuest.js",
"googleTrend.js",
"utility.js",
"badge.js",
"exception.js",
"background.js",
"test.js"
]
},

"browser_action": {
"default_title": "Microsoft Rewards Bot",
"default_popup": "popup/popup.html"
},

"permissions": ["https://www.bing.com/search?q=*",
"https://trends.google.com/trends/*",
"https://account.microsoft.com/rewards/*",
"https://rewards.microsoft.com/*",
"https://rewards.bing.com/*",
"webRequest",
"webRequestBlocking",
"storage",
"notifications"
]
}
"manifest_version": 3,
"name": "Microsoft Rewards Bot",
"version": "2.25.0",
"icons": {
"16": "img/[email protected]",
"24": "img/[email protected]",
"32": "img/[email protected]",
"48": "img/[email protected]",
"128": "img/[email protected]"
},
"description": "A Chrome extension for Microsoft Rewards that automatically clears PC, mobile and EDGE search quests and displays daily point countdown.",
"background": {
"service_worker": "background.js",
"type": "module"
},
"action": {
"default_title": "Microsoft Rewards Bot",
"default_popup": "popup/popup.html"
},
"permissions": [
"notifications",
"storage",
"webRequest",
"declarativeNetRequest"
],
"host_permissions": [
"https://*.bing.com/*",
"https://*.microsoft.com/*",
"https://trends.google.com/trends/*"
]
}
Loading