Skip to content

Commit

Permalink
refactor(js): improve code formatting and structure
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianjnuwu committed Dec 29, 2024
1 parent f0297b9 commit e72f0b1
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 184 deletions.
27 changes: 13 additions & 14 deletions www/src/js/cookie/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ let cookies = 0;
let $cps = 0;

const $update_cps = () => {
$('#cps').text($cps);
$cps = 0;
$("#cps").text($cps);
$cps = 0;
};

const $update_cookies = () => {
cookies++;
cookies++;
$cps++;
$('#click-cookie').text(`${cookies}`);
localStorage.setItem('cookie', cookies);
$("#click-cookie").text(`${cookies}`);
localStorage.setItem("cookie", cookies);
};

setInterval($update_cps, 1000);

$('.cookie').on('click', function (e) {

$(".cookie").on("click", function (e) {
$update_cookies();

const $effect = $(`<div class="click-effect">+1</div>`);
Expand All @@ -26,21 +25,21 @@ $('.cookie').on('click', function (e) {
const Y = e.pageY - offset.top;

$effect.css({
left: X + 'px',
top: Y + 'px',
position: 'absolute',
left: X + "px",
top: Y + "px",
position: "absolute",
});

$(this).append($effect);

$effect
.animate(
{
top: '-=2.5rem',
top: "-=2.5rem",
opacity: 1,
fontSize: '1.5rem',
fontSize: "1.5rem",
},
300
300,
)
.animate(
{
Expand All @@ -49,6 +48,6 @@ $('.cookie').on('click', function (e) {
200,
function () {
$(this).remove();
}
},
);
});
10 changes: 4 additions & 6 deletions www/src/js/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
$(() => {

$("splash-screen").on("click", () => {
$("#splash")[0].volume = 0.1;
$("#splash")[0].play();
Expand All @@ -8,12 +7,11 @@ $(() => {
$("start-screen").show();
}, 1000);
});
$("start-screen button").on("click", () => $("#click")[0].play());

$("start-screen button").on("click", () => $("#click")[0].play());

$("#play").on("click", () => {
$("start-screen").remove();
$("ui").show();
});

});
});
130 changes: 64 additions & 66 deletions www/src/plugins/admob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,72 @@ import {
} from "@capacitor-community/admob";
import $ from "jquery";

function $show_banner() {
AdMob.showBanner({
adId: "ca-app-pub-6690516270288705/1043067086",
adSize: BannerAdSize.FULL_BANNER,
position: BannerAdPosition.BOTTOM_CENTER,
margin: 0,
// isTesting: true
// npa: true
})
.then(() => {
return console.log("Banner displayed.");
})
.catch((err) => {
return console.log("Error displaying banner: ", err.message);
});
}

function $hide_banner() {
AdMob.hideBanner()
.then(() => {
return console.log("Banner hidden successfully.");
})
.catch((err) => {
return console.log("Error hiding banner: ", err.message);
});
}

function $show_video() {
const adId = "ca-app-pub-6690516270288705/7898187843";
AdMob.prepareRewardVideoAd({ adId })
.then(() => {
console.log("Rewarded interstitial prepared.");
return AdMob.showRewardVideoAd();
})
.then(() => {
console.log("Rewarded interstitial displayed successfully.");
})
.catch((err) => {
console.log("Error displaying rewarded interstitial: ", err.message);
});
}

function $award() {
AdMob.prepareInterstitial({
adId: "ca-app-pub-6690516270288705/8937605645",
})
.then(() => {
console.log("Interstitial prepared.");

return AdMob.showInterstitial();
})
.then(() => {
console.log("Interstitial ad displayed successfully.");
})
.catch((err) => {
console.log("Error displaying interstitial ad: ", err.message);
});
}

$(() => {
if (window.Capacitor.getPlatform() !== "android") {
/* if (window.Capacitor.getPlatform() !== "android") {
console.log(
`AdMob: Unsupported platform (${window.Capacitor.getPlatform()})`,
);
return;
}
}*/

AdMob.initialize()
.then(() => {
Expand All @@ -21,70 +80,9 @@ $(() => {
console.log("Error initializing AdMob: ", err.message);
});

function $show_banner() {
AdMob.showBanner({
adId: "ca-app-pub-6690516270288705/1043067086",
adSize: BannerAdSize.FULL_BANNER,
position: BannerAdPosition.BOTTOM_CENTER,
margin: 0,
// isTesting: true
// npa: true
})
.then(() => {
return console.log("Banner displayed.");
})
.catch((err) => {
return console.log("Error displaying banner: ", err.message);
});
}

function $hide_banner() {
AdMob.hideBanner()
.then(() => {
return console.log("Banner hidden successfully.");
})
.catch((err) => {
return console.log("Error hiding banner: ", err.message);
});
}

function $show_video() {
const adId = "ca-app-pub-6690516270288705/7898187843";
AdMob.prepareRewardVideoAd({ adId })
.then(() => {
console.log("Rewarded interstitial prepared.");
return AdMob.showRewardVideoAd();
})
.then(() => {
console.log("Rewarded interstitial displayed successfully.");
})
.catch((err) => {
console.log("Error displaying rewarded interstitial: ", err.message);
});
}

function $award() {
AdMob.prepareInterstitial({
adId: "ca-app-pub-6690516270288705/8937605645",
})
.then(() => {
console.log("Interstitial prepared.");

return AdMob.showInterstitial();
})
.then(() => {
console.log("Interstitial ad displayed successfully.");
})
.catch((err) => {
console.log("Error displaying interstitial ad: ", err.message);
});
}

$("#show_banner").on("click", () => {
return $show_banner();
});
$("#show_video").on("click", () => {
return $show_video();
$("#play").on("click", () => {
$show_video();
$show_banner();
});

$("#hide_banner").on("click", () => {
Expand Down
Loading

0 comments on commit e72f0b1

Please sign in to comment.