178 lines
4.8 KiB
JavaScript
178 lines
4.8 KiB
JavaScript
/**
|
||
* Оптимизированный скрипт прокси для tmdb на основе скрипта https://skaztv.online/t.js
|
||
*/
|
||
(function () {
|
||
'use strict';
|
||
|
||
const DOMAIN = 'cubnotrip.top';
|
||
const API_ENDPOINTS = [
|
||
{ url: `https://${DOMAIN}/api/checker`, name: DOMAIN }
|
||
];
|
||
|
||
const tmdbProxy = {
|
||
name: 'TMDB Proxy by Skaz (Mod. LeMaX)',
|
||
version: '1.0.5',
|
||
description: 'Проксирование постеров и API сайта TMDB (Optimized )',
|
||
pathImage: `imagetmdb.${DOMAIN}/`,
|
||
pathApi: `apitmdb.${DOMAIN}/3/`
|
||
};
|
||
|
||
// Кэширование результатов проверки API
|
||
let apiCheckComplete = false;
|
||
|
||
/**
|
||
* Проверка доступности API
|
||
*/
|
||
function checkApiAvailability() {
|
||
if (apiCheckComplete) return;
|
||
|
||
let currentIndex = 0;
|
||
|
||
function tryNextEndpoint() {
|
||
if (currentIndex >= API_ENDPOINTS.length) return;
|
||
|
||
const endpoint = API_ENDPOINTS[currentIndex];
|
||
const xhr = new XMLHttpRequest();
|
||
|
||
xhr.open('GET', endpoint.url, true);
|
||
xhr.timeout = 5000;
|
||
|
||
xhr.onload = function() {
|
||
if (xhr.status === 200) {
|
||
try {
|
||
const response = xhr.responseText;
|
||
if (response === 'ok') {
|
||
localStorage.setItem('cub_domain', endpoint.name);
|
||
apiCheckComplete = true;
|
||
return;
|
||
}
|
||
} catch (error) {
|
||
console.warn('API check error:', error);
|
||
}
|
||
}
|
||
currentIndex++;
|
||
tryNextEndpoint();
|
||
};
|
||
|
||
xhr.onerror = xhr.ontimeout = function() {
|
||
currentIndex++;
|
||
tryNextEndpoint();
|
||
};
|
||
|
||
xhr.send();
|
||
}
|
||
|
||
tryNextEndpoint();
|
||
}
|
||
|
||
/**
|
||
* Фильтрация URL (замена обратных слешей)
|
||
*/
|
||
function filterUrl(url) {
|
||
const prefix = url.slice(0, 8);
|
||
const suffix = url.slice(8).replace(/\/\+/g, '/');
|
||
return prefix + suffix;
|
||
}
|
||
|
||
/**
|
||
* Получение email пользователя
|
||
*/
|
||
function getUserEmail() {
|
||
try {
|
||
const account = Lampa.Storage.get('account', '{}');
|
||
return (typeof account === 'string' ? JSON.parse(account) : account).email || '';
|
||
} catch (e) {
|
||
return '';
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Добавление email параметра к URL
|
||
*/
|
||
function addEmailParam(url) {
|
||
const email = getUserEmail();
|
||
return email ? Lampa.Utils.addUrlComponent(url, `email=${encodeURIComponent(email)}`) : url;
|
||
}
|
||
|
||
/**
|
||
* Инициализация проверки API
|
||
*/
|
||
if (Lampa.Storage.get('cub_domain_skaz') === 1) {
|
||
checkApiAvailability();
|
||
}
|
||
|
||
// Отключение кэширования изображений
|
||
Lampa.Storage.set('cache_images', false);
|
||
|
||
/**
|
||
* Переопределение метода получения изображений TMDB
|
||
*/
|
||
Lampa.TMDB.image = function (url) {
|
||
const protocol = Lampa.Utils.protocol();
|
||
const isProxyEnabled = Lampa.Storage.field('proxy_tmdb');
|
||
|
||
const baseUrl = isProxyEnabled
|
||
? `${protocol}${tmdbProxy.pathImage}${url}`
|
||
: `${protocol}image.tmdb.org/${url}`;
|
||
|
||
return addEmailParam(filterUrl(baseUrl));
|
||
};
|
||
|
||
/**
|
||
* Переопределение метода API TMDB
|
||
*/
|
||
Lampa.TMDB.api = function (url) {
|
||
const protocol = Lampa.Utils.protocol();
|
||
const isProxyEnabled = Lampa.Storage.field('proxy_tmdb');
|
||
|
||
const baseUrl = isProxyEnabled
|
||
? `${protocol}${tmdbProxy.pathApi}${url}`
|
||
: `${protocol}api.themoviedb.org/3/${url}`;
|
||
|
||
return addEmailParam(filterUrl(baseUrl));
|
||
};
|
||
|
||
/**
|
||
* Удаление стандартного прокси из настроек
|
||
*/
|
||
Lampa.Settings.listener.follow('open', function (event) {
|
||
if (event.name === 'tmdb') {
|
||
event.body.find('[data-parent="proxy"]').remove();
|
||
}
|
||
});
|
||
|
||
console.log(
|
||
'TMDB-Proxy',
|
||
`v${tmdbProxy.version} started, enabled:`,
|
||
Lampa.Storage.field('proxy_tmdb')
|
||
);
|
||
|
||
/**
|
||
* Добавление компонента настроек
|
||
*/
|
||
Lampa.SettingsApi.addComponent({
|
||
component: 'iptvskaz',
|
||
icon: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 2L2 7v10c0 5.55 3.84 10.74 9 12 5.16-1.26 9-6.45 9-12V7l-10-5z"/></svg>',
|
||
name: 'by Skaz (Optimized)'
|
||
});
|
||
|
||
/**
|
||
* Добавление параметра настроек
|
||
*/
|
||
Lampa.SettingsApi.addParam({
|
||
component: 'iptvskaz',
|
||
param: {
|
||
name: 'b_skaz',
|
||
type: 'trigger',
|
||
default: false
|
||
},
|
||
field: {
|
||
name: 'Убрать с главной трансляции',
|
||
description: 'Убирает с главной трансляцию события'
|
||
},
|
||
onChange: function (value) {
|
||
Lampa.Noty.show('Необходимо перезайти в лампу');
|
||
}
|
||
});
|
||
})();
|