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