Skip to content

Instantly share code, notes, and snippets.

@koenbok
Created January 12, 2022 14:27
Show Gist options
  • Save koenbok/dcd3875a1fb17c7a06e297ddc392191d to your computer and use it in GitHub Desktop.
Save koenbok/dcd3875a1fb17c7a06e297ddc392191d to your computer and use it in GitHub Desktop.
<script>
function onPathChange(callback) {
let path;
// Only reliable way seems polling across browsers :-(
setInterval(() => {
if (window.location.pathname !== path) {
path = window.location.pathname;
callback(path);
}
}, 1000);
}
function download(url) {
console.log("download", url);
setTimeout(() => {
document.location.href = url;
}, 1500);
}
onPathChange((path) => {
if (path === "/download-macos") {
download("https://api.detail.co/v1/macOS/latest");
}
if (path === "/download-ios") {
download(
"https://apps.apple.com/nl/app/detail-camera-webcam-for-mac/id1563218359?l=en"
);
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment