FlightConnections Premium

Unlock premium features on flightconnections.com.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name               FlightConnections Premium
// @name:zh-CN         FlightConnections Premium
// @version            1.0.1
// @description        Unlock premium features on flightconnections.com.
// @description:zh-CN  解锁 flightconnections.com 的 Premium 功能。
// @run-at             document-start
// @match              https://www.flightconnections.com/*
// @grant              none
// @author             libraoly <[email protected]>
// @homepage           https://github.com/libraoly/userscripts
// @homepageURL        https://github.com/libraoly/userscripts
// @supportURL         https://github.com/libraoly/userscripts/issues
// @license            MIT
// @contributionURL    https://github.com/sponsors/libraoly
// @namespace          https://github.com/libraoly/userscripts/releases/latest/download/flightconnections-premium.user.js
// ==/UserScript==

(function() {
	//#region src/flightconnections-premium.ts
	const SCRIPT_NAME = "[FlightConnections Premium]";
	const SESSION_ID = "fake-session-123";
	const COOKIE_EXPIRE_DAYS = 90;
	const LS_KEY_USER_ID = "userID";
	const LS_KEY_SESSION_ID = "sessionID";
	const LS_KEY_USER_PROFILE = "userProfile";
	const COOKIE_NAME_USER_ID = "userID";
	const AUTH_HOST = "auth.flightconnections.com";
	const API_VALIDATE = "/validate";
	const API_AIRLINE_LISTS = "/airline_lists";
	const API_ACCOUNT = "/account";
	const API_EXTEND = "/extend";
	const FUNC_REVALIDATE = "revalidateUser";
	const CSS_CLASS_FREE = "free";
	const CSS_CLASS_STOP = "stop";
	const PROFILE = {
		account_id: "fake123",
		account_type: "member_annually",
		account_name: "Test User",
		account_email: "[email protected]",
		account_logo: ""
	};
	localStorage.setItem(LS_KEY_USER_ID, PROFILE.account_id);
	localStorage.setItem(LS_KEY_SESSION_ID, SESSION_ID);
	localStorage.setItem(LS_KEY_USER_PROFILE, JSON.stringify(PROFILE));
	const w = window;
	w.premiumUser = function() {
		return true;
	};
	w.openPremium = function() {};
	w.validateMember = function() {
		localStorage.setItem(LS_KEY_USER_PROFILE, JSON.stringify(PROFILE));
		const userId = localStorage.getItem(LS_KEY_USER_ID);
		if (userId && typeof w.setCookie === "function") w.setCookie(COOKIE_NAME_USER_ID, userId, COOKIE_EXPIRE_DAYS);
	};
	w.userLoggedIn = function(e) {
		if (e) document.body.classList.remove(CSS_CLASS_FREE);
	};
	w.loadUserAirlineLists = function() {};
	w.manageAccount = function() {};
	function removeStopClass() {
		document.body.classList.remove(CSS_CLASS_STOP);
	}
	removeStopClass();
	new MutationObserver((mutations) => {
		for (const mutation of mutations) if (mutation.type === "attributes" && mutation.attributeName === "class" && mutation.target.classList.contains(CSS_CLASS_STOP)) removeStopClass();
	}).observe(document.body, {
		attributes: true,
		attributeFilter: ["class"]
	});
	const origSetInterval = window.setInterval;
	window.setInterval = function(fn, _delay, ...args) {
		if (typeof fn === "function" && fn.toString().includes(FUNC_REVALIDATE)) return 0;
		return origSetInterval.call(this, fn, _delay, ...args);
	};
	const origAjax = w.$.ajax;
	w.$.ajax = function(options) {
		if (options.url && options.url.includes(AUTH_HOST)) {
			if (options.url.includes(API_VALIDATE)) {
				if (options.success) options.success({ result: PROFILE }, "success");
				return {
					done(fn) {
						if (fn) fn({ result: PROFILE });
						return this;
					},
					fail() {
						return this;
					}
				};
			}
			if (options.url.includes(API_AIRLINE_LISTS) || options.url.includes(API_ACCOUNT)) {
				if (options.success) options.success({ result: [] }, "success");
				return {
					done(fn) {
						if (fn) fn({ result: [] });
						return this;
					},
					fail() {
						return this;
					}
				};
			}
			if (options.url.includes(API_EXTEND)) {
				if (options.success) options.success({ result: true }, "success");
				return {
					done(fn) {
						if (fn) fn({ result: true });
						return this;
					},
					fail() {
						return this;
					}
				};
			}
		}
		return origAjax.call(this, options);
	};
	console.warn(`${SCRIPT_NAME} Script loaded successfully`);
	//#endregion
})();