Remove unwarranted semi-colons

This commit is contained in:
Oliver Blanthorn 2020-10-30 15:09:08 +00:00
parent f8da0deaac
commit 78c64de1f9
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3

View file

@ -1064,18 +1064,18 @@ export function jumpprev(n = 1) {
//#content
export async function markjump(key: string) {
if (key.length !== 1) {
throw new Error("markjump accepts only a single letter or '`'");
throw new Error("markjump accepts only a single letter or '`'")
}
if (key === "`") {
return markjumpbefore()
}
if (!/[a-z]/i.exec(key)) {
throw new Error("markjump accepts only a single letter or '`'");
throw new Error("markjump accepts only a single letter or '`'")
}
if (key === key.toUpperCase()) {
return markjumpglobal(key);
return markjumpglobal(key)
}
return markjumplocal(key);
return markjumplocal(key)
}
/**
@ -1085,14 +1085,14 @@ export async function markjump(key: string) {
//#content
export async function markjumplocal(key: string) {
const urlWithoutAnchor = window.location.href.split("#")[0]
const localMarks = await State.getAsync("localMarks");
const mark = localMarks.get(urlWithoutAnchor)?.get(key);
const localMarks = await State.getAsync("localMarks")
const mark = localMarks.get(urlWithoutAnchor)?.get(key)
if (mark) {
const currentTabId = await activeTabId();
state.beforeJumpMark = { url: urlWithoutAnchor, scrollX: window.scrollX, scrollY: window.scrollY, tabId: currentTabId};
scrolltab(currentTabId, mark.scrollX, mark.scrollY, `Jumped to mark '${key}'`);
const currentTabId = await activeTabId()
state.beforeJumpMark = { url: urlWithoutAnchor, scrollX: window.scrollX, scrollY: window.scrollY, tabId: currentTabId}
scrolltab(currentTabId, mark.scrollX, mark.scrollY, `Jumped to mark '${key}'`)
}
return fillcmdline_tmp(3000, `Mark '${key}' is not set`);
return fillcmdline_tmp(3000, `Mark '${key}' is not set`)
}
/**
@ -1102,53 +1102,53 @@ export async function markjumplocal(key: string) {
*/
//#content
export async function markjumpglobal(key: string) {
const globalMarks = await State.getAsync("globalMarks");
const mark = globalMarks.get(key);
const globalMarks = await State.getAsync("globalMarks")
const mark = globalMarks.get(key)
if (!mark) {
return fillcmdline_tmp(3000, `Mark '${key}' is not set`);
return fillcmdline_tmp(3000, `Mark '${key}' is not set`)
}
const currentTabId = await activeTabId();
const currentTabId = await activeTabId()
state.beforeJumpMark = {
url: window.location.href.split("#")[0],
scrollX: window.scrollX,
scrollY: window.scrollY,
tabId: currentTabId
};
}
try {
const tab = await browserBg.tabs.get(mark.tabId);
return onTabExists(tab);
const tab = await browserBg.tabs.get(mark.tabId)
return onTabExists(tab)
} catch (e) {
return onTabNoLongerValid();
return onTabNoLongerValid()
}
async function onTabExists(tab) {
const tabUrl = tab.url.split("#")[0]
if (mark.url !== tabUrl) {
return onTabNoLongerValid();
return onTabNoLongerValid()
}
return goToTab(tab.id).then(() => {
scrolltab(tab.id, mark.scrollX, mark.scrollY, `Jumped to mark '${key}'`);
});
scrolltab(tab.id, mark.scrollX, mark.scrollY, `Jumped to mark '${key}'`)
})
}
// the tab with mark's tabId doesn't exist or it has a different url than the mark's url
async function onTabNoLongerValid() {
const matchingTabs = await browserBg.tabs.query({url: mark.url});
const matchingTabs = await browserBg.tabs.query({url: mark.url})
// If there are no matching tabs, open a new one and update the mark's tabId for future use in this session
if (!matchingTabs.length) {
return openInNewTab(mark.url).then(updateMarkAndScroll());
return openInNewTab(mark.url).then(updateMarkAndScroll())
}
// If there are multiple tabs open with the same url, just pick the first one and update the mark's tabId
// for future use in this session
return goToTab(matchingTabs[0].id).then(updateMarkAndScroll());
return goToTab(matchingTabs[0].id).then(updateMarkAndScroll())
}
function updateMarkAndScroll() {
return (tab) => {
mark.tabId = tab.id;
state.globalMarks = globalMarks;
scrolltab(tab.id, mark.scrollX, mark.scrollY, `Jumped to mark '${key}'`);
};
mark.tabId = tab.id
state.globalMarks = globalMarks
scrolltab(tab.id, mark.scrollX, mark.scrollY, `Jumped to mark '${key}'`)
}
}
}
@ -1158,20 +1158,20 @@ export async function markjumpglobal(key: string) {
*/
//#content
export async function markjumpbefore() {
const beforeJumpMark = await State.getAsync("beforeJumpMark");
const beforeJumpMark = await State.getAsync("beforeJumpMark")
if (!beforeJumpMark) {
return;
return
}
try {
const tab = await browserBg.tabs.get(beforeJumpMark.tabId);
const tab = await browserBg.tabs.get(beforeJumpMark.tabId)
const tabUrl = tab.url.split("#")[0]
const {url, scrollX, scrollY, tabId} = beforeJumpMark;
const {url, scrollX, scrollY, tabId} = beforeJumpMark
if (url !== tabUrl) {
return;
return
}
const currentTabId = await activeTabId();
state.beforeJumpMark = {url: window.location.href.split("#")[0], scrollX: window.scrollX, scrollY: window.scrollY, tabId: currentTabId};
goToTab(tabId).then(() => scrolltab(tabId, scrollX, scrollY, "Jumped to the last location before a mark jump"));
const currentTabId = await activeTabId()
state.beforeJumpMark = {url: window.location.href.split("#")[0], scrollX: window.scrollX, scrollY: window.scrollY, tabId: currentTabId}
goToTab(tabId).then(() => scrolltab(tabId, scrollX, scrollY, "Jumped to the last location before a mark jump"))
} catch (e) {
// the mark's tab is no longer valid
}
@ -1195,12 +1195,12 @@ export async function scrolltab(tabId: number, scrollX: number, scrollY: number,
//#content
export async function markadd(key: string) {
if (!/[a-z]/i.exec(key) || key.length !== 1) {
throw new Error("markadd accepts only a single letter");
throw new Error("markadd accepts only a single letter")
}
if (key === key.toUpperCase()) {
return markaddglobal(key);
return markaddglobal(key)
}
return markaddlocal(key);
return markaddlocal(key)
}
/**
@ -1211,13 +1211,13 @@ export async function markadd(key: string) {
//#content
export async function markaddlocal(key: string) {
const urlWithoutAnchor = window.location.href.split("#")[0]
const localMarks = await State.getAsync("localMarks");
const localUrlMarks = localMarks.get(urlWithoutAnchor) ? localMarks.get(urlWithoutAnchor) : new Map();
const newLocalMark = { scrollX: window.scrollX, scrollY: window.scrollY};
localUrlMarks.set(key, newLocalMark);
localMarks.set(urlWithoutAnchor, localUrlMarks);
state.localMarks = localMarks;
fillcmdline_tmp(3000, `Mark '${key}' set`);
const localMarks = await State.getAsync("localMarks")
const localUrlMarks = localMarks.get(urlWithoutAnchor) ? localMarks.get(urlWithoutAnchor) : new Map()
const newLocalMark = { scrollX: window.scrollX, scrollY: window.scrollY}
localUrlMarks.set(key, newLocalMark)
localMarks.set(urlWithoutAnchor, localUrlMarks)
state.localMarks = localMarks
fillcmdline_tmp(3000, `Mark '${key}' set`)
}
/**
@ -1227,12 +1227,12 @@ export async function markaddlocal(key: string) {
//#content
export async function markaddglobal(key: string) {
const urlWithoutAnchor = window.location.href.split("#")[0]
const globalMarks = await State.getAsync("globalMarks");
const globalMarks = await State.getAsync("globalMarks")
const tabId = await activeTabId()
const newGlobalMark = { url: urlWithoutAnchor, scrollX: window.scrollX, scrollY: window.scrollY, tabId };
globalMarks.set(key, newGlobalMark);
state.globalMarks = globalMarks;
fillcmdline_tmp(3000, `Mark '${key}' set`);
const newGlobalMark = { url: urlWithoutAnchor, scrollX: window.scrollX, scrollY: window.scrollY, tabId }
globalMarks.set(key, newGlobalMark)
state.globalMarks = globalMarks
fillcmdline_tmp(3000, `Mark '${key}' set`)
}
/** Called on 'scroll' events.