sbd-npm 1.0.99 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/.npmignore +1 -0
  2. package/package.json +1 -1
  3. package/util.js +42 -0
package/.npmignore ADDED
@@ -0,0 +1 @@
1
+ sbd-npm.md
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sbd-npm",
3
- "version": "1.0.99",
3
+ "version": "1.1.4",
4
4
  "description": "Stock Big Data",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/util.js CHANGED
@@ -49,6 +49,19 @@ let Util = {
49
49
  return false;
50
50
  });
51
51
 
52
+ $("#random_walk").click(function() {
53
+ let url_arr = [];
54
+ $('.side-menu li a').each(function () {
55
+ let url = $(this).attr("href");
56
+ if (url) {
57
+ url_arr.push(url);
58
+ }
59
+ });
60
+ if (url_arr.length > 0) {
61
+ window.open(Util.array_rand(url_arr), "_blank");
62
+ }
63
+ });
64
+
52
65
  $('#stock').keyup(function () {
53
66
  let st_obj = $("#search-tips");
54
67
  let key_word = $(this).val();
@@ -271,6 +284,21 @@ let Util = {
271
284
  }
272
285
  $(this).html(price);
273
286
  });
287
+ $(".year_price_" + code).each(function () {
288
+ if (item["year_price"]) {
289
+ $(this).html(Util.year_price_rate(item["price"], item["year_price"]));
290
+ } else {
291
+ let year_price = $(this).attr("data-val");
292
+ if (year_price) {
293
+ $(this).html(Util.year_price_rate(item["price"], Util.to_float(year_price)));
294
+ }
295
+ }
296
+ });
297
+ if (item["high_52week"]) {
298
+ $(".high_52week_" + code).each(function () {
299
+ $(this).html(Util.year_price_rate(item["price"], item["high_52week"]));
300
+ });
301
+ }
274
302
  }
275
303
  if (item["high"]) {
276
304
  let high_price = Util.digit_compare_trend(item["high"], item["previous_price"]);
@@ -881,6 +909,20 @@ let Util = {
881
909
  }
882
910
  },
883
911
 
912
+ /**
913
+ * 数组里随机取出一个值
914
+ * @param arr
915
+ * @param default_val
916
+ * @returns {string}
917
+ */
918
+ array_rand: function(arr, default_val = "") {
919
+ if (arr.length > 0) {
920
+ let rand_index = Math.floor((Math.random() * arr.length));
921
+ return arr[rand_index];
922
+ }
923
+ return default_val;
924
+ },
925
+
884
926
  // [为什么要用 setTimeout 模拟 setInterval ?](https://segmentfault.com/a/1190000038829248)
885
927
  set_interval: function (func, timeout) {
886
928
  let handler = function () {