Show More
@@ -86,7 +86,7 b' function selectFileChoice() {' | |||||
86 | $(document).ready(function() { |
|
86 | $(document).ready(function() { | |
87 | var powDifficulty = parseInt($('body').attr('data-pow-difficulty')); |
|
87 | var powDifficulty = parseInt($('body').attr('data-pow-difficulty')); | |
88 | if (powDifficulty > 0 && typeof SharedWorker != 'undefined') { |
|
88 | if (powDifficulty > 0 && typeof SharedWorker != 'undefined') { | |
89 |
var worker = new SharedWorker($(' |
|
89 | var worker = new SharedWorker($('.post-form').attr('data-pow-script')); | |
90 | worker.port.onmessage = function(e) { |
|
90 | worker.port.onmessage = function(e) { | |
91 | var form = $('#form'); |
|
91 | var form = $('#form'); | |
92 | addHiddenInput(form, 'timestamp', e.data.timestamp); |
|
92 | addHiddenInput(form, 'timestamp', e.data.timestamp); | |
@@ -112,7 +112,7 b' function selectFileChoice() {' | |||||
112 | var data = { |
|
112 | var data = { | |
113 | msg: msg, |
|
113 | msg: msg, | |
114 | difficulty: parseInt($('body').attr('data-pow-difficulty')), |
|
114 | difficulty: parseInt($('body').attr('data-pow-difficulty')), | |
115 |
hasher: $(' |
|
115 | hasher: $('.post-form').attr('data-hasher') | |
116 | }; |
|
116 | }; | |
117 | worker.port.postMessage(data); |
|
117 | worker.port.postMessage(data); | |
118 |
|
118 |
@@ -1,10 +1,10 b'' | |||||
1 | var POW_COMPUTING_TIMEOUT = 2; |
|
1 | var POW_COMPUTING_TIMEOUT = 2; | |
2 | var POW_HASH_LENGTH = 16; |
|
2 | var POW_HASH_LENGTH = 16; | |
3 |
|
3 | |||
4 | var hasher; |
|
4 | var hasher = null; | |
5 |
|
5 | |||
6 |
|
6 | |||
7 |
function computeHash(iteration, guess, target, payload, timestamp, |
|
7 | function computeHash(iteration, guess, target, payload, timestamp, port) { | |
8 | iteration += 1; |
|
8 | iteration += 1; | |
9 | var hash = hasher(payload + iteration).toString(); |
|
9 | var hash = hasher(payload + iteration).toString(); | |
10 | guess = hash.substring(0, POW_HASH_LENGTH); |
|
10 | guess = hash.substring(0, POW_HASH_LENGTH); | |
@@ -26,12 +26,12 b' function computeHash(iteration, guess, t' | |||||
26 | //console.log("Target: ", target); |
|
26 | //console.log("Target: ", target); | |
27 |
|
27 | |||
28 | setTimeout(function() { |
|
28 | setTimeout(function() { | |
29 |
computeHash(iteration, guess, target, payload, timestamp, |
|
29 | computeHash(iteration, guess, target, payload, timestamp, port); | |
30 | }, POW_COMPUTING_TIMEOUT); |
|
30 | }, POW_COMPUTING_TIMEOUT); | |
31 | } |
|
31 | } | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 |
function doWork(message |
|
34 | function doWork(message, difficulty, port) { | |
35 | var timestamp = Date.now(); |
|
35 | var timestamp = Date.now(); | |
36 | var iteration = 0; |
|
36 | var iteration = 0; | |
37 | var payload = timestamp + message; |
|
37 | var payload = timestamp + message; | |
@@ -44,7 +44,7 b' function doWork(message, hasher, difficu' | |||||
44 | var guess = target + '0'; |
|
44 | var guess = target + '0'; | |
45 |
|
45 | |||
46 | setTimeout(function() { |
|
46 | setTimeout(function() { | |
47 |
computeHash(iteration, guess, target, payload, timestamp, |
|
47 | computeHash(iteration, guess, target, payload, timestamp, port); | |
48 | }, POW_COMPUTING_TIMEOUT); |
|
48 | }, POW_COMPUTING_TIMEOUT); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
@@ -54,10 +54,13 b' onconnect = function(e) {' | |||||
54 |
|
54 | |||
55 | port.onmessage = function(e) { |
|
55 | port.onmessage = function(e) { | |
56 | var difficulty = e.data.difficulty; |
|
56 | var difficulty = e.data.difficulty; | |
57 | importScripts(e.data.hasher); |
|
|||
58 | var hasher = CryptoJS.SHA256; |
|
|||
59 |
|
57 | |||
60 | self.doWork(e.data.msg, hasher, difficulty, port); |
|
58 | if (hasher == null) { | |
|
59 | importScripts(e.data.hasher); | |||
|
60 | hasher = CryptoJS.SHA256; | |||
|
61 | } | |||
|
62 | ||||
|
63 | self.doWork(e.data.msg, difficulty, port); | |||
61 | }; |
|
64 | }; | |
62 | } |
|
65 | } | |
63 |
|
66 |
@@ -155,7 +155,8 b'' | |||||
155 |
|
155 | |||
156 | <div class="post-form-w"> |
|
156 | <div class="post-form-w"> | |
157 | <script src="{% static 'js/panel.js' %}"></script> |
|
157 | <script src="{% static 'js/panel.js' %}"></script> | |
158 | <div class="post-form"> |
|
158 | <div class="post-form" data-hasher="{% static 'js/3party/sha256.js' %}" | |
|
159 | data-pow-script="{% static 'js/proof_of_work.js' %}"> | |||
159 | <div class="form-title">{% trans "Create new thread" %}</div> |
|
160 | <div class="form-title">{% trans "Create new thread" %}</div> | |
160 | <div class="swappable-form-full"> |
|
161 | <div class="swappable-form-full"> | |
161 | <form enctype="multipart/form-data" method="post" id="form">{% csrf_token %} |
|
162 | <form enctype="multipart/form-data" method="post" id="form">{% csrf_token %} | |
@@ -180,8 +181,6 b'' | |||||
180 | </div> |
|
181 | </div> | |
181 |
|
182 | |||
182 | <script src="{% static 'js/form.js' %}"></script> |
|
183 | <script src="{% static 'js/form.js' %}"></script> | |
183 | <script id="sha256Script" src="{% static 'js/3party/sha256.js' %}"></script> |
|
|||
184 | <script id="powScript" src="{% static 'js/proof_of_work.js' %}"></script> |
|
|||
185 | <script src="{% static 'js/3party/jquery.blockUI.js' %}"></script> |
|
184 | <script src="{% static 'js/3party/jquery.blockUI.js' %}"></script> | |
186 | <script src="{% static 'js/thread_create.js' %}"></script> |
|
185 | <script src="{% static 'js/thread_create.js' %}"></script> | |
187 |
|
186 |
@@ -43,7 +43,8 b'' | |||||
43 | <div class="post-form-w"> |
|
43 | <div class="post-form-w"> | |
44 | <script src="{% static 'js/panel.js' %}"></script> |
|
44 | <script src="{% static 'js/panel.js' %}"></script> | |
45 | <div class="form-title">{% trans "Reply to thread" %} #{{ opening_post.id }}<span class="reply-to-message"> {% trans "to message " %} #<span id="reply-to-message-id"></span></span></div> |
|
45 | <div class="form-title">{% trans "Reply to thread" %} #{{ opening_post.id }}<span class="reply-to-message"> {% trans "to message " %} #<span id="reply-to-message-id"></span></span></div> | |
46 |
<div class="post-form" id="compact-form" |
|
46 | <div class="post-form" id="compact-form" data-hasher="{% static 'js/3party/sha256.js' %}" | |
|
47 | data-pow-script="{% static 'js/proof_of_work.js' %}"> | |||
47 | <div class="swappable-form-full"> |
|
48 | <div class="swappable-form-full"> | |
48 | <form enctype="multipart/form-data" method="post" id="form">{% csrf_token %} |
|
49 | <form enctype="multipart/form-data" method="post" id="form">{% csrf_token %} | |
49 | <div class="compact-form-text"></div> |
|
50 | <div class="compact-form-text"></div> | |
@@ -69,8 +70,6 b'' | |||||
69 |
|
70 | |||
70 | <script src="{% static 'js/form.js' %}"></script> |
|
71 | <script src="{% static 'js/form.js' %}"></script> | |
71 | <script src="{% static 'js/jquery.form.min.js' %}"></script> |
|
72 | <script src="{% static 'js/jquery.form.min.js' %}"></script> | |
72 | <script id="sha256Script" src="{% static 'js/3party/sha256.js' %}"></script> |
|
|||
73 | <script id="powScript" src="{% static 'js/proof_of_work.js' %}"></script> |
|
|||
74 | <script src="{% static 'js/3party/jquery.blockUI.js' %}"></script> |
|
73 | <script src="{% static 'js/3party/jquery.blockUI.js' %}"></script> | |
75 | <script src="{% static 'js/thread.js' %}"></script> |
|
74 | <script src="{% static 'js/thread.js' %}"></script> | |
76 | <script src="{% static 'js/thread_update.js' %}"></script> |
|
75 | <script src="{% static 'js/thread_update.js' %}"></script> |
General Comments 0
You need to be logged in to leave comments.
Login now