Tag Checker

Show D2JSP BNP PokerStatus user

当前为 2021-05-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Tag Checker
  3. // @description Show D2JSP BNP PokerStatus user
  4. // Credits to fokse for creating this tampermonkey script
  5.  
  6. // @include https://forums.d2jsp.org/topic.php?t=*
  7. // @include https://forums.d2jsp.org/user.php?i=*
  8. // @include https://forums.d2jsp.org/pm.php?*
  9. // @include https://forums.d2jsp.org/forum.php?f=104
  10. // @include https://forums.d2jsp.org/forum.php?f=104&o=*
  11. // @include https://forums.d2jsp.org/guild.php*
  12. // @include https://forums.d2jsp.org/users.php?a=1&f=*
  13. // @include https://forums.d2jsp.org/index.php?*act=Friends*
  14. // @include https://forums.d2jsp.org/index.php?
  15. // @require https://code.jquery.com/jquery-latest.js
  16. // @include https://forums.d2jsp.org/gold.php*
  17. // @version 1.26
  18. // @namespace https://greasyfork.org/users/371129
  19. // ==/UserScript==
  20. var TAG_LIST = ["Unknown", "Mediator", "Trusted", "Regular", "Paid Back", "⛔ Blacklist ⛔", "📛 Welcher 📛"],
  21. COLOR = ["#2b2525", "#326110", "#3f5dce", "#f3ede5", "#f50ea1", "#f7f4f6", "#ef7272"],
  22. COLOR_2 = ['#615a5a','#178616','#2360af', 'orange','#dc26e6', 'black', 'red' ],
  23. BACKGROUND = ["#dad1d138", "#d8ecc8", "#d3e6f5", "#c37514", "#ecc1ec", "#151415", "#151415"];
  24.  
  25.  
  26.  
  27.  
  28.  
  29. var PAGE_TYPE = window.location.href.match(/\/topic\.php/) ? 'topic' :
  30. window.location.href.match(/act\=Friends/) ? 'friend' :
  31. window.location.href.match(/\/users\.php\?a=1\&f\=/) ? 'userlist' :
  32.  
  33. window.location.href.match(/\/pm\.php\?c\=3/) ? 'pm' :
  34. window.location.href.match(/\/user\.php/) ? 'user' :
  35. window.location.href.match(/\/guild\.php/) ? 'guild' :
  36. window.location.href.match(/\/gold\.php/) ? 'gold' :
  37. 'UNKNOWN';
  38.  
  39. function getSticky(){
  40.  
  41.  
  42.  
  43. if (!window.location.href.match(/\/forum\.php\?f\=104/)){
  44. return;
  45. }
  46.  
  47. $.ajax({
  48. type: 'GET',
  49. url: 'https://bnp.tools/api/links',
  50. dataType: 'JSON',
  51. success: function(jsonResult) {
  52. var sticky = '<tr><td><div class="sX s0a"></div></td><td class="lc links" colspan="5">Help:';
  53. jsonResult.forEach(function(element) {
  54. sticky += `<a href="${element.url}"><b>${element.display}</b></a>`;
  55. });
  56. sticky += '</td></tr>';
  57. $('body dl dd table.ftb tbody tr:eq(1)').before(sticky);
  58. }
  59. });
  60. }
  61. function showSingleLog(link, uid){
  62.  
  63. var offset = jQuery(link).offset();
  64. $('#psFieldset').css({top:offset.top,left:offset.left}).show();
  65. $('#psFieldset LEGEND SPAN').html("View tag history");
  66. $('#psFieldset DIV.main').html('<center><img src="https://bnp.tools/load.gif"></center>');
  67.  
  68. $.ajax({
  69. type: 'GET',
  70. url:`https://bnp.tools/api/description/${uid}`,
  71. success: function(response)
  72. {
  73. $('#psFieldset DIV.main').html(response);
  74. },
  75.  
  76. error: function(httpCode) {
  77. $('#psFieldset DIV.main').html('<center><i>Error retrieving data from server</i></center>');
  78. }
  79. });
  80.  
  81. };
  82.  
  83. function getStatus(userId) {
  84. $.ajax({
  85. type: 'GET',
  86. url: `https://bnp.tools/api/status/${userId}`,
  87. dataType: 'JSON',
  88. error: function(httpCode) {
  89. $(`div#pokerstatus_${jsonResult.id}`).each(function() {
  90. switch (PAGE_TYPE) {
  91. case 'user':
  92. $(this).html(`<i>Error retrieving data from server</i> `);
  93. break;
  94. case 'topic':
  95. case 'pm':
  96. $(this).html(`<a href=\"javascript:void(0);\">Poker Status: <i>Error</i></a> `)
  97. break;
  98. }
  99.  
  100. });
  101.  
  102. },
  103.  
  104. success: function(jsonResult) {
  105.  
  106.  
  107. $(`div#pokerstatus_${jsonResult.id}`).each(function() {
  108. switch (PAGE_TYPE) {
  109. case 'user':
  110. $(this).html(`
  111. <table class="ftbt">
  112. <tbody>
  113. <tr><td align="right"><b>Status:</b></td><td><b><span style="color: ${COLOR[jsonResult.results == false ? 0 : jsonResult.results[1]]};background: ${BACKGROUND[jsonResult.results == false ? 0 : jsonResult.results[1]]};opacity: 0.9;font-weight: bold;padding-left: 5px;padding-right: 5px;padding-top: 1px;padding-bottom: 1px;border-radius: 10px;">${jsonResult.results == false ? 'Unknown' : TAG_LIST[jsonResult.results[1]]}</span></b></td></tr>
  114. ${(jsonResult.results[2] && jsonResult.results[3].indexOf("#") != -1) || (jsonResult.results[3] ) ? `<tr class="bts">`: ''}
  115. ${jsonResult.results[2] && jsonResult.results[2].indexOf("#") != -1 ? `<td align="right" nowrap="">Discord:</td><td>${jsonResult.results[2]}</td></tr>`: ''}
  116. ${jsonResult.results[3] ? `<tr><td align="right" nowrap="">PokerStars:</td><td>${jsonResult.results[3]}</td></tr>`: ''}
  117.  
  118. ${jsonResult.results[4] || jsonResult.results[5] ? `<tr class="bts"><td></td><td align="right" nowrap=""><a id="tag_history" href="javascript:void(0);">View tag history</a></td></tr>`: ''}
  119. </tbody>
  120. </table>
  121. `);
  122.  
  123. if (jsonResult.results[4] || jsonResult.results[5]){
  124. $("#tag_history").click(function(){
  125. showSingleLog(this, jsonResult.id)
  126. });
  127. }
  128.  
  129.  
  130. break;
  131. case 'gold':
  132. case 'guild':
  133. case 'friend':
  134. $(this).html(`<span style="font-size: 8px;color: ${COLOR[jsonResult.results == false ? 0 : jsonResult.results[1]]};background: ${BACKGROUND[jsonResult.results == false ? 0 : jsonResult.results[1]]};opacity: 0.9;font-weight: bold;padding-left: 5px;padding-right: 5px;padding-top: 1px;padding-bottom: 1px;border-radius: 10px;">${jsonResult.results == false ? 'Unknown' : TAG_LIST[jsonResult.results[1]]}</span>`)
  135.  
  136. break;
  137. case 'userlist':
  138. console.log(jsonResult.results)
  139. if (jsonResult.results != 0 && jsonResult.results[1] != 0){
  140. $(this).html(` (<span style="font-weight:bold;color: ${COLOR_2[jsonResult.results == false ? 0 : jsonResult.results[1]]}">${jsonResult.results == false ? 'Unknown' : TAG_LIST[jsonResult.results[1]]}</span>)`)
  141. }
  142. break;
  143. break;
  144. case 'topic':
  145. case 'pm':
  146.  
  147. $(this).html(`<a href=\"javascript:void(0);\">Poker Status:</a> <span style="font-size: 8px;color: ${COLOR[jsonResult.results == false ? 0 : jsonResult.results[1]]};background: ${BACKGROUND[jsonResult.results == false ? 0 : jsonResult.results[1]]};opacity: 0.9;font-weight: bold;padding-left: 5px;padding-right: 5px;padding-top: 1px;padding-bottom: 1px;border-radius: 10px;">${jsonResult.results == false ? 'Unknown' : TAG_LIST[jsonResult.results[1]]}</span>`)
  148.  
  149.  
  150. if (jsonResult.results != false) {
  151. if (jsonResult.results[2] && jsonResult.results[2].indexOf("#") !== -1) {
  152. $(this).append(`<br>Discord: ${jsonResult.results[2]}`)
  153. }
  154. if (jsonResult.results[3]) {
  155. $(this).append(`<br>PokerStars: ${jsonResult.results[3]}`)
  156. }
  157. if (jsonResult.results[4] || jsonResult.results[5]){
  158. $($($(this).append(`<br><div class="view_log></div>`)).append(`<a href="javascript:void(0);">View tag history</a>`)).click(function(){showSingleLog(this, jsonResult.id)});
  159. }
  160. }
  161. break;
  162. }
  163.  
  164. });
  165. }
  166. });
  167.  
  168.  
  169. }
  170.  
  171. function parsePage() {
  172. var checked = [],
  173. userid;
  174.  
  175. switch (PAGE_TYPE) {
  176. case "pm":
  177. userid = $('body > form > dl.c > dt > a').attr('href').split('=')[1];
  178. $('body > form > dl.c > dd > div.bts.ppc > div.desc.p3.pud').append(`<div id="pokerstatus_${userid}"><a href="javascript:void(0);">Poker Status:</a> Loading...</div>`);
  179. getStatus(userid);
  180. break;
  181. case "friend":
  182. $('body > dl > dd > table > tbody > tr:nth-child(1) > th:last-child').after('<th>Poker Status</th>');
  183. $('body > dl > dd > table > tbody > tr').each(function(){
  184. if (typeof $('td:nth-child(3) a', this).attr('href') !== 'undefined'){
  185. var userid = $('td:nth-child(3) a', this).attr('href').split("=")[1]
  186. // console.log(userid)
  187. $(this).append(`<td><div style="display: inline;" id="pokerstatus_${userid}"></div></td>`);
  188. getStatus(userid);
  189. }
  190.  
  191. })
  192. break;
  193. case "userlist":
  194. console.log("User list")
  195. $('body > dl > dd > table > tbody > tr:nth-child(2) > td > a').each(function(){
  196. var userid = $(this).attr('href').split("=")[1]
  197. $(this).after(`<div style="display: inline;" id="pokerstatus_${userid}"></div>`);
  198. getStatus(userid);
  199. })
  200. break;
  201.  
  202. case "user":
  203. userid = window.location.href.split("=")[1]
  204. getStatus(userid);
  205.  
  206. $('body > form > div > div:nth-child(1) > dl:nth-child(1)').append(`<dl><dt>Bar & Pub Status</dt><dd><div class="p3 ce"><div id="pokerstatus_${userid}"><i>Loading...</i></div></div></dd></dl>`);
  207. $('body > div.upt > div:nth-child(1) > dl:nth-child(1)').after(` <dl><dt>Bar & Pub Status</dt><dd><div class="p3 ce"><div id="pokerstatus_${userid}"><i>Loading...</i></div></div></dd></dl>`);
  208. break;
  209. case 'guild':
  210. $('#tLT > tbody > tr:nth-child(1) > th:last-child').after('<th>Poker Status</th>');
  211. $('#tLT > tbody > tr').each(function(){
  212. if (typeof $('td:nth-child(2) > a', this).attr('href') !== 'undefined'){
  213. var userid = $('td:nth-child(2) > a', this).attr('href').split("=")[1]
  214. $(this).append(`<td><div id="pokerstatus_${userid}"><i>Loading...</i></div></td>`);
  215. getStatus(userid);
  216. }
  217. })
  218. break;
  219. case 'gold':
  220. $('.tzc > tbody > tr:nth-child(1) > th:last-child').after('<th>Poker Status</th>');
  221. $('.tzc > tbody > tr').each(function(){
  222. if (typeof $('td:nth-child(5) > a', this).attr('href') !== 'undefined'){
  223. var userid = $('td:nth-child(5) > a', this).attr('href').split("=")[1]
  224. $(this).append(`<td><div id="pokerstatus_${userid}"><i>Loading...</i></div></td>`);
  225. getStatus(userid);
  226. }
  227. })
  228. break;
  229. case 'topic':
  230. $('body > form > dl > dd > div.bts.ppc > div.desc.p3.pud').each(function() {
  231. $(this).append(`<div id="pokerstatus_${$(this).find('A[href^="pm.php"]').attr('href').split('=')[2]}"><a href="javascript:void(0);">Poker Status:</a> Loading...</div>`);
  232. });
  233.  
  234. $('BODY form DL DT A[href^="user.php"]').each(function() {
  235. userid = $(this).attr('href').split('=')[1];
  236. if (checked.indexOf(userid) == -1) {
  237. checked.push(userid);
  238. getStatus(userid);
  239. }
  240. });
  241. break;
  242. }
  243.  
  244.  
  245. }
  246. function createBox(){
  247. $('BODY').append('<fieldset style="padding:5px;position:absolute;z-index:100;background-color:#D4E0FF;" id="psFieldset"><legend style="background-color:#D4E0FF;border:1px solid #B0B0B0;"><span></span><img style="vertical-align:inherit;margin-left:2px;cursor:pointer;" src="images/x.gif" /></legend><div class="main"></div></fieldset>');
  248. $('#psFieldset LEGEND IMG').click(function(){$('#psFieldset').hide();});
  249. $('#psFieldset').hide();
  250. }
  251. createBox();
  252. parsePage();
  253. getSticky();