Rewrite makeButtons function.
This commit is contained in:
parent
cd322127d6
commit
aa0f0ee70d
|
@ -3,7 +3,7 @@ import * as instance from './instances';
|
|||
|
||||
// ---------- Commons
|
||||
|
||||
export function generateArray(obj: Object): Instance[] {
|
||||
export function generateArray(obj: any): Instance[] {
|
||||
const item = [];
|
||||
|
||||
Object.keys(obj).map((index) => item.push(obj[index]));
|
||||
|
@ -22,7 +22,7 @@ export function getCurrentTabInfo() {
|
|||
if (tabs.length === 0) return;
|
||||
|
||||
const tab = tabs[0] || {};
|
||||
makeBtns(tab);
|
||||
makeButtons(tab);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -33,11 +33,12 @@ function urlAssigner(instance: Instance) {
|
|||
element.href = href;
|
||||
}
|
||||
|
||||
function makeBtns(tabQuery: Query) {
|
||||
function makeButtons(tabQuery: Query) {
|
||||
const socialBtns = generateArray(instance);
|
||||
|
||||
function itemBtn(instance: Instance) {
|
||||
const { name, host, post } = instance;
|
||||
// Getting the host of the instance
|
||||
socialBtns.map((item: Instance) => {
|
||||
const { name, host, post } = item;
|
||||
const element = <HTMLAnchorElement>document.getElementById(`url-${name.toLowerCase()}`);
|
||||
const itemHost: any = browser.storage.sync.get(`${name.toLowerCase()}Host`); // fix this
|
||||
// TODO improve regex
|
||||
|
@ -46,10 +47,8 @@ function makeBtns(tabQuery: Query) {
|
|||
itemHost.then((res: string) => {
|
||||
element.href = [res[`${name.toLowerCase()}Host`] || host] + str;
|
||||
});
|
||||
instance.button = { id: name, href: itemHost };
|
||||
}
|
||||
|
||||
socialBtns.map((item) => itemBtn(item));
|
||||
item.button = { id: name, href: itemHost };
|
||||
});
|
||||
socialBtns.forEach(urlAssigner);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue