FlightConnections Premium

Unlock premium features on flightconnections.com.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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