Last active
December 20, 2015 22:19
-
-
Save pushandplay/6203883 to your computer and use it in GitHub Desktop.
Add "Rate my app" functionality to PhoneGap application
This file contains 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
rateApp = -> | |
# Use iTunes link maker http://itunes.apple.com/linkmaker/ to get the real direct link | |
rate_app_counter = parseInt window.localStorage.getItem("rate_app_counter") or 0 | |
rate_app = parseInt window.localStorage.getItem("rate_app") or 1 | |
rate_count_max = 3 | |
app_id_ios = "123456789" | |
app_id_android = "com.company.YourAppID" | |
app_id_blackberry = "123456789" | |
rate = (buttonIndex) -> | |
# yes = 1, no = 2, later = 3 | |
switch buttonIndex | |
when 1 | |
window.localStorage.setItem "rate_app", 0 | |
window.localStorage.setItem "rate_app_counter", rate_count_max | |
if /(iPhone|iPod|iPad)/i.test navigator.userAgent.toLowerCase() | |
window.open "itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=#{app_id_ios}" | |
else if /(Android)/i.test navigator.userAgent.toLowerCase() | |
window.open "market://details?id=#{app_id_android}" | |
else if /(BlackBerry)/i.test navigator.userAgent.toLowerCase() | |
window.open "http://appworld.blackberry.com/webstore/content/#{app_id_blackberry}" | |
when 2 | |
window.localStorage.setItem "rate_app_counter", 0 | |
when 3 | |
window.localStorage.setItem "rate_app", 0 | |
window.localStorage.setItem "rate_app_counter", rate_count_max | |
if navigator.notification | |
if rate_app_counter is rate_count_max and rate_app isnt 0 | |
navigator.notification.confirm "Нам очень важно знать ваше мнение, пожалуйста оцените приложение. Это займет всего пару минут. \nСпасибо!", rate, "Оцените приложение", | |
["Оценить сейчас", "Напомнить позже", "Нет спасибо"] | |
else if rate_app_counter < rate_count_max | |
rate_app_counter++ | |
window.localStorage.setItem "rate_app_counter", rate_app_counter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment