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

0.2.4 #5

Merged
merged 6 commits into from
Oct 21, 2020
Merged
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
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"rules": {
"no-console": ["error", { allow: ["warn", "error"] }],
"func-names": ["error", "as-needed"],
"max-len": ["error", { "code": 160 }]
"max-len": ["error", { "code": 160 }],
"max-classes-per-file": ["error", 3]
},
"globals": {
"browser": true,
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.2.4 - Hidelist fix (2020-10-21)
* Hidelist bug fix

## 0.2.3 - Hidelist fix (2018-11-21)
* Hidelist bug fix

Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "whatsbuddy",
"version": "0.2.3",
"version": "0.2.4",
"description": "WebExtension that adds extra functionalities to WhatsApp Web™️",
"license": "MIT",
"bugs": {
Expand All @@ -24,14 +24,14 @@
"build": "parcel build src/manifest.json"
},
"devDependencies": {
"eslint": "^4.13.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.8.0",
"parcel": "^1.10.1",
"parcel-plugin-web-extension": "^1.4.0",
"sass": "^1.14.1"
"eslint": "^7.11.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-plugin-import": "^2.22.1",
"parcel": "^1.12.4",
"parcel-plugin-web-extension": "^1.6.1",
"sass": "^1.27.0"
},
"dependencies": {
"spectre.css": "^0.5.3"
"spectre.css": "^0.5.9"
}
}
4 changes: 2 additions & 2 deletions src/chat/chat.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as storage from '../helpers/storage';
import { onChatOpen } from '../helpers/events';
import { onChatOpen } from './events';

const MESSAGE_INPUT_SELECTOR = '#main footer div[contenteditable]';
const SEND_BUTTON_CHILD_SELECTOR = '#main footer button span[data-icon=send]';
const CHAT_FOOTER_SELECTOR = '#main div[data-asset-chat-background] ~ footer';
const CHAT_FOOTER_SELECTOR = '#main div[data-asset-chat-background] ~ footer, #main div[data-asset-chat-background-dark] ~ footer';

const TOOLS_CONTAINER_ID = 'whatsbuddy-tools-container';
const TOOLS_BUTTON_CLASSNAME = 'whatsbuddy-tools-button';
Expand Down
18 changes: 18 additions & 0 deletions src/chat/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const CHAT_CONTAINER_SELECTOR = '#main div[data-asset-chat-background], #main div[data-asset-chat-background-dark]';

export const onChatOpen = (callback) => {
const onNodeInserted = (element) => {
if (element.target.id !== 'main') return true;

const chatContainer = document.querySelector(CHAT_CONTAINER_SELECTOR);
if (!chatContainer) return true;

callback();

return true;
};

document.addEventListener('DOMNodeInserted', onNodeInserted, false);
};

export default { onChatOpen };
17 changes: 0 additions & 17 deletions src/helpers/events.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const CHAT_CONTAINER_SELECTOR = '#main div[data-asset-chat-background]';

export const onDocumentReady = (callback) => {
if (document.attachEvent ? document.readyState === 'complete' : document.readyState !== 'loading') {
callback();
Expand All @@ -8,21 +6,6 @@ export const onDocumentReady = (callback) => {
}
};

export const onChatOpen = (callback) => {
const onNodeInserted = (element) => {
if (element.target.id !== 'main') return true;

const chatContainer = document.querySelector(CHAT_CONTAINER_SELECTOR);
if (!chatContainer) return true;

callback();

return true;
};

document.addEventListener('DOMNodeInserted', onNodeInserted, false);
};

export const onClick = (selector, callback) => {
const element = (() => {
if (typeof selector === 'string') {
Expand Down
30 changes: 12 additions & 18 deletions src/helpers/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,31 @@ const storage = () => {
if (chrome.storage) {
section = chrome.storage.sync || chrome.storage.local;
}
} catch(e) {} //eslint-disable-line
} catch (e) {} //eslint-disable-line

try {
if (window.storage) {
section = window.storage.local;
}
} catch(e) {} //eslint-disable-line
} catch (e) {} //eslint-disable-line

try {
if (browser.storage) {
section = browser.storage.local;
}
} catch(e) {} //eslint-disable-line
} catch (e) {} //eslint-disable-line

return section;
};

export const save = keys => (
new Promise((resolve) => {
storage().set(keys, () => resolve(true));
})
);
export const save = (keys) => new Promise((resolve) => {
storage().set(keys, () => resolve(true));
});

export const get = keys => (
new Promise((resolve) => {
storage().get(keys, items => resolve(items));
})
);
export const get = (keys) => new Promise((resolve) => {
storage().get(keys, (items) => resolve(items));
});

export const remove = keys => (
new Promise((resolve) => {
storage().remove(keys, items => resolve(items));
})
);
export const remove = (keys) => new Promise((resolve) => {
storage().remove(keys, (items) => resolve(items));
});
8 changes: 1 addition & 7 deletions src/list/events.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
const SIDE_PANE_SELECTOR = '#pane-side';
const SIDE_PANE_ROOT_CLASSNAME = 'app';

export const onSidePaneLoaded = (callback) => {
const paneObserver = new MutationObserver((mutations, observer) => {
mutations.some((mutation) => {
const addedNodes = [...mutation.addedNodes];
return addedNodes.some((node) => {
const nodeClass = node.className && node.className.includes && node.className;
if (!nodeClass || !nodeClass.includes(SIDE_PANE_ROOT_CLASSNAME)) {
return false;
}

const sidePane = node.querySelector(SIDE_PANE_SELECTOR);
if (!sidePane) return false;

Expand All @@ -26,4 +20,4 @@ export const onSidePaneLoaded = (callback) => {
return paneObserver.observe(document, { childList: true, subtree: true });
};

export default {};
export default { onSidePaneLoaded };
2 changes: 1 addition & 1 deletion src/list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ const storageParams = { enableHideChats: true };
storage.get(storageParams).then(({ enableHideChats }) => {
if (!enableHideChats) return;

onSidePaneLoaded(sidePane => sidePaneLoadCallback(sidePane));
onSidePaneLoaded((sidePane) => sidePaneLoadCallback(sidePane));
});
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"name": "WABuddy",
"description": "WebExtension that adds extra functionalities to WhatsApp Web™️",
"version": "0.2.3",
"version": "0.2.4",

"icons": {
"512": "./icons/icon.png",
Expand Down
6 changes: 3 additions & 3 deletions src/options/chat/macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const renderEnableSwitch = () => {

const toggleEnableSwitch = () => {
const enabled = state.macrosEnabled;
state = Object.assign({}, state, { macrosEnabled: !enabled });
state = { ...state, macrosEnabled: !enabled };

renderEnableSwitch();
};
Expand Down Expand Up @@ -105,15 +105,15 @@ onClick(ADD_MACRO_BUTTON_SELECTOR, () => insertMacro());
export const save = () => {
const macros = serializeMacros();

state = Object.assign({}, state, { macros });
state = { ...state, macros };

return storage.save(state);
};

onDocumentReady(() => {
storage.get(state)
.then((response) => {
state = Object.assign({}, state, response);
state = { ...state, ...response };
})
.then(() => renderEnableSwitch())
.then(() => renderMacros());
Expand Down
14 changes: 7 additions & 7 deletions src/options/list/chats.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const renderHideChatEnableSwitch = () => {

const toggleHideChatEnableSwitch = () => {
const enabled = state.enableHideChats;
state = Object.assign({}, state, { enableHideChats: !enabled });
state = { ...state, enableHideChats: !enabled };

renderHideChatEnableSwitch();
};
Expand Down Expand Up @@ -57,8 +57,8 @@ const insertChat = (chat, chats) => {

const renderChatList = () => {
const { chats, hiddenChats } = state;
const filteredChats = chats.filter(chat => !hiddenChats.includes(chat.id));
filteredChats.forEach(chat => insertChat(chat, chats));
const filteredChats = chats.filter((chat) => !hiddenChats.includes(chat.id));
filteredChats.forEach((chat) => insertChat(chat, chats));
};

const insertHiddenChat = (chat, chats) => {
Expand Down Expand Up @@ -91,7 +91,7 @@ const insertHiddenChat = (chat, chats) => {
const renderHiddenChatList = () => {
const { chats, hiddenChats } = state;
hiddenChats.forEach((chatId) => {
const chat = chats.find(c => c.id === chatId) || { id: chatId };
const chat = chats.find((c) => c.id === chatId) || { id: chatId };
insertHiddenChat(chat, chats);
});
};
Expand All @@ -100,21 +100,21 @@ const serializeHiddenChatList = () => {
const chatsContainer = document.querySelector(HIDDEN_CHATS_CONTAINER_SELECTOR);
const hiddenList = chatsContainer.querySelectorAll('tr td:last-child');

return ([...hiddenList]).map(node => node.dataset.chatId);
return ([...hiddenList]).map((node) => node.dataset.chatId);
};

export const save = () => {
const hiddenChats = serializeHiddenChatList();

state = Object.assign({}, state, { hiddenChats });
state = { ...state, hiddenChats };

return storage.save(state);
};

onDocumentReady(() => {
storage.get(state)
.then((response) => {
state = Object.assign({}, state, response);
state = { ...state, ...response };
})
.then(() => renderHideChatEnableSwitch())
.then(() => renderChatList())
Expand Down
Loading