FlightConnections Premium

Unlock premium features on flightconnections.com.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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
})();