| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 "use strict"; | 1 "use strict"; |
|
juliandoucette
2018/04/04 10:18:23
Why is this necessary?
ire
2018/04/05 14:32:43
I originally added it because it was in the main.j
juliandoucette
2018/04/06 12:35:22
Ack.
I don't really think it's necessary. Therefo
ire
2018/04/06 13:21:48
Acknowledged.
| |
| 2 | 2 |
| 3 (function() | 3 (function() |
| 4 { | 4 { |
| 5 var supportedPlatforms = { | 5 var supportedPlatforms = { |
| 6 | |
| 6 // Desktop browsers | 7 // Desktop browsers |
|
juliandoucette
2018/04/04 10:18:23
NIT: Please put one blank line above to make this
ire
2018/04/05 14:32:44
Done.
| |
| 7 "chrome": { | 8 "chrome": "https://chrome.google.com/webstore/detail/cfhdojbkjhnklbpkdaibdcc ddilifddb", |
| 8 installer: "https://chrome.google.com/webstore/detail/cfhdojbkjhnklbpkdaib dccddilifddb", | 9 "opera": "https://addons.opera.com/extensions/details/opera-adblock/?display =en-US", |
| 9 label: "Chrome" | 10 "yandexbrowser": "https://chrome.google.com/webstore/detail/cfhdojbkjhnklbpk daibdccddilifddb", |
| 10 }, | 11 "msie": "https://update.adblockplus.org/latest/adblockplusie.exe", |
| 11 "opera": { | 12 "msedge": "https://www.microsoft.com/store/p/adblock-plus/9nblggh4r9nz", |
| 12 installer: "https://addons.opera.com/extensions/details/opera-adblock/?dis play=en-US", | 13 "firefox": "https://update.adblockplus.org/latest/adblockplusfirefox.xpi", |
| 13 label: "Opera" | 14 "safari": "https://update.adblockplus.org/latest/adblockplussafari.safariext z", |
| 14 }, | |
| 15 "yandexbrowser": { | |
| 16 installer: "https://chrome.google.com/webstore/detail/cfhdojbkjhnklbpkdaib dccddilifddb", | |
| 17 label: "Yandex Browser" | |
| 18 }, | |
| 19 "msie": { | |
| 20 installer: "https://update.adblockplus.org/latest/adblockplusie.exe", | |
| 21 label: "Internet Explorer" | |
| 22 }, | |
| 23 "msedge": { | |
| 24 installer: "https://www.microsoft.com/store/p/adblock-plus/9nblggh4r9nz", | |
| 25 label: "Micrsoft Edge" | |
| 26 }, | |
| 27 "firefox": { | |
| 28 installer: "https://update.adblockplus.org/latest/adblockplusfirefox.xpi", | |
| 29 label: "Firefox" | |
| 30 }, | |
| 31 "safari": { | |
| 32 installer: "https://update.adblockplus.org/latest/adblockplussafari.safari extz", | |
| 33 label: "Safari" | |
| 34 }, | |
| 35 "maxthon": "", | 15 "maxthon": "", |
| 36 | 16 |
| 37 // Mobile platforms | 17 // Mobile platforms |
| 38 "ios": { | 18 "ios": "https://eyeo.to/adblockbrowser/ios/abp-website", |
| 39 installer: "https://eyeo.to/adblockbrowser/ios/abp-website", | 19 "android": "https://eyeo.to/adblockbrowser/android/abp-website" |
| 40 label: "iOS", | |
| 41 }, | |
| 42 "android": { | |
| 43 installer: "https://eyeo.to/adblockbrowser/android/abp-website", | |
| 44 label: "Android" | |
| 45 } | |
| 46 }; | 20 }; |
| 47 | 21 |
| 48 function setupHeroDownloadButton() | 22 function setupHeroDownloadButton() |
| 49 { | 23 { |
| 50 var heroDownloadButton = document.getElementById("hero-download-button"); | 24 var detectedPlatform = Object.keys(supportedPlatforms) |
| 51 var detectedPlatform; | 25 .find(bowser.hasOwnProperty.bind(bowser)); |
| 52 | |
| 53 for (var key in supportedPlatforms) if (bowser[key]) detectedPlatform = key; | |
|
juliandoucette
2018/04/04 10:18:23
NITs
- It took me a minute to figure out what you
ire
2018/04/05 14:32:43
I'll go with your implementation.
Done.
| |
| 54 | 26 |
| 55 if (!detectedPlatform) return; | 27 if (!detectedPlatform) return; |
| 56 | 28 |
| 57 document.body.classList.add(detectedPlatform); | 29 document.body.classList.add(detectedPlatform); |
| 58 | 30 |
| 59 if (detectedPlatform === "maxthon") return; | 31 if (detectedPlatform == "maxthon") return; |
| 60 | 32 |
| 61 heroDownloadButton.href = supportedPlatforms[detectedPlatform].installer; | 33 var heroDownloadButton = document.getElementById("hero-download-button"); |
| 34 heroDownloadButton.href = supportedPlatforms[detectedPlatform]; | |
| 62 heroDownloadButton.textContent = document | 35 heroDownloadButton.textContent = document |
| 63 .getElementById("hero-download-button-template") | 36 .getElementById("download-label-" + detectedPlatform) |
| 64 .innerHTML | 37 .textContent; |
| 65 .replace("browser", supportedPlatforms[detectedPlatform].label); | |
|
juliandoucette
2018/04/04 10:18:23
"browser" is not fixed in the include. Therefore,
juliandoucette
2018/04/04 10:18:23
I think the browser name itself is translated in s
ire
2018/04/05 14:32:43
Done.
ire
2018/04/05 14:32:43
Done.
| |
| 66 | 38 |
| 67 heroDownloadButton.addEventListener("click", function(event) | 39 heroDownloadButton.addEventListener("click", function(event) |
|
juliandoucette
2018/04/04 10:18:23
I think chrome.webstore.install works on other chr
ire
2018/04/05 14:32:43
You're right. I switch to checking for the "chrome
| |
| 68 { | 40 { |
| 69 if (detectedPlatform !== "chrome") return; | 41 if (typeof chrome == "undefined") return; |
| 70 event.preventDefault(); | 42 event.preventDefault(); |
| 71 chrome.webstore.install(); | 43 |
| 44 try | |
| 45 { | |
| 46 chrome.webstore.install(); | |
| 47 } | |
| 48 catch(error) | |
| 49 { | |
| 50 window.location = "/" + this.hreflang + "/download"; | |
| 51 } | |
| 72 }); | 52 }); |
| 73 } | 53 } |
| 74 | 54 |
| 75 if (bowser) setupHeroDownloadButton(); | 55 if (typeof bowser != "undefined") setupHeroDownloadButton(); |
| 76 | 56 |
| 77 }()); | 57 }()); |
| LEFT | RIGHT |