Example #1
0
export const pushTab = async (): Promise<void> => {
	const windows: browser.windows.Window[] = await browser.windows.getAll({populate: true});

	// Just in case number of windows goes below 1
	if (windows.length <= 1) {
		return;
	} else if (windows.length === 2) {
		const tab: browser.tabs.Tab = await utils.tabs.getCurrent();

		const otherWindow: browser.windows.Window[] = windows.filter(
			(w: browser.windows.Window): boolean => w.id !== tab.windowId
		);

		browser.tabs.move(tab.id, {windowId: otherWindow[0].id, index: -1}).catch(
			(e: Error): void => {
				logging.error(e.message);
			}
		);

		browser.windows.update(otherWindow[0].id, {focused: true}).catch(
			(e: Error): void => {
				logging.error(e.message);
			}
		);

		browser.tabs.update(tab.id, {selected: true, pinned: tab.pinned}).catch(
			(e: Error): void => {
				logging.error(e.message);
			}
		);
	} else {
		const tab: browser.tabs.Tab = await utils.tabs.getCurrent();
		const newTab: browser.tabs.Tab = await browser.tabs.create(
			{
				url : `../tabbo.html#${tab.id}`
			}
		);

		const onTabChange: tabbo.TabsOnActivatedCallback = async (e: tabbo.TabsOnActivatedEvent) => {
			if (e.tabId !== newTab.id) {
				browser.tabs.onActivated.removeListener(onTabChange);

				browser.tabs.get(newTab.id).catch((e: Error): void => {
					logging.error(e.message);
				});

				if (!browser.runtime.lastError) {
					browser.tabs.remove(newTab.id).catch((e: Error): void => {
						logging.error(e.message);
					});
				}
			}
		};

		browser.tabs.onActivated.addListener(onTabChange);
	}
};
Example #2
0
export const main = async (sendTabID: number): Promise<void> => {
	const windows: browser.windows.Window[] = await browser.windows.getAll({populate: true});
	const current: browser.windows.Window = await browser.windows.getCurrent();
	let count: number = 1;

	const openWindowsElement: HTMLElement = utils.queryOrThrow('#open-windows');
	const t: browser.tabs.Tab = await browser.tabs.get(sendTabID);

	if (windows.length === 1) {
		const h1: HTMLElement = document.createElement('h1');
		h1.innerText = 'No other open windows';

		openWindowsElement.appendChild(h1);
	}

	windows.forEach((w: browser.windows.Window): void => {
		if (w.id === current.id) {
			return;
		}

		const windowNum = count.toString();
		utils.queryOrThrow('body').addEventListener(
			'keydown',
			(e: KeyboardEvent) => {
				if (e.key === windowNum) {
					moveTabToWindow(w, t);
				}
			}
		);

		if (w.tabs) {
			const div: HTMLDivElement = document.createElement('div');
			div.className = 'screenshot';
			div.innerHTML = `<div class="title-bar"> <img src="${w.tabs[0].favIconUrl}"/>
				<div class="screen-title">${w.tabs[0].title}</div></div>
				<div class="screen-index">${count}</div>
				<div class="tab-count">${w.tabs.length + (w.tabs.length === 1 ? " tab" : " tabs")}
				</div>`;

			div.addEventListener('click', (): void => {
				moveTabToWindow(w, t);
			});

			openWindowsElement.appendChild(div);
		}

		count++;
	});

	utils.queryOrThrow('#current-tab').innerHTML = `<div class="title-bar"><img src="${t.favIconUrl}"/>` +
		`<div class="screen-title">${t.title}</div></div>`;
};
Example #3
0
export const popTab = async (): Promise<void> => {
	const w: browser.windows.Window = await browser.windows.getCurrent({populate:true});

	if (w.tabs && w.tabs.length !== 1) {
		const t: browser.tabs.Tab = await utils.tabs.getCurrent();

		browser.windows.create({tabId: t.id}).catch((e: Error): void => {
			logging.error(e.message);
		});

		browser.tabs.update(t.id, {pinned: t.pinned}).catch((e: Error): void => {
			logging.error(e.message);
		});
	}
};
Example #4
0
export const gatherWindow = async (): Promise<void> => {
	const windows: browser.windows.Window[] = await browser.windows.getAll({populate: true});

	let isFirstWindow: boolean = true;
	let firstWindowId: number | undefined;

	windows.forEach((w: browser.windows.Window): void => {
		if (isFirstWindow) {
			isFirstWindow = false;
			firstWindowId = w.id;
		} else {
			if (!w.tabs) {
				return;
			}

			w.tabs.forEach((t: browser.tabs.Tab): void => {
				browser.tabs.move(
					t.id,
					{windowId: firstWindowId, index: -1},
				).catch((e: Error): void => {
					logging.error(e.message);
				});
			});
		}
	});
};
Example #5
0
export const explodeWindow = async (): Promise<void> => {
	const windows: browser.windows.Window[] = await browser.windows.getAll({populate: true});

	windows.forEach((w: browser.windows.Window): void => {
		if (!w.tabs) {
			return;
		}

		w.tabs.forEach((t: browser.tabs.Tab): void => {
			const width: number = Math.floor(Math.random() * (screen.width * 0.75) + 1);
			const height: number = Math.floor(Math.random() * (screen.height * 0.75) + 1);
			const left: number = Math.floor(Math.random() * (screen.width - width) + 1);
			const top: number = Math.floor(Math.random() * (screen.height - height) + 1);

			browser.windows.create({
				tabId: t.id,
				width,
				height,
				left,
				top,
			}).catch((e: Error): void => {
				logging.error(e.message);
			});
		});
	});
};
Example #6
0
		w.tabs.forEach((t: browser.tabs.Tab): void => {
			const width: number = Math.floor(Math.random() * (screen.width * 0.75) + 1);
			const height: number = Math.floor(Math.random() * (screen.height * 0.75) + 1);
			const left: number = Math.floor(Math.random() * (screen.width - width) + 1);
			const top: number = Math.floor(Math.random() * (screen.height - height) + 1);

			browser.windows.create({
				tabId: t.id,
				width,
				height,
				left,
				top,
			}).catch((e: Error): void => {
				logging.error(e.message);
			});
		});
Example #7
0
export const moveTabToWindow = async (w: browser.windows.Window, t: browser.tabs.Tab): Promise<void> => {
	browser.tabs.move(t.id, {windowId: w.id, index: -1}).catch(
		(e: Error): void => {
			logging.error(e.message);
		}
	);

	browser.windows.update(w.id, {focused: true}).catch(
		(e: Error): void => {
			logging.error(e.message);
		}
	);

	browser.tabs.update(t.id, {selected: true, pinned: t.pinned}).catch(
		(e: Error): void => {
			logging.error(e.message);
		}
	);
};