Bettor Status

Puts the betting status of the person in their avatar

  1. // ==UserScript==
  2. // @name Bettor Status
  3. // @namespace d2jsp
  4. // @description Puts the betting status of the person in their avatar
  5. // @include http://forums.d2jsp.org/*
  6. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js
  7. // @version 3.04
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_xmlhttpRequest
  11. // ==/UserScript==
  12. /**************************************
  13. ** COPYRIGHT NUMONE@D2jsp.org ******
  14. **************************************/
  15. //globals
  16. var VERSION = 3.04;
  17. var CACHE_TIME = 1000 * 60 * 60; //1000 to convert to seconds, 60 to convert to min, 60 for 60 minutes
  18. var HEADER_URL = 'https://raw.githubusercontent.com/numone/bettor-status-d2jsp/devel/lists/master.json';
  19. var PAGE_TYPE = window.location.href.match(/\/topic\.php/) ? 'thread'
  20. : window.location.href.match(/\/pm\.php\?c\=3/) ? 'pm'
  21. : window.location.href.match(/\/user\.php/) ? 'user'
  22. : window.location.href.match(/\/settings\.php/) ? 'settings'
  23. : 'UNKNOWN';
  24. var LIST = {}; // holds the list of everything
  25.  
  26. // universal fieldset
  27. $('BODY').append('<fieldset style="padding:5px;position:absolute;z-index:100;background-color:#D4E0FF;" id="bsFieldset"><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>');
  28. $('#bsFieldset LEGEND IMG').click(function(){$('#bsFieldset').hide();});
  29. $('#bsFieldset').hide();
  30.  
  31.  
  32. function showPreferencesMenu(){
  33. $('BODY').css({'overflow':'hidden'});
  34. $('BODY').append('<div id="Bettor_Status_bkgrnd" style="position:absolute;top:0%;left:0%;width:100%;height:100%;background-color:black;z-index:1001;-moz-opacity:0.6;opacity:.60;filter:alpha(opacity=60)">' +
  35. '</div><div id="Bettor_Status_forgrnd" style="position:absolute;top:25%;left:25%;width:50%;height:50%;padding:16px;border:5px solid #8FBEFF;background-color:#E4EBFF;z-index:1002;overflow:auto;color:black;"></div>');
  36. var holder = $('#Bettor_Status_forgrnd');
  37. $(holder).html('<div style="font-size:12pt;"><span style="font-weight:bold;text-decoration:underline;">Bettor Status Settings:</span><span id="Bettor_Status_close" style="float:right;cursor:pointer;color:blue;text-decoration:underline;">Close</span></div>');
  38. $('#Bettor_Status_close').click(function(){
  39. $('#Bettor_Status_bkgrnd').remove();
  40. $('#Bettor_Status_forgrnd').remove();
  41. $('BODY').css({'overflow':'auto'});
  42. });
  43.  
  44. // display type
  45. $(holder).append('<span style="font-weight:bold;">Status Display:</span> <input type="radio" name="dispType" value="rolled" />Combined <input type="radio" name="dispType" value="seporated" />Separated');
  46. $(holder).find('INPUT[name="dispType"][value="' + GM_getValue('BSDispType','rolled') + '"]').prop('checked',true);
  47. $(holder).find('INPUT[name="dispType"]').click(function(){
  48. GM_setValue('BSDispType',$(this).prop('value'));
  49. });
  50.  
  51. // use list checkboxes
  52. $(holder).append('<div style="margin-top:15px;font-weight:bold;">Use Status From The Following Sports:</div>');
  53. for(var i=0;i<LIST.sports.length;i++){
  54. $(holder).append('<input type="checkbox" name="useSport" value="' + LIST.sports[i].title + '" /> ' + LIST.sports[i].title + '<br />');
  55. if(!(GM_getValue('BSHideSpt' + LIST.sports[i].title,false))){
  56. $(holder).find('INPUT[type="checkbox"][value="' + LIST.sports[i].title + '"]').prop('checked',true);
  57. }
  58. }
  59. $(holder).find('INPUT[type="checkbox"][name="useSport"]').click(function(){
  60. if($(this).prop('checked')){
  61. GM_setValue('BSHideSpt' + $(this).prop('value'),false);
  62. }else{
  63. GM_setValue('BSHideSpt' + $(this).prop('value'),true);
  64. }
  65. });
  66.  
  67. // names last updated
  68. var timeAgo = Math.round(((new Date().getTime()) - (GM_getValue('BSExpireTime') - CACHE_TIME)) / 60000);
  69. if(GM_getValue('BSExpireTime') == '0'){
  70. $(holder).append('<br /><br /><br /><span id="Bettor_Status_refreshSpan">Names List will reload when the page is refreshed (F5)</span>');
  71. }else{
  72. $(holder).append('<br /><br /><br /><span id="Bettor_Status_refreshSpan"><span style="font-style:italic;">Names List Last Updated ' + timeAgo + ' minutes ago.</span> <a href="#" id="Bettor_Status_refresh">Reload Now</a></span>');
  73. $('#Bettor_Status_refresh').click(function(){
  74. GM_setValue('BSExpireTime','0');
  75. $('#Bettor_Status_refreshSpan').html('Will now reload when the page is refreshed (F5)');
  76. });
  77. }
  78. }
  79.  
  80. function showPreferencesLink(){
  81. //$('BODY DIV.bar DIV.barR').append('<a href="#" id="Bettor_Status_pref">Bettor Status Settings</a>');
  82. $('BODY TABLE DL DD UL.mL').append('<li><a href="#" id="Bettor_Status_pref">Bettor Status Settings</a></li>');
  83. $('#Bettor_Status_pref').click(function(){
  84. showPreferencesMenu();
  85. });
  86. }
  87.  
  88. function showStatus(nameList,nameHolders){
  89. for(var i=0;i<nameList.length;i++){
  90. var resultsArray = [];
  91. var results = {rank:-1};
  92. for(var j=0;j<LIST.sports.length;j++){
  93. var sport = LIST.sports[j];
  94. if(!(GM_getValue('BSHideSpt' + sport.title,false))){
  95. if(sport.names[nameList[i].toUpperCase()]){
  96. resultsArray.push({sport:sport.title,status:sport.names[nameList[i].toUpperCase()].status,id:j});
  97. if(results.rank < LIST.statusInfo[sport.names[nameList[i].toUpperCase()].status].rank){
  98. results = {rank:LIST.statusInfo[sport.names[nameList[i].toUpperCase()].status].rank,status:sport.names[nameList[i].toUpperCase()].status};
  99. }
  100. }else{
  101. resultsArray.push({sport:sport.title,status:'Unknown',id:j});
  102. if(results.rank < 0){
  103. results = {rank:0,status:'Unknown'};
  104. }
  105. }
  106. }
  107. }
  108. if(results.rank > -1){
  109. if(GM_getValue('BSDispType','rolled') == 'rolled'){
  110. function createLink(){
  111. $(nameHolders[i]).append('<div class="sportStatusHolder"><a href="javascript:void(0);">Bettor Status</a>: ' + colorTheStatus(results.status) + '</div>');
  112. var resArray = resultsArray;
  113. $(nameHolders[i]).find('DIV.sportStatusHolder:last A').click(function(){
  114. showMultiSportsInfo(resArray,this);
  115. });
  116. }
  117. createLink();
  118. }else{
  119. for(var j=0;j<resultsArray.length;j++){
  120. function createLinkAll(){
  121. var appendStr = '<div class="sportStatusHolder"><a href="javascript:void(0);">' + resultsArray[j].sport + '</a>: ' + colorTheStatus(resultsArray[j].status) + '</div>';
  122. $(nameHolders[i]).append(appendStr);
  123. var theID = resultsArray[j].id;
  124. $(nameHolders[i]).find('DIV.sportStatusHolder:last A').click(function(){
  125. showSingleSportInfo(theID,this);
  126. });
  127. }
  128. createLinkAll();
  129. }
  130. }
  131. }
  132. }
  133. }
  134.  
  135. function showSingleSportInfo(id,link){
  136. var offset = $(link).offset();
  137. var sportInfo = LIST.sports[id];
  138. $('#bsFieldset').css({top:offset.top,left:offset.left}).show();
  139. $('#bsFieldset LEGEND SPAN').html(sportInfo.title + ' Info');
  140. $('#bsFieldset DIV.main').html('<a href="' + sportInfo.list + '" target="_blank">Link To ' + sportInfo.title + ' List Image</a><br /><br />List Ran By:<br />');
  141. for(var i=0;i<sportInfo.listRunner.length;i++){
  142. $('#bsFieldset DIV.main').append('<a href="' + sportInfo.listRunner[i].link + '" target="_blank">' + sportInfo.listRunner[i].name + '</a><br />');
  143. }
  144. }
  145.  
  146. function showMultiSportsInfo(resultsArray,link){
  147. var offset = $(link).offset();
  148. $('#bsFieldset').css({top:offset.top,left:offset.left}).show();
  149. $('#bsFieldset LEGEND SPAN').html('Bettor Status Info');
  150. $('#bsFieldset DIV.main').html('');
  151. for(var i=0;i<resultsArray.length;i++){
  152. var t = resultsArray[i];
  153. $('#bsFieldset DIV.main').append('<div><a title="links to ' + t.sport + ' list" href="' + LIST.sports[t.id].list + '" target="_blank">' + t.sport + '</a>: ' + colorTheStatus(t.status) + ' <span style="font-size:7pt;">Ran By: </span></div>');
  154. for(var j=0;j<LIST.sports[t.id].listRunner.length;j++){
  155. var o = LIST.sports[t.id].listRunner[j];
  156. $('#bsFieldset DIV.main DIV:last SPAN:last').append(' <a href="' + o.link + '" target="_blank">' + o.name + '</a>');
  157. }
  158. }
  159. }
  160.  
  161. function colorTheStatus(status){
  162. if(LIST.statusInfo[status]){
  163. return '<span style="color:' + LIST.statusInfo[status].color + ';font-weight:bold;">' + status + '</span>';
  164. }else{
  165. return '<span style="color:gray;font-weight:bold;">' + status + '</span>';
  166. }
  167. }
  168.  
  169. function showMedList(){
  170. var forumID = parseInt(window.location.href.split('&f=')[1]);
  171. var theSport = false;
  172. for(var i=0;i<LIST.sports.length;i++){
  173. if(LIST.sports[i].medForumIDs){
  174. var medList = LIST.sports[i].medForumIDs;
  175. for(var j=0;j<medList.length;j++){
  176. if(medList[j] == forumID){
  177. theSport = LIST.sports[i];
  178. break;
  179. }
  180. }
  181. }
  182. }
  183.  
  184. if(!theSport || theSport.medList.length == 0){
  185. return;
  186. }
  187.  
  188. $('BODY DIV.tbb DIV.links B').append('<a id="BSMedListLink" href="javascript:void(0);">Bettor Med List</a>');
  189. $('#BSMedListLink').click(function(){
  190. showMediators(theSport,this);
  191. });
  192. }
  193.  
  194. function showMediators(sportObj,link){
  195. var offset = $(link).offset();
  196. $('#bsFieldset').css({top:offset.top,left:offset.left}).show();
  197. $('#bsFieldset LEGEND SPAN').html('Bettor Med List');
  198. $('#bsFieldset DIV.main').html('');
  199. for(var i=0;i<sportObj.medList.length;i++){
  200. if(sportObj.medList[i].id){
  201. $('#bsFieldset DIV.main').append('<span style="font-weight:bold;">' + sportObj.medList[i].name + '</span> ( <a href="http://forums.d2jsp.org/user.php?i=' + sportObj.medList[i].id + '" target="_blank">http://forums.d2jsp.org/user.php?i=' + sportObj.medList[i].id + '</a> )<br />');
  202. }else{
  203. $('#bsFieldset DIV.main').append('<span style="font-weight:bold;">' + sportObj.medList[i].name + '</span><br />');
  204. }
  205. }
  206. }
  207.  
  208. function parsePage(){
  209. var names = [],nameHolders = [];
  210. switch(PAGE_TYPE){
  211. case 'thread':
  212. $('BODY DIV.tbb FORM[name="REPLIER"] DL DT A[href^="user.php"]').each(function(){
  213. names.push($(this).text());
  214. });
  215. $('BODY DIV.tbb FORM[name="REPLIER"] DL DD DIV.pud').each(function(){
  216. nameHolders.push(this);
  217. });
  218. break;
  219. case 'pm':
  220. $('BODY FORM[name="a"] DL.c DT A[href^="user.php"]').each(function(){
  221. names.push($(this).text());
  222. });
  223. $('BODY FORM[name="a"] DL.c DD DIV.pud').each(function(){
  224. nameHolders.push(this);
  225. });
  226. break;
  227. case 'user':
  228. $('BODY TABLE TR TD DL DT A[href="#"]').each(function(){
  229. names.push($(this).text());
  230. });
  231. $('BODY TABLE TR TD DL DD UL.bc1').each(function(){
  232. var list = document.createElement('LI');
  233. this.appendChild(list);
  234. nameHolders.push(list);
  235. });
  236. break;
  237. case 'settings':
  238. showPreferencesLink();
  239. break;
  240. }
  241.  
  242. if(names.length > 0 && nameHolders.length > 0){
  243. showStatus(names,nameHolders);
  244. }
  245.  
  246. if(PAGE_TYPE == 'thread'){
  247. showMedList();
  248. }
  249.  
  250. showFlushLink();
  251. }
  252.  
  253. function showFlushLink(){
  254. var timeAgo = Math.round(((new Date().getTime()) - (GM_getValue('BSExpireTime') - CACHE_TIME)) / 60000);
  255. $('BODY DIV.crt.links').append(' | Bettor Status version: ' + VERSION.toFixed(2) + ', <span id="BSBottomSpan">cached for ' + timeAgo + ' minutes <a href="javascript:void(0);" id="BSBottomFlush">flush</a></span>');
  256. $('#BSBottomFlush').click(function(){
  257. GM_setValue('BSExpireTime','0');
  258. $('#BSBottomSpan').html('Will now reload when the page is refreshed (F5)');
  259. });
  260. }
  261.  
  262. function gatherSport(sequence){
  263. if(sequence + 1 > LIST.sports.length){
  264. //save to cache
  265. GM_setValue('BSExpireTime',(new Date().getTime() + CACHE_TIME) + '');
  266. GM_setValue('BSListInfo',JSON.stringify(LIST));
  267.  
  268. parsePage();
  269. return;
  270. }
  271. LIST.sports[sequence].names = {};
  272. LIST.sports[sequence].medList = [];
  273.  
  274. GM_xmlhttpRequest({
  275. method:'GET',
  276. url:LIST.sports[sequence].namesURL + '?' + (new Date().getTime()),
  277. headers: {
  278. 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
  279. 'Accept': 'application/atom+xml,application/xml,text/xml'
  280. },
  281. onload:function(response){
  282. parseNames(sequence,response.responseText);
  283. gatherSport(sequence + 1);
  284. },
  285. onerror:function(err){
  286. showErrorMsg('Error retrieving list ' + LIST.sports[sequence].title);
  287. }
  288. });
  289. }
  290.  
  291. function parseNames(sequence,responseText){
  292. var userStatus;
  293. responseText = responseText.replace(/\r\n|\r|\n/gi,'#EL##SL#');
  294. var split = responseText.split('#EL##SL#');
  295. for(var i=0;i<split.length;i++){
  296. var temp = split[i];
  297. if(temp.match(/###[a-zA-Z0-9\s]+###/)){
  298. //console.log('Title: ' + temp.replace(/#/g,'').trim());
  299. userStatus = temp.replace(/#/g,'').trim();
  300. }else if(temp.length > 0){
  301. if(temp.match(/[^\s]\s+\/\/[0-9]+/)){
  302. var temp2 = temp.split(/\s+\/\//);
  303. //console.log('Name: ' + temp2[0].replace(/\/\//g,'').trim() + ' with number: ' + temp2[1].trim());
  304. LIST.sports[sequence].names[temp2[0].replace(/\/\//g,'').trim().toUpperCase()] = {status:userStatus,id:temp2[1].trim()};
  305. if(userStatus == 'Mediator'){
  306. LIST.sports[sequence].medList.push({name: temp2[0].replace(/\/\//g,'').trim(), id: temp2[1].trim()});
  307. }
  308. }else{
  309. //console.log('Name: ' + temp.trim() + ' length: ' + temp.trim().length);
  310. LIST.sports[sequence].names[temp.trim().toUpperCase()] = {status:userStatus};
  311. if(userStatus == 'Mediator'){
  312. LIST.sports[sequence].medList.push({name: temp.trim()});
  313. }
  314. }
  315. }else{
  316. //console.log('seporator');
  317. // empty line (hopefully)
  318. }
  319. }
  320. }
  321.  
  322. function showErrorMsg(msg){
  323. var div = document.createElement('DIV');
  324. $(div).css({
  325. position:'absolute',
  326. backgroundColor:'yellow',
  327. width:'50%',
  328. padding:'5px',
  329. top:'95px',
  330. textAlign:'center',
  331. left:'25%',
  332. fontWeight:'bold'
  333. }).html('Bettor Status Message: ' + msg);
  334. document.body.appendChild(div);
  335. }
  336.  
  337. function retrieveCache(){//return false;
  338. var expTime = GM_getValue('BSExpireTime');
  339. if(!expTime){//first load?
  340. return false;
  341. }
  342. var nowTime = new Date().getTime();
  343. if(nowTime > expTime){ //we've expired
  344. return false;
  345. }
  346.  
  347. LIST = JSON.parse(GM_getValue('BSListInfo'));
  348. parsePage();
  349. return true;
  350. }
  351.  
  352. function retrieveHeader(){
  353. GM_xmlhttpRequest({
  354. method:'GET',
  355. url:HEADER_URL + '?' + (new Date().getTime()),
  356. headers: {
  357. 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
  358. 'Accept': 'application/atom+xml,application/xml,text/xml'
  359. },
  360. onload:function(response){
  361. LIST = JSON.parse(response.responseText);
  362. if(LIST.version != VERSION){
  363. showErrorMsg('Your bettor status script is out of date, <a href="http://userscripts.org/scripts/show/50720" target="_blank">Click Here</a> to upgrade!');
  364. }
  365. gatherSport(0);
  366. },
  367. onerror:function(err){
  368. showErrorMsg('Error retrieving list header. Will used cached lists if available.');
  369. if(GM_getValue('BSListInfo')){// we have old lists, we will use that for now
  370. LIST = JSON.parse(GM_getValue('BSListInfo'));
  371. parsePage();
  372. }
  373. }
  374. });
  375. }
  376.  
  377. retrieveCache() || retrieveHeader();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址