Skip to content

Commit

Permalink
рефакторинг
Browse files Browse the repository at this point in the history
  • Loading branch information
blazer404 committed Nov 30, 2024
1 parent e8bf19a commit adfe4bc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
66 changes: 39 additions & 27 deletions jb_fisher/main.js
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();
2 changes: 1 addition & 1 deletion jb_fisher/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "JB Fisher",
"version": "0.1",
"version": "0.2",
"description": "Анус себе заблокируй",
"developer": {
"name": "BlazeR404",
Expand Down

0 comments on commit adfe4bc

Please sign in to comment.