Skip to content

Commit

Permalink
Add per-template zoom support (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsavenko committed Dec 24, 2018
1 parent 56f71e5 commit dd9807e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/bg.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ let settings = {
remoteTemplates: new Map(),
typeTemplates: new Map(),
parserTemplates: new Map(),
templateZoom: new Map(),
githubUser: DEFAULT_SETTINGS.githubUser,
welcomePageShown: false
}
Expand Down Expand Up @@ -97,6 +98,7 @@ async function saveSettings() {
remoteTemplates: mapToTextArray(state.templates),
typeTemplates: [...settings.typeTemplates],
parserTemplates: [...settings.parserTemplates],
templateZoom: [...settings.templateZoom],
githubUser: settings.githubUser || DEFAULT_SETTINGS.githubUser,
welcomePageShown: settings.welcomePageShown || false
}
Expand Down Expand Up @@ -127,6 +129,7 @@ async function loadSettings() {
}
settings.typeTemplates = new Map(tmp.typeTemplates || [])
settings.parserTemplates = new Map(tmp.parserTemplates || [])
settings.templateZoom = new Map(tmp.templateZoom || [])
settings.githubUser = tmp.githubUser || DEFAULT_SETTINGS.githubUser,
settings.welcomePageShown = tmp.welcomePageShown || false
}
Expand Down Expand Up @@ -349,6 +352,11 @@ function onDOMContentLoaded(details) {
if (-1 != tabId && 0 == frameId && url) {
const binding = state.tabBindings.get(tabId)
if (binding) {
const templateZoom = settings.templateZoom.get(binding.template.name)
if (templateZoom) {
browser.tabs.setZoom(tabId, templateZoom.zoomFactor)
.catch(e => console.log('Failed to zoom', e))
}
executeRenderingScripts(tabId, binding)
.catch(e => console.log('Failed to execute rendering content scripts', e))
}
Expand Down Expand Up @@ -381,6 +389,15 @@ function onTabReplaced(addedTabId, removedTabId) {
onTabRemoved(removedTabId)
}

function onZoomChange(zoomChangeInfo) {
const {tabId, newZoomFactor} = zoomChangeInfo
const binding = state.tabBindings.get(tabId)
if (binding) {
settings.templateZoom.set(binding.template.name, {zoomFactor: newZoomFactor})
saveSettings()
}
}

async function initTabs() {
const tabs = await browser.tabs.query({})
tabs.forEach(tab => switchPageAction(tab.id, tab.url))
Expand Down Expand Up @@ -628,5 +645,6 @@ browser.runtime.onMessage.addListener(onMessage)

browser.tabs.onRemoved.addListener(onTabRemoved)
browser.tabs.onReplaced.addListener(onTabReplaced)
browser.tabs.onZoomChange.addListener(onZoomChange)

initTabs().catch(e => console.log('Failed to init tabs', e))
2 changes: 1 addition & 1 deletion src/moyparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ function checkAndUnifyInfo(info) {
const matcher = new RegExp(info.suggestedRegex)
info.testPages.forEach(url => {
if (!matcher.test(url)) {
throw new Error(`Test page doesn't match for parser '${name}': ${url}`)
throw new Error(`Test page doesn't match for parser '${name}': ${url}. RegExp: ${matcher}`)
}
})
info.author = checkAndUnifyAuthor(author)
Expand Down

0 comments on commit dd9807e

Please sign in to comment.