-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,52 @@ | ||
class JBFisher { | ||
|
||
static main = () => { | ||
|
||
const URL_DOWNLOADS = 'plugins.jetbrains.com'; | ||
const URL_PLUGINS = 'download.jetbrains.com'; | ||
|
||
const init = () => { | ||
switch (true) { | ||
case imHere(URL_DOWNLOADS): | ||
redirectPlugins(); | ||
break; | ||
case imHere(URL_PLUGINS): | ||
redirectDownloads(); | ||
break; | ||
default: | ||
break; | ||
} | ||
static DOMAINS = { | ||
PLUGIN: 'plugins.jetbrains.com', | ||
PLUGIN_NEW: 'downloads.marketplace.jetbrains.com', | ||
BINARY: 'download.jetbrains.com', | ||
BINARY_NEW: 'download-cdn.jetbrains.com', | ||
}; | ||
|
||
static main = () => this.#handleRedirect(); | ||
|
||
static #handleRedirect() { | ||
switch (true) { | ||
case this.#isCurrentDomain(this.DOMAINS.PLUGIN): | ||
this.#redirectPlugin(); | ||
break; | ||
case this.#isCurrentDomain(this.DOMAINS.BINARY): | ||
this.#redirectBinary(); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
const imHere = (url) => location.origin.includes(`://${url}`); | ||
static #isCurrentDomain = (domain) => location.origin.includes(`://${domain}`); | ||
|
||
const redirectPlugins = () => { | ||
const isValidPath = location.pathname.includes('/files/') && location.search.includes('pluginId='); | ||
if (isValidPath) { | ||
location.href = `https://downloads.marketplace.jetbrains.com${location.pathname}${location.search}`; | ||
} | ||
static #redirectPlugin() { | ||
if (this.#isValidPluginPage()) { | ||
const newUrl = this.#buildNewPluginUrl() | ||
this.#redirect(newUrl); | ||
} | ||
} | ||
|
||
const redirectDownloads = () => { | ||
const newOrigin = location.origin.replace('download.jetbrains.com', 'download-cdn.jetbrains.com'); | ||
location.href = `${newOrigin}${location.pathname}${location.search}`; | ||
} | ||
static #isValidPluginPage = () => location.pathname.includes('/files/') && location.search.includes('pluginId='); | ||
|
||
static #buildNewPluginUrl = () => `https://${this.DOMAINS.PLUGIN_NEW}${location.pathname}${location.search}`; | ||
|
||
init(); | ||
static #redirectBinary() { | ||
const newUrl = this.#buildNewBinaryUrl(); | ||
this.#redirect(newUrl); | ||
} | ||
|
||
static #buildNewBinaryUrl() { | ||
const newOrigin = location.origin.replace(this.DOMAINS.BINARY, this.DOMAINS.BINARY_NEW); | ||
return `${newOrigin}${location.pathname}${location.search}`; | ||
} | ||
|
||
static #redirect = (href) => location.href = href; | ||
|
||
} | ||
|
||
JBFisher.main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters