FlightConnections Premium

Unlock premium features on flightconnections.com.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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
})();