Skip to content

Instantly share code, notes, and snippets.

@HoseanRC
Created September 11, 2025 20:10
Show Gist options
  • Select an option

  • Save HoseanRC/847247f79c3cc724d870c94a7c64f8c8 to your computer and use it in GitHub Desktop.

Select an option

Save HoseanRC/847247f79c3cc724d870c94a7c64f8c8 to your computer and use it in GitHub Desktop.
CafeBazzar apk download button

this is a simple script to replace the "Download" button with "Download APK" button.

installation

  1. install a user script manager

    • for Desktop:
    Browser Installation
    Chrome Tampermonkey or Violentmonkey
    Firefox Greasemonkey, Tampermonkey, or Violentmonkey
    Safari Tampermonkey or Userscripts
    Microsoft Edge Tampermonkey or Violentmonkey
    Opera Tampermonkey or Violentmonkey
    Maxthon Violentmonkey
    AdGuard (no additional software required)
    • for Android:
    Browser Installation
    Firefox Greasemonkey, Tampermonkey, or Violentmonkey
    Microsoft Edge Tampermonkey
    Maxthon Violentmonkey
    Dolphin Tampermonkey
    UC Tampermonkey
    XBrowser (no additional software required)
    • for iOS:
    Browser Installation
    Safari Tampermonkey or Userscripts
    Gear (no additional software required)
  2. create a new script in your user script manager

  3. copy the userscript.js code and paste it, then save the user script

  4. open cafebazzar website

// ==UserScript==
// @name CafeBazaar Direct APK Link
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Replace install button with direct APK link from CafeBazaar API
// @author You
// @match https://cafebazaar.ir/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Convert Persian digits to English
function fixNumbers(s = '') {
return s.replace(/[۰-۹]/g, (d) => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d));
}
async function getLink(pkg) {
try {
const res = await fetch('https://api.cafebazaar.ir/rest-v1/process/AppDownloadInfoRequest', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
properties: {
"clientVersionCode": 1000000000000,
androidClientInfo: {
sdkVersion: 1000,
cpu: 'x86,x86_64,armeabi-v7a,armeabi,aarch64',
},
},
singleRequest: {
appDownloadInfoRequest: {
downloadStatus: 1,
packageName: pkg,
},
},
}),
});
const data = await res.json();
const reply = data?.singleReply?.appDownloadInfoReply;
if (!reply) throw new Error('Invalid API response');
const token = reply.token;
const cdnPrefix = reply.cdnPrefix?.[0];
if (!token || !cdnPrefix) throw new Error('Missing download data');
return `${cdnPrefix}apks/${token}.apk`;
} catch (err) {
console.error('getLink error:', err.message);
return null;
}
}
function main(event) {
let oldHref = "";
const body = document.querySelector('body');
const observer = new MutationObserver(async mutations => {
if (oldHref !== document.location.href && document.location.href.startsWith("https://cafebazaar.ir/app/")) {
oldHref = document.location.href;
// Get package name from URL
const url = window.location.href;
const pkg = url.substring(url.lastIndexOf('/') + 1);
// Find the install button
const btns = document.getElementsByClassName('AppInstallBtn');
if (!btns.length) return;
Array.from(btns).forEach(btn => {
btn.style.transition = '0.5s';
});
// Fetch direct link
const link = await getLink(pkg);
if (link) {
Array.from(btns).forEach(btn => {
btn.href = link;
btn.download = pkg + ".apk";
btn.style.backgroundColor = '#0e95a9';
btn.style.borderColor = '#0e95a9';
});
setTimeout(() => {
Array.from(btns).forEach(btn => {
btn.text = "دانلود APK";
});
}, 1000);
}
}
});
observer.observe(body, { childList: true, subtree: true });
}
// Run when DOM is ready
window.navigation.addEventListener("navigate", main);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment