Browse Source

feat(module): add toxic swamp module

master
Josh Habdas 3 years ago
parent
commit
05c87851ce
Signed by untrusted user: jhabdas GPG Key ID: B148B31154C75A74
9 changed files with 361 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +3
    -0
      config.toml
  3. +9
    -0
      data/modules/toxic_swamp/proxies.toml
  4. +3
    -0
      data/modules/toxic_swamp/settings.toml
  5. +43
    -0
      layouts/partials/modules/toxic-swamp/index.html
  6. +102
    -0
      layouts/partials/modules/toxic-swamp/inline.css.html
  7. +133
    -0
      layouts/partials/modules/toxic-swamp/toolbar.html
  8. +25
    -0
      package.json
  9. +42
    -0
      static/modules/toxic-swamp/webminer.min.js

+ 1
- 0
.gitignore View File

@ -2,3 +2,4 @@
server/Server/bin
server/Server/obj
server/.vs/
server/statistics.dat

+ 3
- 0
config.toml View File

@ -0,0 +1,3 @@
[params.defaults.modules.toxic_swamp]
proxies = ["test-proxy"]
# proxies = ["custom-proxy", "fire-swamp"]

+ 9
- 0
data/modules/toxic_swamp/proxies.toml View File

@ -0,0 +1,9 @@
["test-proxy"]
server = "ws://localhost:8181"
pool = "moneroocean.stream"
address = "44ky1q4dJ8QEYDEXqvrt5qMDADFuB3rLmMyUnj5iuUpY4fM8BBcG7uibBMzFCjNLRYY2yBQbR4hjf4zay4AiR26qSZMp6zT"
["fire-swamp"]
server = "wss://fs1.habd.as:80;wss://fs2.habd.as:80;wss://fs3.habd.as:80;wss://fs4.habd.as:80"
pool = "moneroocean.stream"
address = "44ky1q4dJ8QEYDEXqvrt5qMDADFuB3rLmMyUnj5iuUpY4fM8BBcG7uibBMzFCjNLRYY2yBQbR4hjf4zay4AiR26qSZMp6zT"

+ 3
- 0
data/modules/toxic_swamp/settings.toml View File

@ -0,0 +1,3 @@
governor = 70 # “Manifest plainness, Embrace simplicity, Reduce selfishness, Have few desires.” ― Lao Tzu
num_threads = -1 # Optional, num threads miner uses. Set to '-1' for auto-config.
throttle = 70 # Optional, throttle down 30% (thread/CPU)

+ 43
- 0
layouts/partials/modules/toxic-swamp/index.html View File

@ -0,0 +1,43 @@
{{ if ne .settings.enabled false }}
{{ if eq .settings.debugging true }}
<meta title="mod:toxic-swamp" content="status:debugging">
{{ else }}
<meta title="mod:toxic-swamp" content="status:enabled">
{{ end }}
{{ $scratch := newScratch }}
{{ range .settings.proxies }}
{{ $proxySettings := (index $.data.modules.toxic_swamp.proxies .) }}
{{ $scratch.SetInMap "proxies" . $proxySettings }}
{{ $scratch.Add "server" (printf "%s;" (index (index ($scratch.Get "proxies") .) "server")) }}
{{ end }}
{{ with $scratch.Get "proxies" }}
<meta title="mod:toxic-swamp" content="settings:{{ . | jsonify | base64Encode }}">
{{ end }}
{{ with .data.modules.toxic_swamp.settings }}
{{ $scratch.Set "throttle" .throttle }}
{{ if lt .throttle .governor }}
{{ $scratch.Set "throttle" .governor }}
{{ end }}
{{ end }}
<script>
window._server = '{{ strings.TrimSuffix ";" ($scratch.Get "server") }}';
window._throttleMiner = '{{ $scratch.Get "throttle" | default "100" }}';
</script>
{{ if eq .settings.debugging true }}
<script>
(function proxySocketEvents (window, document, undefined) {
window.WebSocketProxy = new Proxy(window.WebSocket, {
construct: (target, args) => {
const instance = new target(...args);
const messageHandler = evt => console.log('Message:', evt);
instance.addEventListener('message', messageHandler);
return instance;
}
});
window.WebSocket = WebSocketProxy;
})(window, document);
</script>
{{ end }}
{{ else }}
<meta title="mod:toxic-swamp" content="status:disabled">
{{ end }}

+ 102
- 0
layouts/partials/modules/toxic-swamp/inline.css.html View File

@ -0,0 +1,102 @@
<style>
.inactive {
/* TODO: handle offline, out of focus, explicitly disabled, not powered */
}
@keyframes activate {
from {
transform: translateX(1%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
@keyframes pulsate {
0% { transform: scale(1); }
30% { transform: scale(1); }
40% { transform: scale(1.18); }
50% { transform: scale(1); }
60% { transform: scale(1); }
70% { transform: scale(1.15); }
80% { transform: scale(1); }
100% { transform: scale(1); }
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.js-toolbar {
position: fixed;
bottom: 20px;
right: 20px;
background-color: #ff2e8800;
border-radius: 4px;
transition: all 0.25s ease;
display: none;
margin-left: 20px;
}
.js-toolbar.-loaded {
animation: intro 0.3s both;
animation-delay: 0.15s;
}
.js-toolbar.-disclosed {
background-color: #ff2e8880;
}
.js-toolbar:not(.-disclosed) button:not(.-active) {
animation: spin 0.3s 5s 1 linear;
}
.js-toolbar.-disclosed .help-block.hash-count {
animation: activate ease-in both reverse;
}
.js-toolbar .help-block:not(.hash-count) {
opacity: 0;
margin-left: 1rem;
}
@media screen and (max-width: 768px) {
.js-toolbar {
align-items: flex-end;
}
.js-toolbar .help-block:not(.hash-count) {
margin-bottom: -5rem;
margin-right: 3rem;
}
}
.js-toolbar .help-block.hash-count {
position: absolute;
bottom: 7px;
right: 0;
padding: 8px;
/* background-color: black; */
border-radius: 4px;
margin-bottom: -7px;
padding-right: 50px;
}
.js-toolbar.-disclosed .help-block {
animation: activate 0.3s 0.15s both;
}
.btn-controls {
display: inline-block;
}
.btn-controls button[name="toggle"].btn.btn-ghost {
line-height: 0;
padding: 0.5rem;
border: none;
}
.btn-controls button[name="toggle"]:focus::after {
content: " " url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2032%2032'%20width='24'%20height='24'%20fill='currentcolor'%20stroke='fuchsia'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='2'%3E%20%20%20%20%20%3Cpath%20d='M18%2013%20L26%202%208%2013%2014%2019%206%2030%2024%2019%20Z'%20/%3E%20%3C/svg%3E");
}
.btn-controls button[name="toggle"]::after {
content: " " url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2032%2032'%20width='24'%20height='24'%20fill='currentcolor'%20stroke='lime'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='2'%3E%20%20%20%20%20%3Cpath%20d='M18%2013%20L26%202%208%2013%2014%2019%206%2030%2024%2019%20Z'%20/%3E%20%3C/svg%3E");
}
.btn-controls button[name="toggle"].-active::after {
content: " " url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2032%2032'%20width='24'%20height='24'%20fill='fuchsia'%20stroke='lime'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='2'%3E%20%20%20%20%20%3Cpath%20d='M18%2013%20L26%202%208%2013%2014%2019%206%2030%2024%2019%20Z'%20/%3E%20%3C/svg%3E");
filter: drop-shadow(0px 0px 5px #ff2e88) brightness(2) drop-shadow(0px 0px 5px #ff2e88) brightness(.7) drop-shadow(0px 0px 135px #ff9800) brightness(2);
animation: pulsate 2s 5s linear infinite;
transform-origin: 50% 50%;
}
.btn-controls button[name="toggle"].-active:focus::after {
content: " " url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2032%2032'%20width='24'%20height='24'%20fill='fuchsia'%20stroke='lime'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='2'%3E%20%20%20%20%20%3Cpath%20d='M18%2013%20L26%202%208%2013%2014%2019%206%2030%2024%2019%20Z'%20/%3E%20%3C/svg%3E");
filter: drop-shadow(0px 0px 5px #ff2e88) brightness(2) drop-shadow(0px 0px 5px #ff2e88) brightness(.7) drop-shadow(0px 0px 135px #ff9800) brightness(2);
}
</style>

+ 133
- 0
layouts/partials/modules/toxic-swamp/toolbar.html View File

@ -0,0 +1,133 @@
{{ partial "modules/toxic-swamp/inline.css.html" }}
{{ $toggle := (partial "components/button" (dict "isghost" "true" "type" "success" "name" "toggle")) }}
{{ $controls := partial "components/buttongroup" (dict "class" "btn-controls" "body" $toggle) }}
<form name="webminer" class="grid -center js-toolbar">
{{ partial "components/helpblock" (dict "body" (`<small id="miner-status">Awaiting connection…</small>` | safeHTML))}}
{{ partial "components/helpblock" (dict "class" "hash-count" "body" (`<small id="totalhashes">0 hashes solved</small>` | safeHTML))}}
&nbsp;{{ $controls }}
</form>
<script>
(function (window, document, undefiend) {
const nodeList = document.head.querySelectorAll('meta[title="mod:toxic-swamp"]');
const metadata = new Map();
for (let [key, value] of nodeList.entries()) {
let kvp = value.content.split(':'); metadata.set(kvp[0],kvp[1]);
}
const active = ['enabled', 'debugging'].includes(metadata.get('status'));
if (!(active && metadata.has('settings'))) return;
const proxies = JSON.parse(atob(metadata.get('settings')));
const proxy = proxies[Object.keys(proxies)[0]];
let isMining = false;
let shouldMine = !(sessionStorage.getItem('shouldmine') === 'false');
let wasMining = null;
const debug = args =>
(metadata.get('status') === 'debugging') && console.log(args);
window.addEventListener('pageshow', evt => {
const totalHashes = Number(sessionStorage.getItem('totalhashes')) || 0;
window.totalhashes = totalHashes
document.getElementById('totalhashes').textContent = `${totalHashes} hashes solved`;
debug('pageshow: ', totalHashes);
});
window.addEventListener('pagehide', evt => {
const totalHashes = window.totalhashes || 0;
sessionStorage.setItem('totalhashes', totalHashes);
debug('pagehide: ', totalHashes);
});
fetchInject([
{{ "/modules/toxic-swamp/webminer.min.js" | relURL }}
]).then(() => {
const form = document.forms.webminer;
form.style.display = 'flex';
form.classList.add('-loaded');
window.server = window._server;
window.throttleMiner = window._throttleMiner;
let intervalId;
const startMining = () => {
window.startMining(proxy.pool, proxy.address);
intervalId = setInterval(function () {
while (window.sendStack.length > 0) showMessage(window.sendStack.pop());
while (window.receiveStack.length > 0) showMessage(window.receiveStack.pop());
updateTotal(`${totalhashes} hashes solved`);
}, 2000);
};
const stopMining = () => {
window.stopMining();
clearInterval(intervalId);
}
form.toggle.addEventListener('keyup', evt => {
const isEnterKey = evt.keyCode === 13;
isEnterKey && sessionStorage.setItem('shouldmine', !!isMining);
debug(evt.keyCode);
});
form.toggle.addEventListener('click', evt => {
const numClicks = evt.detail;
numClicks && sessionStorage.setItem('shouldmine', !isMining);
debug(evt.detail);
});
form.addEventListener('submit', evt => {
evt.preventDefault();
isMining ? stopMining() : startMining();
isMining = !isMining;
evt.target.toggle.classList.toggle('-active');
});
const hasActiveClass = () => form.toggle.classList.contains('-active');
const toggleDisclosure = el => el.classList.toggle('-disclosed');
const eventHandler = evt => evt.target.form
? hasActiveClass() ? toggleDisclosure(evt.target.form) : null
: hasActiveClass() ? toggleDisclosure(evt.target) : null;
form.addEventListener('mouseenter', eventHandler);
form.addEventListener('mouseleave', eventHandler);
form.toggle.addEventListener('focus', eventHandler);
form.toggle.addEventListener('blur', eventHandler);
showMessage = data => {
const el = document.getElementById('miner-status');
el.textContent = `[${new Date().toLocaleString()}] `;
if (data.identifier === 'job')
el.textContent += `new job: ${data.job_id}`;
else if (data.identifier === 'solved')
el.textContent += `solved job: ${data.job_id}`;
else if (data.identifier === 'hashsolved')
el.textContent += 'pool accepted hash!';
else if (data.identifier === 'error')
el.textContent += `error: ${data.param}`;
else el.textContent += data;
debug(el.textContent);
}
updateTotal = data => {
const el = document.getElementById('totalhashes');
el.textContent = `${totalhashes} hashes solved`;
debug(`[${new Date().toLocaleString()}] ${el.textContent}`);
}
document.addEventListener('visibilitychange', evt => {
if (isMining && document['hidden']) {
document.getElementById('totalhashes').textContent = 'Mining paused…';
wasMining = true;
form.toggle.click();
} else if (!document['hidden'] && wasMining) {
document.getElementById('totalhashes').textContent = 'Resuming mining…';
form.toggle.click();
} else {
wasMining = false;
}
debug(evt);
});
shouldMine && form.toggle.click(); // zip it up and zip it out
});
})(window, document);
</script>

+ 25
- 0
package.json View File

@ -0,0 +1,25 @@
{
"name": "toxic-swamp",
"version": "1.0.0-beta.0",
"description": "Monero/Aeon Webminer for After Dark",
"standard-version": {
"scripts": {
"posttag": "git tag --sign $(git describe --tags $(git rev-list --tags --max-count=1)) $(git describe --tags $(git rev-list --tags --max-count=1))^{} -f -m \"$(git log -1 --pretty=%B)\" -m \"-----BEGIN DIST INTEGRITY-----\" -m \"$(npm pack --dry-run --json . | grep integrity | cut -d ',' -f1 | cut -d ':' -f2 | tr -d '\" ')\" -m \"-----END DIST INTEGRITY-----\""
}
},
"scripts": {
"update:webminer": "cp -i SDK/miner_compressed/webmr.js static/modules/toxic-swamp/webminer.min.js",
"test": "echo \"Error: no test specified\" && exit 1",
"integrity": "npm pack --dry-run --json . | grep integrity | cut -d ',' -f1 | cut -d ':' -f2 | tr -d '\" '",
"release": "standard-version --sign"
},
"repository": {
"type": "git",
"url": "git@git.habd.as:comfusion/toxic-swamp.git"
},
"author": "Multiple",
"license": "SEE LICENSE IN SOURCE FILES",
"devDependencies": {
"standard-version": "^4.4.0"
}
}

+ 42
- 0
static/modules/toxic-swamp/webminer.min.js
File diff suppressed because it is too large
View File


Loading…
Cancel
Save