Last active
July 21, 2016 21:49
-
-
Save hogmoru/4023f007cbd7438d998c14a602199b11 to your computer and use it in GitHub Desktop.
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
/* | |
* Experiment for Syncthing's beta download page: | |
* Highlight download links for local platform, and move them to the top. | |
* | |
* Coding convention: variables beginning with $ are jquery selections | |
*/ | |
var css = document.createElement("style"); | |
css.type = "text/css"; | |
css.innerHTML = "a.dl-suggestion { font-weight: bold; color: #29b74e; }"; | |
document.body.appendChild(css); | |
function getPlatform() { | |
/* Very simplistic, this is just a proof of concept. | |
* It's relatively easy to detect common platforms, but harder (or impossible) | |
* to detect 32-bit or 64-bit OS... */ | |
if (window.navigator.platform === 'MacIntel') return 'macosx'; | |
if (window.navigator.platform === 'Win32') return 'windows'; | |
if (window.navigator.platform.indexOf('Linux')>=0) return 'linux'; | |
} | |
var platform = getPlatform(); | |
// Find the UL that holds the list of versions. Could you give this UL an id to make this easier & safer? | |
var $versionsUL = $('body > div > h3').next('ul').first(); | |
// Get the links that are relevant to local platform | |
var $links = $versionsUL.find('a').filter(function() { return $(this).attr('href').indexOf('-'+platform+'-')>=0; }); | |
// Add class and move those <li> to the top of the <ul> | |
$links.addClass('dl-suggestion'); | |
$links.parent().each(function() { $(this).parent().prepend(this); }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment