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