CFAccountsManager

Codeforces多账号管理助手

  1. // ==UserScript==
  2. // @name CFAccountsManager
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Codeforces多账号管理助手
  6. // @author bakapiano
  7. // @match *://codeforces.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. var BACKENDURL = "https://cf.bakapiano.site";
  13. function login(username, password) {
  14. if (document.querySelector("#header > div.lang-chooser > div:nth-child(2) > a:nth-child(2)").innerText == "Logout") {
  15. var url = document.querySelector("#header > div.lang-chooser > div:nth-child(2) > a:nth-child(2)").href;
  16. $.ajax({
  17. type: "GET",
  18. url: url,
  19. async: false,
  20. });
  21. }
  22.  
  23. $.get(
  24. url = "https://codeforces.com/enter",
  25. success = function(response,status,xhr){
  26. //console.log(response);
  27. var temp = $('<div></div>');
  28. temp.append($.parseHTML(response));
  29. var csrf_token = temp.find('.csrf-token')[0].attributes['data-csrf'].value;
  30. console.log(csrf_token);
  31. $.post(
  32. url = "https://codeforces.com/enter",
  33. data = {
  34. 'csrf_token': csrf_token,
  35. 'ftaa': 'jshedqz38upltgyz7u',
  36. 'bfaa': '262e4b1217220f326d1bb72da0b5daa4',
  37. 'handleOrEmail': username,
  38. 'password': password,
  39. '_tta': '115',
  40. 'action': 'enter',
  41. },
  42. success = function(response,status,xhr){
  43. location.reload()
  44. }
  45. )
  46. }
  47. );
  48. }
  49.  
  50. function check_current_work() {
  51. if (localStorage["work"] == "login") {
  52. login();
  53. } else if (1==1) {
  54. }
  55. }
  56.  
  57. function get_friend() {
  58. var list = $("#pageContent > div.datatable > div:nth-child(6) > table > tbody > tr").find("td");
  59. for(var i=0; i<list.length; i++) {
  60. if (i%3 == 1) {
  61. console.log(list[i]);
  62. }
  63. }
  64. }
  65.  
  66. function process_accounts_info() {
  67. var data = [];
  68. var lines = localStorage['accounts'].split('\n');
  69. for(var i=0; i<lines.length; i++) {
  70. var temp = lines[i].trim().split(' ');
  71. console.log(temp);
  72. if(temp.length>=2) {
  73. var username = temp[0].trim();
  74. var password = temp[temp.length-1].trim();
  75. if(username!="" && password!="") {
  76. data.push([username,password])
  77. }
  78. }
  79. }
  80. localStorage['data'] = JSON.stringify(data);
  81. }
  82.  
  83. function refresh_msg() {
  84. if(localStorage['data'] == null){
  85. return;
  86. }
  87. var data = jQuery.parseJSON(localStorage['data']);
  88. var ele = [];
  89. for(var i=0; i<data.length; i++) {
  90. var p = document.createElement("p");
  91. var a = document.createElement("a");
  92. //var username = data[i][0];
  93. //var password = data[i][1];
  94.  
  95. a.href = "#";
  96. //a.href="javascript:login('" + username + "','" + password + "')";
  97. a.attributes['username'] = data[i][0];
  98. a.attributes['password'] = data[i][1];
  99.  
  100. console.log("fuck", a.attributes['username'], a.attributes['password']);
  101.  
  102. a.onclick = function(){
  103. //console.log(this.href);
  104. //var t = username;
  105. //var a = password;
  106. //alert(this.attributes['username'], this.attributes['password']);
  107. //alert(this.attributes['password']);
  108. //console.log(t,a);
  109. login(this.attributes['username'], this.attributes['password']);
  110. };
  111.  
  112.  
  113. console.log(data[i][0]);
  114. var t = document.createTextNode(data[i][0]);
  115. a.appendChild(t);
  116. /*
  117. var success = document.createElement("div");
  118. success.style = 'display:inline;';
  119. success.className = 'success';
  120. p.appendChild(success);
  121. */
  122. var info = document.createElement("div");
  123. info.style = 'display:inline;';
  124. info.className = 'info';
  125. p.appendChild(a);
  126. p.appendChild(info);
  127.  
  128. ele.push(p);
  129. }
  130. $('#msg').children().remove();
  131. for(i=0; i<ele.length; i++) {
  132. $('#msg')[0].appendChild(ele[i]);
  133. console.log(ele[i]);
  134. ele[i].id = "user_" + data[i][0];
  135. }
  136. //$('#msg').append('<br>');
  137. }
  138.  
  139. function check_unread_msg() {
  140. if(localStorage['data'] == null){
  141. return;
  142. }
  143. var data = jQuery.parseJSON(localStorage['data']);
  144. console.log(data);
  145. //console.log()
  146. $.ajax({
  147. type: "POST",
  148. url: BACKENDURL + "/check_unread",
  149. //contentType: "application/json; charset=utf-8",
  150. data: "data="+JSON.stringify(data),
  151. dataType: "json",
  152. success : function (data) {
  153. unread = data[0];
  154. fail = data[1];
  155. var i = 0;
  156. all = $('#msg').find('.info');
  157. //for(i=0; i<all.length; i++) {
  158. // all[i].innerText = " No info. "
  159. //}
  160. for(i=0; i<unread.length; i++) {
  161. $('#msg').find('#user_'+unread[i]).find('.info')[0].innerText = " New message! ";
  162. }
  163. for(i=0; i<fail.length; i++) {
  164. $('#msg').find('#user_'+fail[i]).find('.info')[0].innerText = " Fail to login! ";
  165. }
  166. console.log(data);
  167. }
  168. });
  169. }
  170.  
  171. function sync_friend() {
  172. if(localStorage['data'] == null){
  173. return;
  174. }
  175. var data = jQuery.parseJSON(localStorage['data']);
  176. console.log(data);
  177. //console.log()
  178. $.ajax({
  179. type: "POST",
  180. url: BACKENDURL + "/sync_friend",
  181. //contentType: "application/json; charset=utf-8",
  182. data: "data="+JSON.stringify(data),
  183. dataType: "json",
  184. success : function (data) {
  185. fail = data;
  186. var i = 0;
  187. all = $('#msg').find('.info');
  188. for(i=0; i<all.length; i++) {
  189. all[i].innerText = " Sync done. "
  190. }
  191. for(i=0; i<fail.length; i++) {
  192. $('#msg').find('#user_'+fail[i]).find('.info')[0].innerText = " Fail to login! ";
  193. }
  194. console.log(data);
  195. }
  196. });
  197. }
  198.  
  199. function window_switch() {
  200. var main = $('#cfmain')[0];
  201. main.hidden = !main.hidden;
  202. var small = $('#cfmain_small')[0];
  203. small.hidden = !small.hidden;
  204.  
  205. }
  206.  
  207. setTimeout(function(){
  208. check_current_work();
  209.  
  210. $("body").append(" <div id='cfmain' style='left: 10px;bottom: 10px;background: #C0C0C0;overflow: hidden;z-index: 9999;position: fixed;padding:5px;text-align:center;width:220px;border-bottom-left-radius: 4px;border-bottom-right-radius: 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;'></div>");
  211.  
  212. $('#cfmain').append("<div id='msg'></div>");
  213. refresh_msg()
  214.  
  215. $('#cfmain').append('<div id="input"> </div>');
  216. $("#input").append('<textarea id="data" rows="8" style="width:200px;"></textarea>')
  217. $('#input').append('<br>');
  218.  
  219. if(localStorage['hideen'] != null) {
  220. localStorage['hideen'] = true;
  221. }
  222. $('#input')[0].hidden = localStorage['hideen'];
  223.  
  224. if(localStorage['accounts'] != null) {
  225. $('#data')[0].value = localStorage['accounts'];
  226. }
  227.  
  228. $('#cfmain').append('<button type="button" id="sync" >同步好友</button>');
  229. $('#cfmain').append('<button type="button" id="edit" >编辑账号</button>');
  230. $('#cfmain').append('<button type="button" id="exit" >关闭窗口</button>');
  231. $('#cfmain').append('<br>');
  232.  
  233. $('#data')[0].onblur = function() {
  234. localStorage['accounts'] = $('#data')[0].value;
  235. process_accounts_info();
  236. refresh_msg();
  237. check_unread_msg();
  238. }
  239.  
  240. $('#sync').click(function(){
  241. //localStorage["preURL"] = document.URL;
  242. //login();
  243.  
  244. sync_friend()
  245. });
  246.  
  247. $('#edit').click(function(){
  248. var input = $('#input')[0];
  249. if(input.hidden) {
  250. check_unread_msg();
  251. }
  252. input.hidden = !input.hidden;
  253. localStorage['hideen'] = input.hidden;
  254. });
  255.  
  256. $('#exit').click(function(){
  257. window_switch();
  258. });
  259.  
  260. $("body").append(" <div id='cfmain_small' style='left: 10px;bottom: 10px;background: #C0C0C0;overflow: hidden;z-index: 9999;position: fixed;padding:5px;text-align:center;width:50px;border-bottom-left-radius: 4px;border-bottom-right-radius: 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;'></div>");
  261. $("#cfmain_small").append("显示");
  262. $("#cfmain_small").click(function(){
  263. window_switch();
  264. });
  265.  
  266. //$("#cfmain_small")[0].hidden = true;
  267. $("#cfmain")[0].hidden = true;
  268.  
  269. setInterval(check_unread_msg, 1000*30);
  270.  
  271. //$('#cfmain').append('<input type="text" name="" id="TIME" style="width: 50" oninput="value=value.replace(/[^\\d]/g,\'\')">');
  272.  
  273. if (localStorage["preURL"] != "") {
  274. var temp = localStorage["preURL"];
  275. alert("xxx");
  276. localStorage["preURL"] = "";
  277. window.location.href = temp;
  278. }
  279. },500);
  280. })();

QingJ © 2025

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