ChromeDetector

Chrome tarayıcıyı tespit etme ve versiyonunu alma

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.greasyfork.org/scripts/582434/1849851/ChromeDetector.js

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         ChromeDetector
// @namespace    http://tampermonkey.net/
// @version      1
// @description  Chrome tarayıcıyı tespit etme ve versiyonunu alma
// @author       Atilla
// @license MIT
// ==/UserScript==

/**
 * ============================================================================
 * 🚀 ULTRA SECURE CHROME DETECTOR (POWERED BY BOWSER)
 * ============================================================================
 * 
 * En Kolay Kullanım Örnekleri:
 * 
 * 1. Tarayıcı Gerçek Google Chrome mu? (True/False):
 *    if (ChromeDetector.isChrome()) { console.log("Evet, kesinlikle Chrome!"); }
 * 
 * 2. Chrome Ana Versiyonunu Alma:
 *    const version = ChromeDetector.getMajorVersion(); // Örn: 124 veya null
 * 
 * 3. Detaylı Rapor Alma:
 *    const info = ChromeDetector.getInfo(); // { isChrome: true, majorVersion: 124 }
 * ============================================================================
 */

(function (global) {
  'use strict';

  // Bowser kütüphanesini sayfaya dinamik olarak enjekte eden yardımcı fonksiyon
  function injectBowser() {
    if (global.bowser) return;
    const script = document.createElement('script');
    script.src = 'https://cdnjs.cloudflare.com/ajax/libs/bowser/2.12.1/bundled.js';
    script.async = false; // Kodun sıralı çalışması için senkronize yükleme simülasyonu
    document.head.appendChild(script);
  }

  // Sayfa yüklenirken Bowser'ı arka planda hazırla
  if (typeof document !== 'undefined') {
    injectBowser();
  }

  class ChromeDetector {
    /**
     * Bowser parser nesnesini döndürür.
     * @private
     */
    static _getParser() {
      if (!global.bowser) {
        // Eğer Bowser henüz yüklenmediyse anlık olarak userAgent analizi için fallback yapar
        console.warn("ChromeDetector: Bowser henüz tamamen yüklenmedi, bekleniyor...");
        return null;
      }
      return global.bowser.getParser(global.navigator.userAgent);
    }

    /**
     * Kullanıcının gerçek Google Chrome kullanıp kullanmadığını doğrular.
     * Edge, Opera, Brave, Vivaldi vb. tüm yan sanayi Chromium tarayıcıları eler.
     * @returns {boolean}
     */
    static isChrome() {
      const parser = this._getParser();
      if (!parser) {
        // Bowser yüklenene kadar temel JavaScript kontrolü (Geçici Fallback)
        return navigator.vendor === 'Google Inc.' && !navigator.brave && !navigator.userAgent.includes('Edg');
      }

      // Bowser motor adının Blink (Chrome motoru) ve tarayıcı adının tam olarak Chrome olduğunu doğrular
      const browserName = parser.getBrowserName(); // "Chrome"
      const engineName = parser.getEngineName();   // "Blink"

      return browserName === 'Chrome' && engineName === 'Blink';
    }

    /**
     * Chrome'un Major (Ana) sürüm numarasını sayı (number) olarak döndürür.
     * Tarayıcı Chrome değilse null döner.
     * @returns {number|null} Örn: 124 veya null
     */
    static getMajorVersion() {
      if (!this.isChrome()) return null;

      const parser = this._getParser();
      if (!parser) {
        const match = global.navigator.userAgent.match(/(?:Chrome|CriOS)\/([0-9]+)/);
        return match ? parseInt(match[1], 10) : null;
      }

      const versionStr = parser.getBrowserVersion(); // Örn: "124.0.6367.61"
      if (!versionStr) return null;

      return parseInt(versionStr.split('.')[0], 10);
    }

    /**
     * Tüm bilgileri tek bir pratik nesne (object) içinde döndürür.
     * @returns {Object} { isChrome: boolean, majorVersion: number|null }
     */
    static getInfo() {
      return {
        isChrome: this.isChrome(),
        majorVersion: this.getMajorVersion()
      };
    }
  }

  // Global window nesnesine bağlama (Evrensel kütüphane desteği)
  if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
    module.exports = ChromeDetector;
  } else {
    global.ChromeDetector = ChromeDetector;
  }

})(typeof window !== 'undefined' ? window : this);