Index: static/js/index.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/static/js/index.js |
@@ -0,0 +1,57 @@ |
+"use strict"; |
+ |
+(function() |
+{ |
+ var supportedPlatforms = { |
+ |
+ // Desktop browsers |
+ "chrome": "https://chrome.google.com/webstore/detail/cfhdojbkjhnklbpkdaibdccddilifddb", |
+ "opera": "https://addons.opera.com/extensions/details/opera-adblock/?display=en-US", |
+ "yandexbrowser": "https://chrome.google.com/webstore/detail/cfhdojbkjhnklbpkdaibdccddilifddb", |
+ "msie": "https://update.adblockplus.org/latest/adblockplusie.exe", |
+ "msedge": "https://www.microsoft.com/store/p/adblock-plus/9nblggh4r9nz", |
+ "firefox": "https://update.adblockplus.org/latest/adblockplusfirefox.xpi", |
+ "safari": "https://update.adblockplus.org/latest/adblockplussafari.safariextz", |
+ "maxthon": "", |
+ |
+ // Mobile platforms |
+ "ios": "https://eyeo.to/adblockbrowser/ios/abp-website", |
+ "android": "https://eyeo.to/adblockbrowser/android/abp-website" |
+ }; |
+ |
+ function setupHeroDownloadButton() |
+ { |
+ var detectedPlatform = Object.keys(supportedPlatforms) |
+ .find(bowser.hasOwnProperty.bind(bowser)); |
+ |
+ if (!detectedPlatform) return; |
+ |
+ document.body.classList.add(detectedPlatform); |
+ |
+ if (detectedPlatform == "maxthon") return; |
+ |
+ var heroDownloadButton = document.getElementById("hero-download-button"); |
+ heroDownloadButton.href = supportedPlatforms[detectedPlatform]; |
+ heroDownloadButton.innerHTML = document |
juliandoucette
2018/04/16 15:44:41
NIT/Suggest: innerText (we don't support IE 8 anym
ire
2018/04/16 16:00:59
Changed to textContent which seems to be better fo
juliandoucette
2018/04/16 16:12:58
Thanks!
(Facepalm: I meant to say textContent. My
|
+ .getElementById("hero-download-button-template-" + detectedPlatform) |
+ .innerHTML; |
+ |
+ heroDownloadButton.addEventListener("click", function(event) |
+ { |
+ if (typeof chrome == "undefined") return; |
+ event.preventDefault(); |
+ |
+ try |
juliandoucette
2018/04/16 15:44:41
TOL: Why are curly braces required for try/catch s
ire
2018/04/16 16:00:59
I know right?!?! Maybe there's a good reason I don
|
+ { |
+ chrome.webstore.install(); |
+ } |
+ catch(error) |
+ { |
+ window.location = "/" + this.hreflang + "/download"; |
+ } |
+ }); |
+ } |
+ |
+ if (typeof bowser != "undefined") setupHeroDownloadButton(); |
+ |
+}()); |