Tag Checker

Show D2JSP BNP PokerStatus user

当前为 2021-04-30 提交的版本,查看 最新版本

  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.25
  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.  
  111.  
  112. $(this).html(`
  113. <table class="ftbt">
  114. <tbody>
  115. <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>
  116. ${(jsonResult.results[2] && jsonResult.results[3].indexOf("#") != -1) || (jsonResult.results[3] ) ? `<tr class="bts">`: ''}
  117. ${jsonResult.results[2] && jsonResult.results[2].indexOf("#") != -1 ? `<td align="right" nowrap="">Discord:</td><td>${jsonResult.results[2]}</td></tr>`: ''}
  118. ${jsonResult.results[3] ? `<tr><td align="right" nowrap="">PokerStars:</td><td>${jsonResult.results[3]}</td></tr>`: ''}
  119.  
  120. ${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>`: ''}
  121. </tbody>
  122. </table>
  123. `);
  124.  
  125. if (jsonResult.results[4] || jsonResult.results[5]){
  126. $("#tag_history").click(function(){
  127. showSingleLog(this, jsonResult.id)
  128. });
  129. }
  130.  
  131.  
  132. break;
  133. case 'gold':
  134. case 'guild':
  135. case 'friend':
  136. $(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>`)
  137.  
  138. break;
  139. case 'userlist':
  140. console.log(jsonResult.results)
  141. if (jsonResult.results != 0 && jsonResult.results[1] != 0){
  142. $(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>)`)
  143. }
  144. break;
  145. break;
  146. case 'topic':
  147. case 'pm':
  148.  
  149. $(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>`)
  150.  
  151.  
  152. if (jsonResult.results != false) {
  153. if (jsonResult.results[2] && jsonResult.results[2].indexOf("#") !== -1) {
  154. $(this).append(`<br>Discord: ${jsonResult.results[2]}`)
  155. }
  156. if (jsonResult.results[3]) {
  157. $(this).append(`<br>PokerStars: ${jsonResult.results[3]}`)
  158. }
  159. if (jsonResult.results[4] || jsonResult.results[5]){
  160. $($($(this).append(`<br><div class="view_log></div>`)).append(`<a href="javascript:void(0);">View tag history</a>`)).click(function(){showSingleLog(this, jsonResult.id)});
  161. }
  162.  
  163. }
  164. break;
  165. }
  166.  
  167. });
  168. }
  169. });
  170.  
  171.  
  172. }
  173.  
  174. function parsePage() {
  175. var checked = [],
  176. userid;
  177.  
  178. switch (PAGE_TYPE) {
  179. case "pm":
  180. userid = $('body > form > dl.c > dt > a').attr('href').split('=')[1];
  181. $('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>`);
  182. getStatus(userid);
  183. break;
  184. case "friend":
  185. $('body > dl > dd > table > tbody > tr:nth-child(1) > th:last-child').after('<th>Poker Status</th>');
  186. $('body > dl > dd > table > tbody > tr').each(function(){
  187. if (typeof $('td:nth-child(3) a', this).attr('href') !== 'undefined'){
  188. var userid = $('td:nth-child(3) a', this).attr('href').split("=")[1]
  189. // console.log(userid)
  190. $(this).append(`<td><div style="display: inline;" id="pokerstatus_${userid}"></div></td>`);
  191. getStatus(userid);
  192. }
  193.  
  194. })
  195. break;
  196. case "userlist":
  197. console.log("User list")
  198. $('body > dl > dd > table > tbody > tr:nth-child(2) > td > a').each(function(){
  199. var userid = $(this).attr('href').split("=")[1]
  200. $(this).after(`<div style="display: inline;" id="pokerstatus_${userid}"></div>`);
  201. getStatus(userid);
  202. })
  203. break;
  204.  
  205. case "user":
  206. userid = window.location.href.split("=")[1]
  207. getStatus(userid);
  208.  
  209. $('body > form > table > tbody > tr > td: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>`);
  210. $('body > table > tbody > tr > td: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>`);
  211. break;
  212. case 'guild':
  213. $('#tLT > tbody > tr:nth-child(1) > th:last-child').after('<th>Poker Status</th>');
  214. $('#tLT > tbody > tr').each(function(){
  215. if (typeof $('td:nth-child(2) > a', this).attr('href') !== 'undefined'){
  216. var userid = $('td:nth-child(2) > a', this).attr('href').split("=")[1]
  217. $(this).append(`<td><div id="pokerstatus_${userid}"><i>Loading...</i></div></td>`);
  218. getStatus(userid);
  219. }
  220. })
  221. break;
  222. case 'gold':
  223. $('.tzc > tbody > tr:nth-child(1) > th:last-child').after('<th>Poker Status</th>');
  224. $('.tzc > tbody > tr').each(function(){
  225. if (typeof $('td:nth-child(5) > a', this).attr('href') !== 'undefined'){
  226. var userid = $('td:nth-child(5) > a', this).attr('href').split("=")[1]
  227. $(this).append(`<td><div id="pokerstatus_${userid}"><i>Loading...</i></div></td>`);
  228. getStatus(userid);
  229. }
  230. })
  231. case 'topic':
  232. $('body > form > dl > dd > div.bts.ppc > div.desc.p3.pud').each(function() {
  233. $(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>`);
  234. });
  235.  
  236. $('BODY form DL DT A[href^="user.php"]').each(function() {
  237. userid = $(this).attr('href').split('=')[1];
  238. if (checked.indexOf(userid) == -1) {
  239. checked.push(userid);
  240. getStatus(userid);
  241. }
  242. });
  243. break;
  244. }
  245.  
  246.  
  247. }
  248. function createBox(){
  249. $('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>');
  250. $('#psFieldset LEGEND IMG').click(function(){$('#psFieldset').hide();});
  251. $('#psFieldset').hide();
  252. }
  253. createBox();
  254. parsePage();
  255. getSticky();