diff options
Diffstat (limited to 'js/tab.js')
-rw-r--r-- | js/tab.js | 562 |
1 files changed, 281 insertions, 281 deletions
@@ -2,7 +2,7 @@ ηMatrix - a browser extension to black/white list requests. Copyright (C) 2014-2019 Raymond Hill - Copyright (C) 2019-2020 Alessio Vanni + Copyright (C) 2019-2022 Alessio Vanni This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see {http://www.gnu.org/licenses/}. - Home: https://libregit.spks.xyz/heckyel/ematrix + Home: https://gitlab.com/vannilla/ematrix uMatrix Home: https://github.com/gorhill/uMatrix */ @@ -40,47 +40,47 @@ // apply only to that scheme. ηm.normalizePageURL = function (tabId, pageURL) { - if (vAPI.isBehindTheSceneTabId(tabId)) { + if (vAPI.isBehindTheSceneTabId(tabId)) { return 'http://' + this.behindTheSceneScope + '/'; - } - - // https://github.com/gorhill/uMatrix/issues/992 - if (pageURL.startsWith('wyciwyg:')) { - // Matches strings like 'wyciwyg://101/' - let filter = /^wyciwyg:\/\/\d+\//.exec(pageURL); - if (filter) { - pageURL = pageURL.slice(filter[0].length); - } - } - - // If the URL is that of our "blocked page" document, return - // the URL of the blocked page. - if (pageURL.lastIndexOf(vAPI.getURL('main-blocked.html'), 0) === 0) { + } + + // https://github.com/gorhill/uMatrix/issues/992 + if (pageURL.startsWith('wyciwyg:')) { + // Matches strings like 'wyciwyg://101/' + let filter = /^wyciwyg:\/\/\d+\//.exec(pageURL); + if (filter) { + pageURL = pageURL.slice(filter[0].length); + } + } + + // If the URL is that of our "blocked page" document, return + // the URL of the blocked page. + if (pageURL.lastIndexOf(vAPI.getURL('main-blocked.html'), 0) === 0) { let matches = /main-blocked\.html\?details=([^&]+)/.exec(pageURL); if (matches && matches.length === 2) { - try { + try { let details = JSON.parse(atob(matches[1])); pageURL = details.url; - } catch (e) { - } + } catch (e) { + } } - } + } - let uri = UriTools.set(pageURL); - let scheme = uri.scheme; - if (scheme === 'https' || scheme === 'http') { + let uri = UriTools.set(pageURL); + let scheme = uri.scheme; + if (scheme === 'https' || scheme === 'http') { return UriTools.normalizedURI(); - } + } - let fakeHostname = scheme + '-scheme'; + let fakeHostname = scheme + '-scheme'; - if (uri.hostname !== '') { + if (uri.hostname !== '') { fakeHostname = uri.hostname + '.' + fakeHostname; - } else if (scheme === 'about') { + } else if (scheme === 'about') { fakeHostname = uri.path + '.' + fakeHostname; - } + } - return 'http://' + fakeHostname + '/'; + return 'http://' + fakeHostname + '/'; }; /* @@ -149,119 +149,119 @@ */ ηm.tabContextManager = (function () { - let tabContexts = Object.create(null); + let tabContexts = Object.create(null); - // https://github.com/chrisaljoudi/uBlock/issues/1001 - // This is to be used as last-resort fallback in case a tab is - // found to not be bound while network requests are fired for - // the tab. - let mostRecentRootDocURL = ''; - let mostRecentRootDocURLTimestamp = 0; + // https://github.com/chrisaljoudi/uBlock/issues/1001 + // This is to be used as last-resort fallback in case a tab is + // found to not be bound while network requests are fired for + // the tab. + let mostRecentRootDocURL = ''; + let mostRecentRootDocURLTimestamp = 0; - let gcPeriod = 31 * 60 * 1000; // every 31 minutes + let gcPeriod = 31 * 60 * 1000; // every 31 minutes - // A pushed entry is removed from the stack unless it is - // committed with a set time. - let StackEntry = function (url, commit) { + // A pushed entry is removed from the stack unless it is + // committed with a set time. + let StackEntry = function (url, commit) { this.url = url; this.committed = commit; this.tstamp = Date.now(); - }; + }; - let TabContext = function (tabId) { + let TabContext = function (tabId) { this.tabId = tabId; this.stack = []; this.rawURL = - this.normalURL = - this.scheme = - this.rootHostname = - this.rootDomain = ''; + this.normalURL = + this.scheme = + this.rootHostname = + this.rootDomain = ''; this.secure = false; this.commitTimer = null; this.gcTimer = null; tabContexts[tabId] = this; - }; + }; - TabContext.prototype.destroy = function () { + TabContext.prototype.destroy = function () { if (vAPI.isBehindTheSceneTabId(this.tabId)) { - return; + return; } if (this.gcTimer !== null) { - clearTimeout(this.gcTimer); - this.gcTimer = null; + clearTimeout(this.gcTimer); + this.gcTimer = null; } delete tabContexts[this.tabId]; - }; + }; - TabContext.prototype.onTab = function (tab) { + TabContext.prototype.onTab = function (tab) { if (tab) { - this.gcTimer = vAPI.setTimeout(this.onGC.bind(this), gcPeriod); + this.gcTimer = vAPI.setTimeout(this.onGC.bind(this), gcPeriod); } else { - this.destroy(); + this.destroy(); } - }; + }; - TabContext.prototype.onGC = function () { + TabContext.prototype.onGC = function () { this.gcTimer = null; if (vAPI.isBehindTheSceneTabId(this.tabId)) { - return; + return; } vAPI.tabs.get(this.tabId, this.onTab.bind(this)); - }; + }; - // https://github.com/gorhill/uBlock/issues/248 - // Stack entries have to be committed to stick. Non-committed - // stack entries are removed after a set delay. - TabContext.prototype.onCommit = function () { + // https://github.com/gorhill/uBlock/issues/248 + // Stack entries have to be committed to stick. Non-committed + // stack entries are removed after a set delay. + TabContext.prototype.onCommit = function () { if (vAPI.isBehindTheSceneTabId(this.tabId)) { - return; + return; } this.commitTimer = null; // Remove uncommitted entries at the top of the stack. let i = this.stack.length; while (i--) { - if (this.stack[i].committed) { + if (this.stack[i].committed) { break; - } + } } // https://github.com/gorhill/uBlock/issues/300 // If no committed entry was found, fall back on the bottom-most one // as being the committed one by default. if (i === -1 && this.stack.length !== 0) { - this.stack[0].committed = true; - i = 0; + this.stack[0].committed = true; + i = 0; } ++i; if (i < this.stack.length) { - this.stack.length = i; - this.update(); - ηm.bindTabToPageStats(this.tabId, 'newURL'); + this.stack.length = i; + this.update(); + ηm.bindTabToPageStats(this.tabId, 'newURL'); } - }; + }; - // This takes care of orphanized tab contexts. Can't be - // started for all contexts, as the behind-the-scene context - // is permanent -- so we do not want to flush it. - TabContext.prototype.autodestroy = function () { + // This takes care of orphanized tab contexts. Can't be + // started for all contexts, as the behind-the-scene context + // is permanent -- so we do not want to flush it. + TabContext.prototype.autodestroy = function () { if (vAPI.isBehindTheSceneTabId(this.tabId)) { - return; + return; } this.gcTimer = vAPI.setTimeout(this.onGC.bind(this), gcPeriod); - }; + }; - // Update just force all properties to be updated to match the - // most recent root URL. - TabContext.prototype.update = function () { + // Update just force all properties to be updated to match the + // most recent root URL. + TabContext.prototype.update = function () { if (this.stack.length === 0) { - this.rawURL = - this.normalURL = - this.scheme = - this.rootHostname = - this.rootDomain = ''; - this.secure = false; - return; + this.rawURL = + this.normalURL = + this.scheme = + this.rootHostname = + this.rootDomain = ''; + this.secure = false; + return; } this.rawURL = this.stack[this.stack.length - 1].url; @@ -269,71 +269,71 @@ this.scheme = UriTools.schemeFromURI(this.rawURL); this.rootHostname = UriTools.hostnameFromURI(this.normalURL); this.rootDomain = UriTools.domainFromHostname(this.rootHostname) - || this.rootHostname; + || this.rootHostname; this.secure = UriTools.isSecureScheme(this.scheme); - }; + }; - // Called whenever a candidate root URL is spotted for the tab. - TabContext.prototype.push = function (url, context) { + // Called whenever a candidate root URL is spotted for the tab. + TabContext.prototype.push = function (url, context) { if (vAPI.isBehindTheSceneTabId(this.tabId)) { - return; - } + return; + } let committed = context !== undefined; let count = this.stack.length; let topEntry = this.stack[count - 1]; if (topEntry && topEntry.url === url) { - if (committed) { + if (committed) { topEntry.committed = true; - } - return; + } + return; } if (this.commitTimer !== null) { - clearTimeout(this.commitTimer); + clearTimeout(this.commitTimer); } if (committed) { - this.stack = [new StackEntry(url, true)]; + this.stack = [new StackEntry(url, true)]; } else { - this.stack.push(new StackEntry(url)); - this.commitTimer = - vAPI.setTimeout(this.onCommit.bind(this), 1000); + this.stack.push(new StackEntry(url)); + this.commitTimer = + vAPI.setTimeout(this.onCommit.bind(this), 1000); } this.update(); ηm.bindTabToPageStats(this.tabId, context); - }; + }; - // These are to be used for the API of the tab context manager. + // These are to be used for the API of the tab context manager. - let push = function (tabId, url, context) { + let push = function (tabId, url, context) { let entry = tabContexts[tabId]; if (entry === undefined) { - entry = new TabContext(tabId); - entry.autodestroy(); + entry = new TabContext(tabId); + entry.autodestroy(); } entry.push(url, context); mostRecentRootDocURL = url; mostRecentRootDocURLTimestamp = Date.now(); return entry; - }; + }; - // Find a tab context for a specific tab. If none is found, - // attempt to fix this. When all fail, the behind-the-scene - // context is returned. - let mustLookup = function (tabId, url) { + // Find a tab context for a specific tab. If none is found, + // attempt to fix this. When all fail, the behind-the-scene + // context is returned. + let mustLookup = function (tabId, url) { let entry; if (url !== undefined) { - entry = push(tabId, url); + entry = push(tabId, url); } else { - entry = tabContexts[tabId]; + entry = tabContexts[tabId]; } if (entry !== undefined) { - return entry; + return entry; } // https://github.com/chrisaljoudi/uBlock/issues/1025 @@ -342,8 +342,8 @@ // it is too far in the future, at which point it ceases // to be a "best guess". if (mostRecentRootDocURL - !== '' && mostRecentRootDocURLTimestamp + 500 < Date.now()) { - mostRecentRootDocURL = ''; + !== '' && mostRecentRootDocURLTimestamp + 500 < Date.now()) { + mostRecentRootDocURL = ''; } // https://github.com/chrisaljoudi/uBlock/issues/1001 @@ -352,7 +352,7 @@ // document to the unbound tab. It's a guess, but better // than ending up filtering nothing at all. if (mostRecentRootDocURL !== '') { - return push(tabId, mostRecentRootDocURL); + return push(tabId, mostRecentRootDocURL); } // If all else fail at finding a page store, re-categorize @@ -363,69 +363,69 @@ // Example: Chromium + case #12 at // http://raymondhill.net/ublock/popup.html return tabContexts[vAPI.noTabId]; - }; + }; - let lookup = function (tabId) { + let lookup = function (tabId) { return tabContexts[tabId] || null; - }; + }; - // Behind-the-scene tab context - (function () { + // Behind-the-scene tab context + (function () { let entry = new TabContext(vAPI.noTabId); entry.stack.push(new StackEntry('', true)); entry.rawURL = ''; entry.normalURL = ηm.normalizePageURL(entry.tabId); entry.rootHostname = UriTools.hostnameFromURI(entry.normalURL); entry.rootDomain = UriTools.domainFromHostname(entry.rootHostname) - || entry.rootHostname; - })(); + || entry.rootHostname; + })(); - // https://github.com/gorhill/uMatrix/issues/513 - // Force a badge update here, it could happen that all the - // subsequent network requests are already in the page - // store, which would cause the badge to no be updated for - // these network requests. + // https://github.com/gorhill/uMatrix/issues/513 + // Force a badge update here, it could happen that all the + // subsequent network requests are already in the page + // store, which would cause the badge to no be updated for + // these network requests. - vAPI.tabs.onNavigation = function (details) { + vAPI.tabs.onNavigation = function (details) { let tabId = details.tabId; if (vAPI.isBehindTheSceneTabId(tabId)) { - return; - } + return; + } push(tabId, details.url, 'newURL'); ηm.updateBadgeAsync(tabId); - }; + }; - // https://github.com/gorhill/uMatrix/issues/872 - // `changeInfo.url` may not always be available (Firefox). + // https://github.com/gorhill/uMatrix/issues/872 + // `changeInfo.url` may not always be available (Firefox). - vAPI.tabs.onUpdated = function (tabId, changeInfo, tab) { + vAPI.tabs.onUpdated = function (tabId, changeInfo, tab) { if (vAPI.isBehindTheSceneTabId(tabId)) { - return; - } + return; + } if (typeof tab.url !== 'string' || tab.url === '') { - return; - } + return; + } let url = changeInfo.url || tab.url; if (url) { - push(tabId, url, 'updateURL'); + push(tabId, url, 'updateURL'); } - }; + }; - vAPI.tabs.onClosed = function (tabId) { + vAPI.tabs.onClosed = function (tabId) { ηm.unbindTabFromPageStats(tabId); let entry = tabContexts[tabId]; if (entry instanceof TabContext) { - entry.destroy(); + entry.destroy(); } - }; + }; - return { + return { push: push, lookup: lookup, mustLookup: mustLookup - }; + }; })(); vAPI.tabs.registerListeners(); @@ -433,30 +433,30 @@ // Create an entry for the tab if it doesn't exist ηm.bindTabToPageStats = function (tabId, context) { - this.updateBadgeAsync(tabId); + this.updateBadgeAsync(tabId); - // Do not create a page store for URLs which are of no - // interests Example: dev console - let tabContext = this.tabContextManager.lookup(tabId); - if (tabContext === null) { + // Do not create a page store for URLs which are of no + // interests Example: dev console + let tabContext = this.tabContextManager.lookup(tabId); + if (tabContext === null) { throw new Error('Unmanaged tab id: ' + tabId); - } + } - // rhill 2013-11-24: Never ever rebind behind-the-scene - // virtual tab. - // https://github.com/gorhill/httpswitchboard/issues/67 - if (vAPI.isBehindTheSceneTabId(tabId)) { + // rhill 2013-11-24: Never ever rebind behind-the-scene + // virtual tab. + // https://github.com/gorhill/httpswitchboard/issues/67 + if (vAPI.isBehindTheSceneTabId(tabId)) { return this.pageStores[tabId]; - } + } - let normalURL = tabContext.normalURL; - let pageStore = this.pageStores[tabId] || null; + let normalURL = tabContext.normalURL; + let pageStore = this.pageStores[tabId] || null; - // The previous page URL, if any, associated with the tab - if (pageStore !== null) { + // The previous page URL, if any, associated with the tab + if (pageStore !== null) { // No change, do not rebind if (pageStore.pageUrl === normalURL) { - return pageStore; + return pageStore; } // https://github.com/gorhill/uMatrix/issues/37 @@ -466,124 +466,124 @@ // https://github.com/gorhill/uMatrix/issues/72 // Need to double-check that the new scope is same as old scope if (context === 'updateURL' - && pageStore.pageHostname === tabContext.rootHostname) { - pageStore.rawURL = tabContext.rawURL; - pageStore.normalURL = normalURL; - this.updateTitle(tabId); - this.pageStoresToken = Date.now(); - return pageStore; + && pageStore.pageHostname === tabContext.rootHostname) { + pageStore.rawURL = tabContext.rawURL; + pageStore.normalURL = normalURL; + this.updateTitle(tabId); + this.pageStoresToken = Date.now(); + return pageStore; } // We won't be reusing this page store. this.unbindTabFromPageStats(tabId); - } + } - // Try to resurrect first. - pageStore = this.resurrectPageStore(tabId, normalURL); - if (pageStore === null) { + // Try to resurrect first. + pageStore = this.resurrectPageStore(tabId, normalURL); + if (pageStore === null) { pageStore = this.pageStoreFactory(tabContext); - } - this.pageStores[tabId] = pageStore; - this.updateTitle(tabId); - this.pageStoresToken = Date.now(); + } + this.pageStores[tabId] = pageStore; + this.updateTitle(tabId); + this.pageStoresToken = Date.now(); - return pageStore; + return pageStore; }; ηm.unbindTabFromPageStats = function (tabId) { - if (vAPI.isBehindTheSceneTabId(tabId)) { + if (vAPI.isBehindTheSceneTabId(tabId)) { return; - } + } - let pageStore = this.pageStores[tabId] || null; - if (pageStore === null) { + let pageStore = this.pageStores[tabId] || null; + if (pageStore === null) { return; - } + } - delete this.pageStores[tabId]; - this.pageStoresToken = Date.now(); + delete this.pageStores[tabId]; + this.pageStoresToken = Date.now(); - if (pageStore.incinerationTimer) { + if (pageStore.incinerationTimer) { clearTimeout(pageStore.incinerationTimer); pageStore.incinerationTimer = null; - } + } - if (this.pageStoreCemetery.hasOwnProperty(tabId) === false) { + if (this.pageStoreCemetery.hasOwnProperty(tabId) === false) { this.pageStoreCemetery[tabId] = {}; - } - let pageStoreCrypt = this.pageStoreCemetery[tabId]; + } + let pageStoreCrypt = this.pageStoreCemetery[tabId]; - let pageURL = pageStore.pageUrl; - pageStoreCrypt[pageURL] = pageStore; + let pageURL = pageStore.pageUrl; + pageStoreCrypt[pageURL] = pageStore; - pageStore.incinerationTimer = - vAPI.setTimeout(this.incineratePageStore.bind(this, tabId, pageURL), - 4 * 60 * 1000); + pageStore.incinerationTimer = + vAPI.setTimeout(this.incineratePageStore.bind(this, tabId, pageURL), + 4 * 60 * 1000); }; ηm.resurrectPageStore = function (tabId, pageURL) { - if (this.pageStoreCemetery.hasOwnProperty(tabId) === false) { + if (this.pageStoreCemetery.hasOwnProperty(tabId) === false) { return null; - } + } - let pageStoreCrypt = this.pageStoreCemetery[tabId]; + let pageStoreCrypt = this.pageStoreCemetery[tabId]; - if (pageStoreCrypt.hasOwnProperty(pageURL) === false) { + if (pageStoreCrypt.hasOwnProperty(pageURL) === false) { return null; - } + } - let pageStore = pageStoreCrypt[pageURL]; + let pageStore = pageStoreCrypt[pageURL]; - if (pageStore.incinerationTimer !== null) { + if (pageStore.incinerationTimer !== null) { clearTimeout(pageStore.incinerationTimer); pageStore.incinerationTimer = null; - } + } - delete pageStoreCrypt[pageURL]; - if (Object.keys(pageStoreCrypt).length === 0) { + delete pageStoreCrypt[pageURL]; + if (Object.keys(pageStoreCrypt).length === 0) { delete this.pageStoreCemetery[tabId]; - } + } - return pageStore; + return pageStore; }; ηm.incineratePageStore = function (tabId, pageURL) { - if (this.pageStoreCemetery.hasOwnProperty(tabId) === false) { + if (this.pageStoreCemetery.hasOwnProperty(tabId) === false) { return; - } + } - let pageStoreCrypt = this.pageStoreCemetery[tabId]; + let pageStoreCrypt = this.pageStoreCemetery[tabId]; - if (pageStoreCrypt.hasOwnProperty(pageURL) === false) { + if (pageStoreCrypt.hasOwnProperty(pageURL) === false) { return; - } + } - let pageStore = pageStoreCrypt[pageURL]; - if (pageStore.incinerationTimer !== null) { + let pageStore = pageStoreCrypt[pageURL]; + if (pageStore.incinerationTimer !== null) { clearTimeout(pageStore.incinerationTimer); pageStore.incinerationTimer = null; - } + } - delete pageStoreCrypt[pageURL]; + delete pageStoreCrypt[pageURL]; - if (Object.keys(pageStoreCrypt).length === 0) { + if (Object.keys(pageStoreCrypt).length === 0) { delete this.pageStoreCemetery[tabId]; - } + } - pageStore.dispose(); + pageStore.dispose(); }; ηm.pageStoreFromTabId = function (tabId) { - return this.pageStores[tabId] || null; + return this.pageStores[tabId] || null; }; // Never return null ηm.mustPageStoreFromTabId = function (tabId) { - return this.pageStores[tabId] || this.pageStores[vAPI.noTabId]; + return this.pageStores[tabId] || this.pageStores[vAPI.noTabId]; }; ηm.forceReload = function (tabId, bypassCache) { - vAPI.tabs.reload(tabId, bypassCache); + vAPI.tabs.reload(tabId, bypassCache); }; // Update badge @@ -595,9 +595,9 @@ // ηMatrix: does it matter to us? ηm.updateBadgeAsync = (function () { - let tabIdToTimer = Object.create(null); + let tabIdToTimer = Object.create(null); - let updateBadge = function (tabId) { + let updateBadge = function (tabId) { delete tabIdToTimer[tabId]; let iconId = null; @@ -605,81 +605,81 @@ let pageStore = this.pageStoreFromTabId(tabId); if (pageStore !== null) { - let total = pageStore.perLoadAllowedRequestCount + + let total = pageStore.perLoadAllowedRequestCount + pageStore.perLoadBlockedRequestCount; - if (total) { + if (total) { let squareSize = 19; let greenSize = squareSize * - Math.sqrt(pageStore.perLoadAllowedRequestCount / total); + Math.sqrt(pageStore.perLoadAllowedRequestCount / total); iconId = greenSize < squareSize/2 ? - Math.ceil(greenSize) : - Math.floor(greenSize); - } + Math.ceil(greenSize) : + Math.floor(greenSize); + } - if (this.userSettings.iconBadgeEnabled - && pageStore.perLoadBlockedRequestCount !== 0) { + if (this.userSettings.iconBadgeEnabled + && pageStore.perLoadBlockedRequestCount !== 0) { badgeStr = - this.formatCount(pageStore.perLoadBlockedRequestCount); - } + this.formatCount(pageStore.perLoadBlockedRequestCount); + } } vAPI.setIcon(tabId, iconId, badgeStr); - }; + }; - return function (tabId) { + return function (tabId) { if (tabIdToTimer[tabId]) { - return; + return; } if (vAPI.isBehindTheSceneTabId(tabId)) { - return; + return; } tabIdToTimer[tabId] = - vAPI.setTimeout(updateBadge.bind(this, tabId), 750); - }; + vAPI.setTimeout(updateBadge.bind(this, tabId), 750); + }; })(); ηm.updateTitle = (function () { - let tabIdToTimer = Object.create(null); - let tabIdToTryCount = Object.create(null); - let delay = 499; + let tabIdToTimer = Object.create(null); + let tabIdToTryCount = Object.create(null); + let delay = 499; - let tryNoMore = function (tabId) { + let tryNoMore = function (tabId) { delete tabIdToTryCount[tabId]; - }; + }; - let tryAgain = function (tabId) { + let tryAgain = function (tabId) { let count = tabIdToTryCount[tabId]; if (count === undefined) { - return false; + return false; } if (count === 1) { - delete tabIdToTryCount[tabId]; - return false; + delete tabIdToTryCount[tabId]; + return false; } tabIdToTryCount[tabId] = count - 1; tabIdToTimer[tabId] = - vAPI.setTimeout(updateTitle.bind(ηm, tabId), delay); + vAPI.setTimeout(updateTitle.bind(ηm, tabId), delay); return true; - }; + }; - let onTabReady = function (tabId, tab) { + let onTabReady = function (tabId, tab) { if (!tab) { - return tryNoMore(tabId); + return tryNoMore(tabId); } let pageStore = this.pageStoreFromTabId(tabId); if (pageStore === null) { - return tryNoMore(tabId); + return tryNoMore(tabId); } if (!tab.title && tryAgain(tabId)) { - return; + return; } // https://github.com/gorhill/uMatrix/issues/225 @@ -688,67 +688,67 @@ pageStore.title = tab.title || tab.url || ''; this.pageStoresToken = Date.now(); if (settled || !tryAgain(tabId)) { - tryNoMore(tabId); + tryNoMore(tabId); } - }; + }; - let updateTitle = function (tabId) { + let updateTitle = function (tabId) { delete tabIdToTimer[tabId]; vAPI.tabs.get(tabId, onTabReady.bind(this, tabId)); - }; + }; - return function (tabId) { + return function (tabId) { if (vAPI.isBehindTheSceneTabId(tabId)) { - return; + return; } if (tabIdToTimer[tabId]) { - clearTimeout(tabIdToTimer[tabId]); + clearTimeout(tabIdToTimer[tabId]); } tabIdToTimer[tabId] = - vAPI.setTimeout(updateTitle.bind(this, tabId), delay); + vAPI.setTimeout(updateTitle.bind(this, tabId), delay); tabIdToTryCount[tabId] = 5; - }; + }; })(); // Stale page store entries janitor // https://github.com/chrisaljoudi/uBlock/issues/455 (function () { - let cleanupPeriod = 7 * 60 * 1000; - let cleanupSampleAt = 0; - let cleanupSampleSize = 11; + let cleanupPeriod = 7 * 60 * 1000; + let cleanupSampleAt = 0; + let cleanupSampleSize = 11; - let cleanup = function () { + let cleanup = function () { let tabIds = Object.keys(ηm.pageStores).sort(); let checkTab = function(tabId) { - vAPI.tabs.get(tabId, function (tab) { + vAPI.tabs.get(tabId, function (tab) { if (!tab) { - ηm.unbindTabFromPageStats(tabId); + ηm.unbindTabFromPageStats(tabId); } - }); + }); }; if (cleanupSampleAt >= tabIds.length) { - cleanupSampleAt = 0; + cleanupSampleAt = 0; } let tabId; let n = - Math.min(cleanupSampleAt + cleanupSampleSize, tabIds.length); + Math.min(cleanupSampleAt + cleanupSampleSize, tabIds.length); for (let i=cleanupSampleAt; i<n; i++) { - tabId = tabIds[i]; - if (vAPI.isBehindTheSceneTabId(tabId)) { + tabId = tabIds[i]; + if (vAPI.isBehindTheSceneTabId(tabId)) { continue; - } - checkTab(tabId); + } + checkTab(tabId); } cleanupSampleAt = n; vAPI.setTimeout(cleanup, cleanupPeriod); - }; + }; - vAPI.setTimeout(cleanup, cleanupPeriod); + vAPI.setTimeout(cleanup, cleanupPeriod); })(); })(); |