Ome.tv IP Geolocation

Ome.tv IP Geolocation By RannStudio

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Ome.tv IP Geolocation
// @license      MIT License
// @namespace    https://github.com/Rann-Studio/Ome.tv-IP-geolocation
// @version      0.2
// @description  Ome.tv IP Geolocation By RannStudio
// @author       RannStudio
// @match        https://ome.tv/
// @icon         https://www.google.com/s2/favicons?domain=ome.tv
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your API Key for ipinfo.io
    var apiKey = "your-api-key";  // <-- Replace this with your real API key

    var regionNames = new Intl.DisplayNames(['en'], {type: 'region'});

    var addMessage = async (msg) => {
        var putData = document.getElementsByClassName("message-bubble")[0].firstChild;
        var div = document.createElement("div");
        div.setAttribute("class", "logitem");
        var p = document.createElement("p");
        p.setAttribute("class", "statuslog");
        p.innerText = msg;
        div.appendChild(p);
        putData.appendChild(div);
    };

    window.oRTCPeerConnection = window.oRTCPeerConnection || window.RTCPeerConnection;

    window.RTCPeerConnection = function (...args) {
        const pc = new window.oRTCPeerConnection(...args);

        pc.oaddIceCandidate = pc.addIceCandidate;

        pc.addIceCandidate = function (iceCandidate, ...rest) {
            const fields = iceCandidate.candidate.split(" ");

            console.log(iceCandidate.candidate); // Logs the full ICE candidate string
            const ip = fields[4];  // The IP address is generally at position 4

            // Check if this is a STUN candidate (srflx), meaning a public IP is detected
            if (fields[7] === "srflx") {
                getLocation(ip); // Get geolocation info for the detected IP
            }

            return pc.oaddIceCandidate(iceCandidate, ...rest);
        };
        return pc;
    };

    var getLocation = async (ip) => {
        let url = `https://ipinfo.io/${ip}?token=${apiKey}`;
        await fetch(url).then((response) =>
            response.json().then((json) => {
                const output = `
--------------------------
IP        : ${json.ip}
Country   : ${regionNames.of(json.country)}
State     : ${json.city}
City      : ${json.region}
Lat / Long: ${json.loc}
--------------------------
`;
                addMessage(output);  // Display the IP information in the Ome.tv chat box
            })
        );
    };
})();