Commit f1868242 authored by sajolida's avatar sajolida

Alternate automatically between our different bitcoin addresses (#12268)

The 'data-weight' attribute of the elements of the 'bitcoin-address'
class determine the probability of them being displayed.
parent 739746f1
......@@ -342,11 +342,17 @@ permitted by law.</strong></p>
<div class="col-md-5">
<div id="bitcoin">
<h4>Bitcoin</h4>
<div id="tails-bitcoind" class="bitcoin-address">
<!--
The bitcoin addresses below ('bitcoin-address' class) are displayed
randomly according to their weight ('data-weight' attribute):
- Addresses with 'data-weight="0"' are never displayed.
- There is no maximum weight.
-->
<div id="tails-bitcoind" class="bitcoin-address" data-weight="1">
<p><a href="bitcoin:1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2">[[!img bitcoin-1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2.png link="no"]]</a></p>
<p><strong>1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2</strong></p>
</div>
<div id="riseuplab-coinbase" class="bitcoin-address">
<div id="riseuplab-coinbase" class="bitcoin-address" data-weight="0">
<p><a href="bitcoin:3QirvVRntoascPfTgNTUQvKxfKwPah5FNK">[[!img bitcoin-3QirvVRntoascPfTgNTUQvKxfKwPah5FNK.png link="no"]]</a></p>
<p><strong>3QirvVRntoascPfTgNTUQvKxfKwPah5FNK</strong></p>
</div>
......
......@@ -89,4 +89,26 @@ document.addEventListener('DOMContentLoaded', function() {
document.getElementById('amount').value = newvalue;
});
}
// Alternate between our different bitcoin addresses
var bitcoinAddresses = document.getElementsByClassName('bitcoin-address'),
current_top_weight = 0,
picked_value,
ranges_end = [];
for (let i = 0; i < bitcoinAddresses.length; i++) {
hide(bitcoinAddresses[i]);
ranges_end[i]
= current_top_weight
= current_top_weight + parseInt(bitcoinAddresses[i].dataset.weight);
}
picked_value = Math.floor(Math.random() * current_top_weight);
for (let i = 0; i <= bitcoinAddresses.length; i++) {
if (picked_value < ranges_end[i]) {
show(bitcoinAddresses[i]);
break;
}
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment