Skip to content

Instantly share code, notes, and snippets.

@assBuk
Last active February 16, 2024 01:10
Show Gist options
  • Save assBuk/f07bd2ad7ea2d1270fb92e6b51477d8f to your computer and use it in GitHub Desktop.
Save assBuk/f07bd2ad7ea2d1270fb92e6b51477d8f to your computer and use it in GitHub Desktop.
CRX Download
// ==UserScript==
// @name CRX Download
// @namespace https://gist.github.com/assBuk/f07bd2ad7ea2d1270fb92e6b51477d8f/
// @version 0.5
// @description Replace existing button with custom button
// @author Hth4nh && Assbuk
// @downloadURL https://gist.github.com/assBuk/f07bd2ad7ea2d1270fb92e6b51477d8f/raw/c637042ea84677b4a9153e4ea86e4d314b35ad12/CRX%2520Download.user.js
// @updateURL https://gist.github.com/assBuk/f07bd2ad7ea2d1270fb92e6b51477d8f/raw/c637042ea84677b4a9153e4ea86e4d314b35ad12/CRX%2520Download.user.js
// @match https://chromewebstore.google.com/detail/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Объект с переводами для разных языков
const translations = {
en: {
buttonText: 'Download CRX'
},
ru: {
buttonText: 'Скачать CRX'
},
ja: {
buttonText: 'CRXをダウンロード'
}
// Добавьте здесь другие языки и их переводы
};
// Функция для определения языка сайта
function getSiteLanguage() {
const htmlTag = document.documentElement;
return htmlTag.getAttribute('lang') || 'en'; // Возвращаем английский язык по умолчанию
}
// Функция для замены существующей кнопки на вашу
function replaceExistingButtonWithCustom() {
const siteLanguage = getSiteLanguage();
const translation = translations[siteLanguage] || translations['ja']; // Используем японский язык по умолчанию, если не ru и не en
const existingButton = document.querySelector('.UywwFc-LgbsSe'); // Замените селектор на актуальный
if (existingButton) {
let customButton = document.createElement('button');
customButton.textContent = translation.buttonText;
customButton.className = 'custom-button'; // Применяем класс кнопки
customButton.style.cssText = `
display: inline-block;
padding: 10px 20px;
margin-left: 10px;
font-size: 14px;
color: #fff;
background-color: #007bff; /* Серая кнопка */
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
`;
customButton.onmouseover = function() {
this.style.backgroundColor = '#153a8c'; // Голубой цвет при наведении
};
customButton.onmouseout = function() {
this.style.backgroundColor = '#007bff'; // Вернуть серой цвет при убирании курсора
};
customButton.onmousedown = function() {
this.style.backgroundColor = '#007bff'; // Голубой цвет при нажатии
};
customButton.onmouseup = function() {
this.style.backgroundColor = '#153a8c'; // Голубой цвет остается после отпускания кнопки
};
customButton.addEventListener('click', getCRXLink);
existingButton.replaceWith(customButton); // Заменяем существующую кнопку на вашу
}
}
// Функция для получения ссылки на CRX-файл и открытия её в новой вкладке
function getCRXLink() {
const pathSegments = location.pathname.split('/');
const extensionId = pathSegments[pathSegments.length - 1];
if (extensionId) {
const crxUrl = `https://clients2.google.com/service/update2/crx?response=redirect&prodversion=9999.0.9999.0&acceptformat=crx2,crx3&x=id%3D${extensionId}%26uc`;
window.open(crxUrl, '_blank'); // Открываем ссылку в новой вкладке
} else {
alert('Could not find extension ID');
}
}
window.addEventListener('load', replaceExistingButtonWithCustom);
})();
@assBuk
Copy link
Author

assBuk commented Feb 13, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment