Last active
July 16, 2026 19:10
-
-
Save Ap0dexMe0/e325a54d779ab9a265c0c72abeb087ec to your computer and use it in GitHub Desktop.
Tampermonkey script to bypass Rate limiting requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Auto Proxy with ProxyScrape (Multi-Protocol) | |
| // @namespace http://tampermonkey.net/ | |
| // @version 3.3 | |
| // @description Fetches proxies from ProxyScrape, tests HTTP/HTTPS/SOCKS4/SOCKS5, uses first one that masks your IP. (Unlimited proxy testing) | |
| // @author YourName | |
| // @match *://*/* | |
| // @grant GM_xmlhttpRequest | |
| // @grant unsafeWindow | |
| // @run-at document-start | |
| // @connect api.proxyscrape.com | |
| // @connect httpbin.org | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| // ========== CONFIGURATION ========== | |
| // Choose the proxy protocol you want to use: | |
| // 'http', 'https', 'socks4', 'socks5' | |
| const PROXY_PROTOCOL = 'http'; | |
| // ProxyScrape API URL - simplified as requested | |
| const PROXY_API_URL = 'https://api.proxyscrape.com/v2/?request=displayproxies&protocol=' + PROXY_PROTOCOL; | |
| const IP_CHECK_URL = 'https://httpbin.org/ip'; | |
| const PROXY_TIMEOUT = 5000; | |
| // Optional: restrict which URLs go through the proxy (regex) | |
| const URL_PATTERN = /.*/; | |
| // =================================== | |
| let activeProxy = null; | |
| function shouldProxy(url) { | |
| return URL_PATTERN.test(url); | |
| } | |
| // ----- Fetch proxy list from API ----- | |
| function fetchProxyList() { | |
| return new Promise((resolve, reject) => { | |
| GM_xmlhttpRequest({ | |
| method: 'GET', | |
| url: PROXY_API_URL, | |
| onload: function(resp) { | |
| try { | |
| const raw = resp.responseText.trim(); | |
| const entries = raw.split(/\s+/).filter(s => s.includes(':')); | |
| resolve(entries); | |
| } catch (e) { | |
| reject(e); | |
| } | |
| }, | |
| onerror: function(err) { reject(err); }, | |
| ontimeout: function() { reject(new Error('Proxy list fetch timed out')); } | |
| }); | |
| }); | |
| } | |
| // ----- Get real IP (without proxy) ----- | |
| function getRealIP() { | |
| return new Promise((resolve) => { | |
| GM_xmlhttpRequest({ | |
| method: 'GET', | |
| url: IP_CHECK_URL, | |
| timeout: PROXY_TIMEOUT, | |
| onload: function(resp) { | |
| try { | |
| const data = JSON.parse(resp.responseText); | |
| resolve(data.origin); | |
| } catch (e) { | |
| resolve(null); | |
| } | |
| }, | |
| onerror: function() { resolve(null); }, | |
| ontimeout: function() { resolve(null); } | |
| }); | |
| }); | |
| } | |
| // ----- Get IP through a given proxy ----- | |
| function getProxyIP(proxy) { | |
| return new Promise((resolve) => { | |
| GM_xmlhttpRequest({ | |
| method: 'GET', | |
| url: IP_CHECK_URL, | |
| proxy: proxy, | |
| timeout: PROXY_TIMEOUT, | |
| onload: function(resp) { | |
| try { | |
| const data = JSON.parse(resp.responseText); | |
| resolve(data.origin); | |
| } catch (e) { | |
| resolve(null); | |
| } | |
| }, | |
| onerror: function() { resolve(null); }, | |
| ontimeout: function() { resolve(null); } | |
| }); | |
| }); | |
| } | |
| // ----- Test a single proxy by comparing IPs ----- | |
| async function testProxy(proxy, realIP) { | |
| const proxyIP = await getProxyIP(proxy); | |
| if (proxyIP && proxyIP !== realIP) { | |
| console.log('[OK] Proxy ' + proxy + ' works - IP changed to ' + proxyIP); | |
| return { working: true, proxy, ip: proxyIP }; | |
| } else if (proxyIP === realIP) { | |
| console.log('[WARN] Proxy ' + proxy + ' is transparent - IP unchanged (' + proxyIP + ')'); | |
| } else { | |
| console.log('[FAIL] Proxy ' + proxy + ' failed or timed out.'); | |
| } | |
| return { working: false }; | |
| } | |
| // ----- Find a working proxy that changes your IP (tests ALL proxies until one works) ----- | |
| async function findWorkingProxy(proxyList, realIP) { | |
| // Shuffle to avoid bias (all proxies will be tested) | |
| const shuffled = proxyList.sort(() => Math.random() - 0.5); | |
| console.log('Testing all ' + shuffled.length + ' proxies for IP change...'); | |
| let tested = 0; | |
| for (const entry of shuffled) { | |
| const proxy = PROXY_PROTOCOL + '://' + entry; | |
| const result = await testProxy(proxy, realIP); | |
| tested++; | |
| if (result.working) { | |
| console.log('Found working proxy after testing ' + tested + ' proxies.'); | |
| return result.proxy; | |
| } | |
| // Log progress every 10 proxies | |
| if (tested % 10 === 0) { | |
| console.log('Tested ' + tested + '/' + shuffled.length + ' proxies so far...'); | |
| } | |
| } | |
| console.warn('No working proxy found after testing all ' + shuffled.length + ' proxies.'); | |
| return null; | |
| } | |
| // ----- Override fetch and XHR once we have a proxy ----- | |
| function applyProxyOverrides(proxy) { | |
| if (!proxy) return; | |
| // Override fetch | |
| const originalFetch = window.fetch; | |
| window.fetch = function(input, init) { | |
| const url = typeof input === 'string' ? input : input.url; | |
| if (!shouldProxy(url)) { | |
| return originalFetch.call(this, input, init); | |
| } | |
| return new Promise((resolve, reject) => { | |
| GM_xmlhttpRequest({ | |
| method: init?.method || 'GET', | |
| url: url, | |
| headers: init?.headers || {}, | |
| data: init?.body, | |
| proxy: proxy, | |
| onload: function(resp) { | |
| const responseInit = { | |
| status: resp.status, | |
| statusText: resp.statusText, | |
| headers: new Headers(resp.responseHeaders) | |
| }; | |
| const blob = new Blob([resp.responseText], { | |
| type: resp.responseHeaders?.['content-type'] || 'text/plain' | |
| }); | |
| resolve(new Response(blob, responseInit)); | |
| }, | |
| onerror: function(err) { reject(err); }, | |
| ontimeout: function() { reject(new Error('Proxy request timed out')); } | |
| }); | |
| }); | |
| }; | |
| // Override XMLHttpRequest | |
| const OriginalXHR = window.XMLHttpRequest; | |
| class ProxyXMLHttpRequest extends EventTarget { | |
| constructor() { | |
| super(); | |
| this.readyState = 0; | |
| this.status = 0; | |
| this.statusText = ''; | |
| this.response = null; | |
| this.responseText = ''; | |
| this.responseType = ''; | |
| this.responseURL = ''; | |
| this.timeout = 0; | |
| this.withCredentials = false; | |
| this.upload = new EventTarget(); | |
| this._method = 'GET'; | |
| this._url = ''; | |
| this._async = true; | |
| this._user = null; | |
| this._password = null; | |
| this._headers = {}; | |
| this._body = null; | |
| this._aborted = false; | |
| } | |
| open(method, url, async = true, user = null, password = null) { | |
| this._method = method; | |
| this._url = url; | |
| this._async = async; | |
| this._user = user; | |
| this._password = password; | |
| this.readyState = 1; | |
| this.dispatchEvent(new Event('readystatechange')); | |
| } | |
| setRequestHeader(header, value) { | |
| this._headers[header] = value; | |
| } | |
| send(body) { | |
| if (this._aborted) return; | |
| this.readyState = 2; | |
| this.dispatchEvent(new Event('readystatechange')); | |
| const url = this._url; | |
| if (!shouldProxy(url)) { | |
| const xhr = new OriginalXHR(); | |
| xhr.open(this._method, url, this._async, this._user, this._password); | |
| for (const h in this._headers) { | |
| xhr.setRequestHeader(h, this._headers[h]); | |
| } | |
| xhr.onreadystatechange = () => { | |
| this.readyState = xhr.readyState; | |
| this.status = xhr.status; | |
| this.statusText = xhr.statusText; | |
| this.response = xhr.response; | |
| this.responseText = xhr.responseText; | |
| this.responseURL = xhr.responseURL; | |
| this.dispatchEvent(new Event('readystatechange')); | |
| if (xhr.readyState === 4) { | |
| this.dispatchEvent(new Event('load')); | |
| this.dispatchEvent(new Event('loadend')); | |
| } | |
| }; | |
| xhr.send(body); | |
| return; | |
| } | |
| const options = { | |
| method: this._method, | |
| url: url, | |
| headers: this._headers, | |
| data: body, | |
| proxy: proxy, | |
| onload: (resp) => { | |
| if (this._aborted) return; | |
| this.status = resp.status; | |
| this.statusText = resp.statusText; | |
| this.responseText = resp.responseText; | |
| this.response = resp.responseText; | |
| this.responseURL = url; | |
| this.readyState = 4; | |
| this.dispatchEvent(new Event('readystatechange')); | |
| this.dispatchEvent(new Event('load')); | |
| this.dispatchEvent(new Event('loadend')); | |
| }, | |
| onerror: (err) => { | |
| if (this._aborted) return; | |
| this.dispatchEvent(new Event('error')); | |
| this.dispatchEvent(new Event('loadend')); | |
| }, | |
| ontimeout: () => { | |
| if (this._aborted) return; | |
| this.dispatchEvent(new Event('timeout')); | |
| this.dispatchEvent(new Event('loadend')); | |
| } | |
| }; | |
| if (this.timeout > 0) options.timeout = this.timeout; | |
| GM_xmlhttpRequest(options); | |
| } | |
| abort() { | |
| this._aborted = true; | |
| this.dispatchEvent(new Event('abort')); | |
| } | |
| } | |
| window.XMLHttpRequest = ProxyXMLHttpRequest; | |
| console.log('Proxy active - using ' + proxy); | |
| } | |
| // ----- Main: get real IP, find working proxy (unlimited testing), apply overrides ----- | |
| (async function init() { | |
| try { | |
| // 1. Get real IP first | |
| console.log('Fetching your real IP...'); | |
| const realIP = await getRealIP(); | |
| if (!realIP) { | |
| console.warn('Could not determine your real IP. Using direct connection.'); | |
| return; | |
| } | |
| console.log('Your real IP: ' + realIP); | |
| // 2. Fetch proxy list | |
| console.log('Fetching proxy list from ProxyScrape (protocol: ' + PROXY_PROTOCOL + ')...'); | |
| let proxyList; | |
| try { | |
| proxyList = await fetchProxyList(); | |
| } catch (e) { | |
| console.error('Failed to fetch proxy list:', e); | |
| return; | |
| } | |
| if (!proxyList || proxyList.length === 0) { | |
| console.error('No proxies returned from API.'); | |
| return; | |
| } | |
| console.log('Received ' + proxyList.length + ' proxies.'); | |
| // 3. Find a proxy that changes your IP (tests ALL proxies until success) | |
| const workingProxy = await findWorkingProxy(proxyList, realIP); | |
| if (workingProxy) { | |
| activeProxy = workingProxy; | |
| applyProxyOverrides(activeProxy); | |
| } else { | |
| console.warn('No working proxy found after testing all proxies. Falling back to direct connection.'); | |
| } | |
| } catch (e) { | |
| console.error('Error initializing proxy:', e); | |
| } | |
| })(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment