Ghost-Trapper-Auto-Collect-And-Send-Badge

Auto send badge for ghost trapper, priority who send you request first. Still beta, more features comming soon

当前为 2016-12-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Ghost-Trapper-Auto-Collect-And-Send-Badge
  3. // @namespace http://www.ghost-trappers.com/fb/request_badges.php
  4. // @version 0.1
  5. // @description Auto send badge for ghost trapper, priority who send you request first. Still beta, more features comming soon
  6. // @author KoK9
  7. // @match http://www.ghost-trappers.com/fb/request_badges.php
  8. // @grant none
  9. // @require http://code.jquery.com/jquery-latest.js
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. var userList;
  15. var users;
  16. var optionsList =[];
  17. var selectElement;
  18.  
  19.  
  20. // Your code here...
  21. init();
  22. compareAndSelect(users,optionsList);
  23. userList = convertUsers(users);
  24. setUserList(userList);
  25.  
  26. /**
  27. * Function defined here
  28. */
  29. function compareAndSelect(users,optionsList){
  30. for(var i =1;i<optionsList.length;i++){
  31. for(var r = 0;r<users.length;r++){
  32. if(users[r].name == optionsList[i].name){
  33. console.log(optionsList[i].name +" " +optionsList[i].value);
  34. $("#request_fbid").val(optionsList[i].value).change();
  35. document.getElementsByClassName("sendRequestButton")[0].click();
  36. return;
  37. }
  38. }
  39. }
  40. }
  41.  
  42. function init(){
  43. userList = getUserList();
  44. users = covertUserList(userList);
  45. var rawList = document.getElementsByClassName("badgeRequestTable")[1].getElementsByClassName("nameContainer");
  46. for(var i =0;i<rawList.length;i++){
  47. var name = rawList[i].innerText;
  48. checkAndIncrease(name);
  49. }
  50. users = users.sort(compare);
  51. /**
  52. * Get option list
  53. */
  54. optionsList = initOptionList();
  55.  
  56. }
  57. function initOptionList(){
  58. var options = [];
  59. selectElement = document.getElementById("request_fbid");
  60. for(var i =0;i<selectElement.length;i++){
  61. var option ={name:"",value:0,select:function(){}};
  62. option.name = selectElement[i].innerText;
  63. option.value = selectElement[i].value;
  64. console.log("$option.name "+option.name+" $option.value "+option.value);
  65. option.select = function(){
  66. $("#request_fbid").val(option.value).change();
  67. };
  68. options.push(option);
  69. }
  70. return options;
  71. }
  72. function checkAndIncrease(name){
  73. for(var b = 0;b<users.length;b++){
  74. if(b.name==name)
  75. {
  76. b.count++;
  77. return;
  78. }
  79. }
  80. users.push({name:name,count:0});
  81. }
  82. function compare(a,b) {
  83. if (a.count < b.count)
  84. return -1;
  85. else if (a.count > b.count)
  86. return 1;
  87. else
  88. return 0;
  89. }
  90. function covertUserList(userList){
  91. if(userList==""||userList==null) return [];
  92. var user = [];
  93. var r = userList.split('@');
  94. for(var i =0;i< r.length;i++){
  95. user.push({name:r[i].split("|")[0],count:r[i].split("|")[1]});
  96. }
  97. return users;
  98. }
  99. function convertUsers(users){
  100. var userList ="";
  101. for(var i =0;i<users.length;i++){
  102. userList += users[i].name+"|";
  103. userList+= users[i].count+"@";
  104. }
  105. userList = userList.splice(userList.length-2,userList.length-1);
  106. return userList;
  107. }
  108. function getUserList(){
  109. return localStorage.getItem("userList");
  110.  
  111. }
  112. function setUserList(userList){
  113.  
  114. }
  115. })();