Add crime stats to result

Add the new number of crimes in the category to the result message

当前为 2022-10-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Add crime stats to result
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Add the new number of crimes in the category to the result message
  6. // @author miros
  7. // @license MIT
  8. // @match https://www.torn.com/crimes.php*
  9. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. // YOUR API KEY HERE - I think public level should be OK
  14. const API_KEY = "";
  15.  
  16. var nerve_to_cat = {
  17. 2: 'other',
  18. 3: 'selling_illegal_products',
  19. 4: 'theft',
  20. 5: 'theft',
  21. 6: 'theft',
  22. 7: 'theft',
  23. 8: 'drug_deals',
  24. 9: 'computer_crimes',
  25. 10: 'murder',
  26. 11: 'fraud_crimes',
  27. 12: 'auto_theft',
  28. 13: 'theft',
  29. 14: 'fraud_crimes',
  30. 15: 'theft',
  31. 16: 'selling_illegal_products',
  32. 17: 'fraud_crimes',
  33. 18 : 'computer_crimes',
  34. };
  35.  
  36. Object.defineProperty(String.prototype, 'capitalize', {
  37. value: function() {
  38. return this.charAt(0).toUpperCase() + this.slice(1);
  39. },
  40. });
  41.  
  42. Object.defineProperty(String.prototype, 'cat_to_title', {
  43. value: function() {
  44. return this.split('_').map(element => { return element.capitalize() }).join(' ');
  45. }
  46. });
  47.  
  48.  
  49. (function() {
  50. 'use strict';
  51. //alert('running Add crime stats to result.user');
  52. var intv = setInterval(function() {
  53. var message = document.querySelector('div.success-message');
  54. if(! message){
  55. return false;
  56. }
  57. //when element is found, clear the interval.
  58. clearInterval(intv);
  59. //alert('found message: [' + message.innerHTML + ']');
  60.  
  61. var nerve = document.querySelector('input[name="nervetake"]').getAttribute('value');
  62. var cat = nerve_to_cat[nerve];
  63. var title = cat.cat_to_title();
  64. //alert('nerve is [' + nerve + '], category is [' + cat + ']') ;
  65.  
  66. fetch('https://api.torn.com/user/' + API_KEY + '?selections=crimes&key=' + API_KEY)
  67. .then((response) => response.json())
  68. .then((data) => message.innerHTML = message.innerHTML + '<span style="display: inline-block; float: right; color:aquamarine;">' + data.criminalrecord[cat] + ' ' + title + '</span>');
  69. }, 300);
  70. })();
  71.