diff --git a/src/manifest-chrome.json b/src/manifest-chrome.json index 43ba476..be293dd 100644 --- a/src/manifest-chrome.json +++ b/src/manifest-chrome.json @@ -2,8 +2,8 @@ "manifest_version": 2, "name": "Grabby", "description": "An extension for downloading files and media from websites.", - "version": "0.62.14", - "version_name": "0.62.14", + "version": "0.62.15", + "version_name": "0.62.15", "author": "Pouria Pirhadi", "homepage_url": "https://github.com/pouriap/Grabby", "key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQC0Z61bUCTt90ySxy/HiQxseplfx9D4ra1+u2x7YlnHv3kx9Q/QkD+0Q95p4m8Co7D2Zjs3cB+r6ZukhCGEUqFoU+X6dEQfAKXZPkotmtZ8sOVs+tM5S3zay0MHMSmkksEvr4Z1URaseBSg/G8+qu+CvLb4pAS0qCxhZFb8awaBERMFylD7tXta60+2/zPAvw2Wj4WmSNhtXQWzMttM3qUgsEAGJeO5p5QjiJjOjoRC/cAbkTub48A6HgduBFUqkMY2FYQFgqttySrQrJjvK+RBhEu3P6xICUTE5i4PC4q4Yl1r+cYs4mygnWZbwu3wyFl4u7OkFXUIg4QFtlKICfWp", diff --git a/src/manifest.json b/src/manifest.json index eef2d4b..de1e285 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "Grabby", "description": "An extension for downloading files and media from websites.", - "version": "0.62.14", + "version": "0.62.15", "author": "Pouria Pirhadi", "homepage_url": "https://github.com/pouriap/Grabby", diff --git a/src/scripts/classes.ts b/src/scripts/classes.ts index 71a1e11..f1a134b 100644 --- a/src/scripts/classes.ts +++ b/src/scripts/classes.ts @@ -125,6 +125,16 @@ class Grabby log.warn('download is duplicate of', duplicate); + if(!download.tabId) + { + download.tabId = download.ownerTabId; + } + + if(!duplicate.tabId) + { + duplicate.tabId = duplicate.ownerTabId; + } + //if the duplicate is from the same tab as the previous download do not add it if(duplicate.tabId === download.tabId) { @@ -132,9 +142,13 @@ class Grabby return; } + //todo: handle this if(!download.tabId) { - log.err('duplicate download does not have a tab id', download); + //if we are here we do not have a tab ID nor a ownertabid so it will be shown + //on every tab so no need to add it again + log.warn('duplicate download does not have a tab id', download); + return; } //if there is a duplicate but it's from another tab then add a salt to it @@ -297,8 +311,6 @@ class BaseDownload private _host: str_und = undefined; private _filesize: num_und = -1; private _fileExtension: str_und = undefined; - private _ownerTabId: num_und = undefined; - private _ownerTabUrl: str_und = undefined; private _isFromBlankTab: bool_und = undefined; private _tabs: SureMap; @@ -320,50 +332,65 @@ class BaseDownload this._hash_src = details.url; } - get ownerTabId(): number + get ownerTabId(): number | undefined { - if(typeof this._ownerTabId === 'undefined') + //todo: what do? + if(typeof this.tabId === 'undefined') { - //todo: handle this case - //if this is a download not associated with any tabs like service workers (reddit.com) - if(typeof this.tabId === 'undefined'){ - log.err('download does not have a tab id', this); + for(let [tabId, tabInfo] of this._tabs.entries()) + { + if(this.url === tabInfo.url) + { + return tabId; + } + log.d(this.url, ' [does not equal] ', tabInfo.url); } - if(this.isFromBlankTab) + for(let [tabId, tabInfo] of this._tabs.entries()) { - let tab = this._tabs.getsure(this.tabId); - - if(typeof tab.openerId === 'undefined') + if(this.httpDetails.documentUrl === tabInfo.url) { - //this happens when we open a blank tab directly - //for example a bookmark to here: https://www.st.com/resource/en/datasheet/lm317.pdf - log.warn('blank tab does not have an opener id', tab); - this._ownerTabId = this.tabId; + return tabId; } - else + } + + for(let [tabId, tabInfo] of this._tabs.entries()) + { + if(this.httpDetails.originUrl === tabInfo.url) { - this._ownerTabId = tab.openerId; + return tabId; } } + + log.warn('could not find owner tab for download', this); + return undefined; + } + else if(this.isFromBlankTab) + { + let tab = this._tabs.getsure(this.tabId); + + if(typeof tab.openerId === 'undefined') + { + //this happens when we open a blank tab directly + //for example a bookmark to here: https://www.st.com/resource/en/datasheet/lm317.pdf + log.warn('blank tab does not have an opener id', tab); + return this.tabId; + } else { - this._ownerTabId = this.tabId; + return tab.openerId; } } - - return this._ownerTabId; - } - - get ownerTabUrl(): string - { - if(typeof this._ownerTabUrl === 'undefined') + else { - let tab = this._tabs.getsure(this.ownerTabId); - this._ownerTabUrl = tab.url; + return this.tabId; } + } - return this._ownerTabUrl; + get ownerTabUrl(): string | undefined + { + if(typeof this.ownerTabId == 'undefined') return undefined; + return this._tabs.getsure(this.ownerTabId).url; } get isFromBlankTab(): boolean @@ -830,13 +857,20 @@ class StreamDownload extends GrabbedDownload implements YTDLableDownload