Kongquer

Adds a number of commands to Kongregate chat

当前为 2015-05-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Kongquer
  3. // @namespace http://alphaoverall.com
  4. // @version 1.1
  5. // @description Adds a number of commands to Kongregate chat
  6. // @author AlphaOverall
  7. // @include http://www.kongregate.com/games/*/*
  8. // ==/UserScript==
  9.  
  10. //==========
  11. // Kongquer
  12. // http://alphaoverall.com
  13. // by AlphaOverall (http://www.kongregate.com/accounts/AlphaOverall)
  14. // Inspired by Kongregate Get (http://userscripts-mirror.org/scripts/review/56432)
  15. //==========
  16.  
  17. //
  18. //This (slightly modified) cross browser init from Uknown Guardian's Kongregate One script
  19. // http://userscripts-mirror.org/scripts/show/164732
  20. // Full credit and thanks to him!
  21. //
  22. var dom = (typeof unsafeWindow === "undefined"?window:unsafeWindow);
  23. dom.oneScriptVersion = "1.101";
  24.  
  25. init();
  26. function init()
  27. {
  28. if(typeof GM_setValue === 'undefined'){
  29. window.GM_setValue = function(a,b){localStorage.setItem(a,b)}
  30. window.GM_getValue = function(a,b){var r=localStorage.getItem(a);return (r==null?b:r)}
  31. window.GM_deleteValue = function(a){localStorage.removeItem(a)}
  32. }
  33.  
  34. var url = dom.location.href;
  35. url = url.substr(url.indexOf(".com/") + ".com/".length);
  36.  
  37. if(url.indexOf("/") != -1)
  38. oneDirectory = url.substring(0,url.indexOf("/"));
  39. else
  40. oneDirectory = url;
  41.  
  42. oneDirectory = oneDirectory.split("?")[0];
  43.  
  44. dom.holodeckCheckCounter = 0
  45. dom.holodeckInterval = dom.setInterval(checkIfHolodeckLoaded, 100)
  46. }
  47. function checkIfHolodeckLoaded()
  48. {
  49. holodeckCheckCounter++;
  50. console.log("[Kongquer] Checking if holodeck loaded");
  51. if(typeof holodeck === 'undefined')
  52. {
  53.  
  54. }
  55. else if(holodeck.ready)
  56. {
  57. dom.clearInterval(dom.holodeckInterval);
  58. console.log("[Kongquer] Holodeck loaded");
  59. }
  60.  
  61. if(holodeckCheckCounter > 40)
  62. {
  63. dom.clearInterval(dom.holodeckInterval);
  64. console.log("[Kongquer] Holodeck failed to load");
  65. }
  66. }
  67.  
  68. function init_kongquer(){
  69. function makeLink(user){
  70. return '<a href="#" onclick="holodeck.showMiniProfile(\'' + user + '\'); return false;">' + user + '</a>';
  71. }
  72. var holodeck = dom.holodeck;
  73. ChatDialogue = dom.ChatDialogue;
  74. //
  75. //Test command so you don't look stupid if script doesn't load
  76. //
  77. holodeck.addChatCommand("test", function(l,n){
  78. l.activeDialogue().displayUnsanitizedMessage("Kong Bot", "Script is active! Have fun...", {"class":"whisper received_whisper"}, {non_user: true});
  79. return false;
  80. });
  81. //
  82. //From original Kongregate Get script (http://userscripts-mirror.org/scripts/review/56432)
  83. //
  84. holodeck.addChatCommand("avg", function(l,n){
  85. var roomDetails = l.chatWindow().activeRoom();
  86. var allUsers = roomDetails.users();
  87. var allLevels = 0;
  88. for(var i=0; i < allUsers.length; i++){
  89. allLevels += allUsers[i]._level;
  90. }
  91. var avgLevel = Math.round(allLevels/allUsers.length*10)/10;
  92. l.activeDialogue().displayUnsanitizedMessage("Average Level in Room", avgLevel , {"class":"whisper received_whisper"}, {non_user: true});
  93. return false;
  94. });
  95. if(holodeck && ChatDialogue && !holodeck._chat_commands.mostplayed) {
  96. //Credit goes entirely to Ventero for this command. Thanks for fixing the command after the Kongregate update, Vent :)
  97. holodeck.addChatCommand("mostplayed", function(l,n){
  98. var matchArr = n.match(/\/\S+\s+(\d+)/),
  99. dialog = l.activeDialogue(),
  100. gamesCount = 5,
  101. userList = dom.$A(l.chatWindow().activeRoom().users()),
  102. usersCount = userList.length;
  103. if(matchArr && matchArr[1]) gamesCount = matchArr[1];
  104. function p(count){
  105. return count == 1?"":"s";
  106. }
  107. var games = dom.$H();
  108. userList.each(function(user){
  109. console.log(user);
  110. var o = user._game_url;
  111. if(!games.get(o)){
  112. games.set(o, {
  113. title: user._game_title,
  114. count: 0,
  115. user: "",
  116. url: o
  117. });
  118. }
  119. games.get(o).count++;
  120. games.get(o).user = user.username;
  121. });
  122.  
  123. var countArr = games.values().sort(function(a,b){
  124. return +b.count - +a.count;
  125. }).slice(0, gamesCount);
  126. var totalCount = games.size();
  127.  
  128. dialog.displayUnsanitizedMessage("Kong Bot", usersCount+" user"+p(usersCount)+" playing "+totalCount+" different game" + p(totalCount), {"class":"whisper received_whisper"}, {non_user: true});
  129. dialog.displayUnsanitizedMessage("Kong Bot", gamesCount + " most played game" + p(gamesCount) + ":", {"class":"whisper received_whisper"}, {non_user: true});
  130. countArr.each(function(obj){
  131. dialog.displayUnsanitizedMessage("Kong Bot",
  132. obj.count + " user" + p(obj.count) + " (" +
  133. (obj.count > 1 ? "" : makeLink(obj.user) + ", ") +
  134. (100*obj.count/usersCount).toFixed(1) + "%) " +
  135. (obj.count > 1 ? "are" : "is") + ' playing <a href="' +
  136. obj.url + '">' + obj.title + "</a>", {"class":"whisper received_whisper"}, {non_user: true});
  137. });
  138. return false;
  139. });
  140. holodeck._chat_commands.mp = holodeck._chat_commands.getmp = holodeck._chat_commands.mostplayed;
  141. }
  142. //
  143. //Rest by AlphaOverall
  144. //
  145. holodeck.addChatCommand("highlvl", function(l,n){
  146. var roomDetails = l.chatWindow().activeRoom();
  147. var allUsers = roomDetails.users();
  148. var highLevels = "";
  149. var highestLevel = 0;
  150. var count = 0;
  151. for(var i=0; i < allUsers.length; i++){
  152. if (allUsers[i]._level > highestLevel){
  153. highestLevel = allUsers[i]._level;
  154. highLevels = "<img src=\"" + allUsers[i]._chat_avatar_url + "\">" + makeLink(allUsers[i].username);
  155. count = 1;
  156. }
  157. else if (allUsers[i]._level == highestLevel){
  158. highLevels = highLevels + ", <img src=\"" + allUsers[i]._chat_avatar_url + "\">" + makeLink(allUsers[i].username);
  159. count+=1;
  160. }
  161. }
  162. l.activeDialogue().displayUnsanitizedMessage("Highest Level in Room", highestLevel + ", Usercount: " + count + ", Users: " + highLevels, {"class":"whisper received_whisper"}, {non_user: true});
  163. return false;
  164. });
  165.  
  166. holodeck.addChatCommand("lowlvl", function(l,n){
  167. var roomDetails = l.chatWindow().activeRoom();
  168. var allUsers = roomDetails.users();
  169. var lowLevels = "";
  170. var lowestLevel = Infinity; //Just to makes sure :P
  171. var count = 0;
  172. for(var i=0; i < allUsers.length; i++){
  173. if (allUsers[i]._level < lowestLevel){
  174. lowestLevel = allUsers[i]._level;
  175. lowLevels = "<img src=\"" + allUsers[i]._chat_avatar_url + "\">" + makeLink(allUsers[i].username);
  176. count = 1;
  177. }
  178. else if (allUsers[i]._level == lowestLevel){
  179. count+=1;
  180. lowLevels = lowLevels + ", <img src=\"" + allUsers[i]._chat_avatar_url + "\">" + makeLink(allUsers[i].username);
  181. }
  182. }
  183. l.activeDialogue().displayUnsanitizedMessage("Lowest Level in Room", lowestLevel + ", Usercount: " + count + ", Users: " + lowLevels, {"class":"whisper received_whisper"}, {non_user: true});
  184. return false;
  185. });
  186.  
  187. holodeck.addChatCommand("list", function(l,n){
  188. var roomDetails = l.chatWindow().activeRoom();
  189. var allUsers = roomDetails.users();
  190. var userList = "";
  191. var word = n.match(/^\/\S+\s+(.+)/);
  192. var count = 0;
  193. if (word){
  194. var toFind = word[1];
  195. for(var i=0; i < allUsers.length; i++){
  196. if (allUsers[i].username.toLowerCase().includes(toFind.toLowerCase())){
  197. if (userList == ""){
  198. userList = "<img src=\"" + allUsers[i]._chat_avatar_url + "\">" + makeLink(allUsers[i].username);
  199. count = 1;
  200. }
  201. else{
  202. count+=1;
  203. userList = userList + ", <img src=\"" + allUsers[i]._chat_avatar_url + "\">" + makeLink(allUsers[i].username);
  204. }
  205. }
  206. }
  207. l.activeDialogue().displayUnsanitizedMessage("Usernames Containing " + word[1], "Usercount: " + count + ", Users: " + userList, {"class":"whisper received_whisper"}, {non_user: true});
  208. }
  209. else{
  210. l.activeDialogue().displayUnsanitizedMessage("Kong Bot", "Please use this command like " + n + " cat", {"class":"whisper received_whisper"}, {non_user: true});
  211. }
  212. return false;
  213. });
  214. holodeck.addChatCommand("levels", function(l,n){
  215. var z = n.match(/^\/\S+\s+(.+)/);
  216. var roomDetails = l.chatWindow().activeRoom();
  217. var allUsers = roomDetails.users();
  218. if (z){
  219. var userLevels = "";
  220. var levelCount = [];
  221. var displaymessage = "";
  222. if (z[1].includes("-")){
  223. var inbetween = z[1].split("-");
  224. if (inbetween[0] < inbetween[1]) {
  225. for (var a=inbetween[0]; a <= inbetween[1]; a++){
  226. levelCount.push(a);
  227. }
  228. }
  229. else{
  230. for (var a=inbetween[0]; a >= inbetween[1]; a--){
  231. levelCount.push(a);
  232. }
  233. }
  234. displaymessage = z[1];
  235. }
  236. else{
  237. var levelCount = z[1].split(" ");
  238. displaymessage = levelCount.join(", ");
  239. }
  240. console.log(levelCount);
  241. var count = 0;
  242. for (var b=0; b < levelCount.length; b++){
  243. for(var i=0; i < allUsers.length; i++){
  244. if (allUsers[i]._level == levelCount[b] && userLevels == ""){
  245. userLevels = "<img src=\"" + allUsers[i]._chat_avatar_url + "\">" + makeLink(allUsers[i].username);
  246. count = 1;
  247. }
  248. else if (allUsers[i]._level == levelCount[b]){
  249. count+=1;
  250. userLevels = userLevels + ", <img src=\"" + allUsers[i]._chat_avatar_url + "\">" + makeLink(allUsers[i].username);
  251. }
  252. }
  253. }
  254. l.activeDialogue().displayUnsanitizedMessage("Level " + displaymessage, "Usercount: " + count + ", Users: " + userLevels, {"class":"whisper received_whisper"}, {non_user: true});
  255. return false;
  256. }
  257. else{
  258. var levelsList = [l._active_user._attributes._object.level];
  259. for(var j=0; j < allUsers.length; j++){
  260. for (var k=0; k <= allUsers[j]._level; k++){
  261. if (allUsers[j]._level == k){
  262. if (levelsList.indexOf(k) < 0){
  263. levelsList.push(k);
  264. }
  265. }
  266. }
  267. }
  268. levelsList.sort(function(a, b){return a-b});
  269. l.activeDialogue().displayUnsanitizedMessage("Levels", levelsList.join(", "), {"class":"whisper received_whisper"}, {non_user: true});
  270. return false;
  271. }
  272. });
  273. holodeck.addChatCommand("developer", function(l,n){
  274. var roomDetails = l.chatWindow().activeRoom();
  275. var allUsers = roomDetails.users();
  276. var devs = [];
  277. for(var i=0; i < allUsers.length; i++){
  278. if (allUsers[i]._developer){
  279. devs.push(makeLink(allUsers[i].username));
  280. }
  281. }
  282. l.activeDialogue().displayUnsanitizedMessage("Developers in room", devs.join(", "), {"class":"whisper received_whisper"}, {non_user: true});
  283. return false;
  284. });
  285.  
  286. holodeck.addChatCommand("admin", function(l,n){
  287. var roomDetails = l.chatWindow().activeRoom();
  288. var allUsers = roomDetails.users();
  289. var admins = [];
  290. for(var i=0; i < allUsers.length; i++){
  291. if (allUsers[i]._admin){
  292. admins.push(makeLink(allUsers[i].username));
  293. }
  294. }
  295. l.activeDialogue().displayUnsanitizedMessage("Admins in room", admins.join(", "), {"class":"whisper received_whisper"}, {non_user: true});
  296. return false;
  297. });
  298. holodeck.addChatCommand("moderator", function(l,n){
  299. var roomDetails = l.chatWindow().activeRoom();
  300. var allUsers = roomDetails.users();
  301. var mods = [];
  302. for(var i=0; i < allUsers.length; i++){
  303. if (allUsers[i]._moderator_room_ids.length > 0 || allUsers[i]._moderator_game_ids.length > 0){
  304. mods.push(makeLink(allUsers[i].username));
  305. }
  306. }
  307. l.activeDialogue().displayUnsanitizedMessage("Mods in room", mods.join(", "), {"class":"whisper received_whisper"}, {non_user: true});
  308. return false;
  309. });
  310. //Simple commands that will show up in user info also
  311. holodeck.addChatCommand("id", function(l,n){
  312. var user = l._active_user._attributes._object;
  313. l.activeDialogue().displayUnsanitizedMessage("ID", user.id, {"class":"whisper received_whisper"}, {non_user: true});
  314. return false;
  315. });
  316. holodeck.addChatCommand("username", function(l,n){
  317. var user = l._active_user._attributes._object;
  318. l.activeDialogue().displayUnsanitizedMessage("Username", makeLink(user.username), {"class":"whisper received_whisper"}, {non_user: true});
  319. return false;
  320. });
  321. holodeck.addChatCommand("kreds", function(l,n){
  322. var user = l._active_user._attributes._object;
  323. l.activeDialogue().displayUnsanitizedMessage("Kreds", user.kreds_balance, {"class":"whisper received_whisper"}, {non_user: true});
  324. return false;
  325. });
  326. holodeck.addChatCommand("level", function(l,n){
  327. var user = l._active_user._attributes._object;
  328. l.activeDialogue().displayUnsanitizedMessage("Level", user.level, {"class":"whisper received_whisper"}, {non_user: true});
  329. return false;
  330. });
  331. holodeck.addChatCommand("age", function(l,n){
  332. var user = l._active_user._attributes._object;
  333. l.activeDialogue().displayUnsanitizedMessage("Age", user.age, {"class":"whisper received_whisper"}, {non_user: true});
  334. return false;
  335. });
  336. holodeck.addChatCommand("email", function(l,n){
  337. var user = l._active_user._attributes._object;
  338. l.activeDialogue().displayUnsanitizedMessage("Name/Email", user.sender_name_or_email, {"class":"whisper received_whisper"}, {non_user: true});
  339. return false;
  340. });
  341. holodeck.addChatCommand("user", function(l,n){
  342. var z = n.match(/^\/\S+\s+(.+)/);
  343. if (z){
  344. var roomDetails = l.chatWindow().activeRoom();
  345. var allUsers = roomDetails.users();
  346. for(var i=0; i < allUsers.length; i++){
  347. if (i == allUsers.length-1 && allUsers[i].username != z[1]){
  348. l.activeDialogue().displayUnsanitizedMessage("Kong Bot", "User not in chat... Opening mini profile", {"class":"whisper received_whisper"}, {non_user: true});
  349. holodeck.showMiniProfile(z[1]);
  350. return false;
  351. }
  352. if (allUsers[i].username == z[1]){
  353. var user = allUsers[i];
  354. l.activeDialogue().displayUnsanitizedMessage("Username", "<img src=\""+user._chat_avatar_url+"\"></img>" + makeLink(user.username), {"class":"whisper received_whisper"}, {non_user: true});
  355. l.activeDialogue().displayUnsanitizedMessage("Level", user._level, {"class":"whisper received_whisper"}, {non_user: true});
  356. if (user._moderator_room_ids.length == 0 && user._moderator_game_ids.length == 0){
  357. l.activeDialogue().displayUnsanitizedMessage("Admin/Moderator/Developer/Premium",user._admin+"/false/"+user._developer+"/"+user._premium, {"class":"whisper received_whisper"}, {non_user: true});
  358. }
  359. else{
  360. l.activeDialogue().displayUnsanitizedMessage("Admin/Moderator/Developer/Premium",user._admin+"/true/"+user._developer+"/"+user._premium, {"class":"whisper received_whisper"}, {non_user: true});
  361. if (!user._admin) {
  362. l.activeDialogue().displayUnsanitizedMessage("Moderator Game Ids", user._moderator_game_ids.join(", "), {"class":"whisper received_whisper"}, {non_user: true});
  363. l.activeDialogue().displayUnsanitizedMessage("Moderator Room Ids", user._moderator_room_ids.join(", "), {"class":"whisper received_whisper"}, {non_user: true});
  364. }
  365. }
  366. l.activeDialogue().displayUnsanitizedMessage("Playing", "<a href=\"http://www.kongregate.com" + user._game_url + "\" target=\"_blank\">" + user._game_title + "</a>", {"class":"whisper received_whisper"}, {non_user: true});
  367. l.activeDialogue().displayUnsanitizedMessage("Presence", user._presence, {"class":"whisper received_whisper"}, {non_user: true});
  368. l.activeDialogue().displayUnsanitizedMessage("Role", user._role, {"class":"whisper received_whisper"}, {non_user: true});
  369. return false;
  370. }
  371. }
  372. }
  373. else {
  374. var user = l._active_user._attributes._object;
  375. l.activeDialogue().displayUnsanitizedMessage("Username", "<img src=\""+user.avatar_url+"\">" + makeLink(user.username), {"class":"whisper received_whisper"}, {non_user: true});
  376. l.activeDialogue().displayUnsanitizedMessage("Age", user.age, {"class":"whisper received_whisper"}, {non_user: true});
  377. l.activeDialogue().displayUnsanitizedMessage("Admin/Moderator/Developer/Premium",user.admin+"/"+user.moderator+"/"+user.developer+"/"+user.premium, {"class":"whisper received_whisper"}, {non_user: true});
  378. l.activeDialogue().displayUnsanitizedMessage("ID", user.id, {"class":"whisper received_whisper"}, {non_user: true});
  379. l.activeDialogue().displayUnsanitizedMessage("Level", user.level, {"class":"whisper received_whisper"}, {non_user: true});
  380. l.activeDialogue().displayUnsanitizedMessage("Points for Next Level", user.points_away, {"class":"whisper received_whisper"}, {non_user: true});
  381. l.activeDialogue().displayUnsanitizedMessage("Total Points", user.points, {"class":"whisper received_whisper"}, {non_user: true});
  382. l.activeDialogue().displayUnsanitizedMessage("Last Level Up", user.last_levelup_at, {"class":"whisper received_whisper"}, {non_user: true});
  383. l.activeDialogue().displayUnsanitizedMessage("Kreds", user.kreds_balance, {"class":"whisper received_whisper"}, {non_user: true});
  384. l.activeDialogue().displayUnsanitizedMessage("Gameplays", user.gameplays_count, {"class":"whisper received_whisper"}, {non_user: true});
  385. l.activeDialogue().displayUnsanitizedMessage("Game Ratings", user.ratings_count, {"class":"whisper received_whisper"}, {non_user: true});
  386. l.activeDialogue().displayUnsanitizedMessage("BOTD Earned This Week", user.botds_this_week, {"class":"whisper received_whisper"}, {non_user: true});
  387. l.activeDialogue().displayUnsanitizedMessage("Name/Email", user.sender_name_or_email, {"class":"whisper received_whisper"}, {non_user: true});
  388. return false;
  389. }
  390. });
  391.  
  392. holodeck.addChatCommand("available", function(l,n){
  393. var z = n.match(/^\/\S+\s+(.+)/);
  394. if (z){
  395. l.activeDialogue().displayUnsanitizedMessage("Kong Bot", "Availability of " + z[1] + ":<iframe src=\"httP://www.kongregate.com/accounts/availability?username=" + z[1] + "\" width=\"100%\" height=\"30\"></iframe>", {"class":"whisper received_whisper"}, {non_user: true});
  396. }
  397. return false;
  398. });
  399. holodeck.addChatCommand("info", function(l,n){
  400. var info = l._chat_window._active_room;
  401. var room = info._room;
  402. l.activeDialogue().displayUnsanitizedMessage("Room Name", room.name, {"class":"whisper received_whisper"}, {non_user: true});
  403. l.activeDialogue().displayUnsanitizedMessage("Room ID", room.id, {"class":"whisper received_whisper"}, {non_user: true});
  404. l.activeDialogue().displayUnsanitizedMessage("Room Owner", "<a href=\"http://www.kongregate.com/accounts/" + room.owner + "\" target=\"_blank\">" + room.owner + "</a>", {"class":"whisper received_whisper"}, {non_user: true});
  405. l.activeDialogue().displayUnsanitizedMessage("Room Type", room.type, {"class":"whisper received_whisper"}, {non_user: true});
  406. l.activeDialogue().displayUnsanitizedMessage("Favorite Room", info._favorite_room, {"class":"whisper received_whisper"}, {non_user: true});
  407. l.activeDialogue().displayUnsanitizedMessage("Users In Room", info._number_in_room_node.innerText, {"class":"whisper received_whisper"}, {non_user: true});
  408. l.activeDialogue().displayUnsanitizedMessage("Guests In Room", info._guests_in_room_node.innerText, {"class":"whisper received_whisper"}, {non_user: true});
  409. return false;
  410. });
  411.  
  412. holodeck.addChatCommand("botd", function(l,n){
  413. var kbotd = l._active_user._attributes._object;
  414. var typeOf = "(easy)";
  415. if (kbotd.botd_reward_points == 5){//Do nothing
  416. }
  417. else if (kbotd.botd_reward_points == 15) {typeOf = "(medium)";}
  418. else if (kbotd.botd_reward_points == 30){typeOf = "(hard)";}
  419. else if (kbotd.botd_reward_points == 60){typeOf = "(impossible)";}
  420. else {typeOf = "Points: " + kbotd.botd_reward_points;} //Just in case
  421. l.activeDialogue().displayUnsanitizedMessage("BOTD", "<img src=\""+kbotd.botd_icon_uri+"\"></img>" + "<a href=\"" + kbotd.botd_game_uri + "\" target=\"_blank\">" + kbotd.botd_game_name + " - " + kbotd.botd_description + "</a> " + typeOf, {"class":"whisper received_whisper"}, {non_user: true});
  422. return false;
  423. });
  424.  
  425. holodeck.addChatCommand("friends", function(l,n){
  426. var kongfriends = l._chat_window._friends;
  427. var final = [];
  428. for(var friend in kongfriends){
  429. final.push("<a href=\"http://www.kongregate.com/accounts/" + friend + "\" target=\"_blank\">" + friend + "</a>");
  430. }
  431. l.activeDialogue().displayUnsanitizedMessage("Friends", final.join(", "), {"class":"whisper received_whisper"}, {non_user: true});
  432. return false;
  433. });
  434.  
  435. holodeck.addChatCommand("online", function(l,n){
  436. var online = document.getElementsByClassName("chat_actions_list")[0].childNodes[5];
  437. online.click();
  438. return false;
  439. });
  440.  
  441. holodeck.addChatCommand("exit", function(l,n){
  442. close();
  443. return false;
  444. });
  445.  
  446. holodeck.addChatCommand("open", function(l,n){
  447. var z = n.match(/^\/\S+\s+(.+)/);
  448. if (z[1]) {
  449. m = z[1].split(" ");
  450. if (m[0] == "accounts"){
  451. if (m[1]){
  452. open("http://www.kongregate.com/accounts/" + m[1], "_blank");
  453. }
  454. else{
  455. open("http://www.kongregate.com/accounts/" + l._active_user._attributes._object.username);
  456. }
  457. }
  458. else if (m[0] == "games"){
  459. if (m[1]) {
  460. if (m[2]){
  461. open("http://www.kongregate.com/games/" + m[1] + "/" + m[2], "_blank");
  462. }
  463. else{
  464. l.activeDialogue().displayUnsanitizedMessage("Kong Bot", "No specified game", {"class":"whisper received_whisper"}, {non_user: true});
  465. }
  466. }
  467. else{
  468. l.activeDialogue().displayUnsanitizedMessage("Kong Bot", "No specified game creator", {"class":"whisper received_whisper"}, {non_user: true});
  469. }
  470. }
  471. else {
  472. open("http://www.kongregate.com/search?q=" + z[1], "_blank");
  473. }
  474. }
  475. else {
  476. open("http://www.kongregate.com/accounts/" + l._active_user._attributes._object.username);
  477. }
  478. return false;
  479. });
  480.  
  481. holodeck.addChatCommand("khelp", function(l,n){
  482. open("http://www.kongregate.com/pages/help", "_blank");
  483. return false;
  484. });
  485. holodeck.addChatCommand("kong", function(l,n){
  486. open("http://www.kongregate.com", "_blank");
  487. return false;
  488. });
  489. holodeck.addChatCommand("help", function(l,n){
  490. open("http://www.alphaoverall.com", "_blank");
  491. return false;
  492. });
  493. holodeck.addChatCommand("signup", function(l,n){
  494. lightbox.prototype.initializeKongregateLightboxFromAjax('/accounts/new/behind_login?game_id=' + active_user.gameId(), { afterStaticContentLoad:lightbox.prototype.toggleRegistration });
  495. return false;
  496. });
  497. holodeck.addChatCommand("login", function(l,n){
  498. active_user.activateInlineLogin();
  499. return false;
  500. });
  501. holodeck.addChatCommand("signout", function(l,n){
  502. signoutFromSite();
  503. return false;
  504. });
  505. holodeck.addChatCommand("google", function(l,n){
  506. var z = n.match(/^\/\S+\s+(.+)/);
  507. if (z) {
  508. open("https://www.google.com/search?q=" + z[1], "_blank");
  509. }
  510. else {
  511. open("https://www.google.com", "_blank");
  512. }
  513. return false;
  514. });
  515. holodeck.addChatCommand("bing", function(l,n){
  516. var z = n.match(/^\/\S+\s+(.+)/);
  517. if (z) {
  518. open("https://www.bing.com/search?q=" + z[1], "_blank");
  519. }
  520. else {
  521. open("https://www.bing.com", "_blank");
  522. }
  523. return false;
  524. });
  525. holodeck.addChatCommand("yahoo", function(l,n){
  526. var z = n.match(/^\/\S+\s+(.+)/);
  527. if (z) {
  528. open("https://search.yahoo.com/search;_ylt=Aq7xBwaF.DQZx151DcVK87ybvZx4?p=" + z[1], "_blank");
  529. }
  530. else {
  531. open("https://www.yahoo.com", "_blank");
  532. }
  533. return false;
  534. });
  535. holodeck.addChatCommand("url", function(l,n){
  536. var z = n.match(/^\/\S+\s+(.+)/);
  537. if (z) {
  538. if (!z[1].includes("http://") && !z[1].includes("https://")){
  539. open("http://"+z[1], "_blank");
  540. }
  541. else {
  542. open(z[1], "_blank");
  543. }
  544. }
  545. else {
  546. l.activeDialogue().displayUnsanitizedMessage("Kong Bot", "Please use command like " + n + " https://www.google.com", {"class":"whisper received_whisper"}, {non_user: true});
  547. }
  548. return false;
  549. });
  550. holodeck.addChatCommand("calculator", function(l,n){
  551. var z = n.match(/^\/\S+\s+(.+)/);
  552. var output = "Nothing happened";
  553. if (z) {
  554. /*jshint multistr: true */
  555. if (z[1] == "help"){
  556. l.activeDialogue().displayUnsanitizedMessage("Math Commands", "+,-,*,<br>Math.abs(a) = absolute value of a<br>Math.acos(a) = arc cosine of a<br>\
  557. Math.asin(a) = arc sine of a<br>Math.atan(a) = arc tangent of a<br>Math.atan2(a,b) = arc tangent of a/b<br>Math.ceil(a) = integer closest to a and not less than a<br>\
  558. Math.cos(a) = cosine of a<br>Math.exp(a) = exponent of a (Math.E to the power a)<br>Math.floor(a) = integer closest to a, not greater than a<br>Math.log(a) = log of a base e<br>\
  559. Math.max(a,b) = the maximum of a and b<br>Math.min(a,b) = the minimum of a and b<br>Math.pow(a,b) = a to the power b<br>Math.random() = pseudorandom number 0 to 1<br>\
  560. Math.round(a) = integer closest to a <br> Math.sin(a) = sine of a<br>Math.sqrt(a) = square root of a<br>Math.tan(a) = tangent of a", {"class":"whisper received_whisper"}, {non_user: true});
  561. }
  562. else{
  563. try {
  564. output = eval(z[1]); //I know, I know, eval is evil
  565. l.activeDialogue().displayUnsanitizedMessage("Calculation", z[1] + " = " + output, {"class":"whisper received_whisper"}, {non_user: true});
  566. }
  567. catch (err){
  568. l.activeDialogue().displayUnsanitizedMessage("Kong Bot", err, {"class":"whisper received_whisper"}, {non_user: true});
  569. }
  570. }
  571. }
  572. else {
  573. l.activeDialogue().displayUnsanitizedMessage("Kong Bot", "Please use command like " + n + " 4+3-8*9/3^.5", {"class":"whisper received_whisper"}, {non_user: true});
  574. }
  575. console.log(output);
  576. return false;
  577. });
  578. holodeck.addChatCommand("youtube", function(l,n){
  579. var z = n.match(/^\/\S+\s+(.+)/);
  580. if (z) {
  581. var m = z[1].split(" ");
  582. if (m[0] == "embed"){
  583. var chatWindow = document.getElementsByClassName("chat_message_window");
  584. var chatWin;
  585. if (chatWindow[2] != undefined && chatWindow[2].offsetHeight > chatWindow[1].offsetHeight){
  586. chatWin = chatWindow[2];
  587. }
  588. else {
  589. chatWin = chatWindow[1];
  590. }
  591. var h = chatWin.offsetHeight;
  592. if (chatWin.offsetWidth > chatWin.offsetHeight) {
  593. h = chatWin.offsetHeight;
  594. }
  595. else{
  596. h = chatWin.offsetWidth*9/16; //YouTube 16:9 aspect ratio
  597. }
  598. if (m[1].includes("youtu.be/")){
  599. l.activeDialogue().displayUnsanitizedMessage("YouTube", "<iframe src=\"https://www.youtube.com/embed/" + m[1].split("youtu.be/")[1] + "\" width=\"100%\" height=\"" + h +"\"></iframe>", {"class":"whisper received_whisper"}, {non_user: true});
  600. }
  601. else if (m[1].includes("youtube.com/watch?v=")){
  602. l.activeDialogue().displayUnsanitizedMessage("YouTube", "<iframe src=\"https://www.youtube.com/embed/" + m[1].split("youtube.com/watch?v=")[1] + "\" width=\"100%\" height=\"" + h + "\"></iframe>", {"class":"whisper received_whisper"}, {non_user: true});
  603. }
  604. else{
  605. l.activeDialogue().displayUnsanitizedMessage("YouTube", "Invalid YouTube video url", {"class":"whisper received_whisper"}, {non_user: true});
  606. }
  607. }
  608. else {
  609. open("https://www.youtube.com/results?search_query=" + z[1], "_blank");
  610. }
  611. }
  612. else {
  613. open("https://www.youtube.com", "_blank");
  614. }
  615. return false;
  616. });
  617. holodeck.addChatCommand("mp3", function(l,n){
  618. var z = n.match(/^\/\S+\s+(.+)/);
  619. if (z) {
  620. l.activeDialogue().displayUnsanitizedMessage("MP3 Container", "<audio src=\"" + z[1] + "\" controls><embed src=\"" + z[1] + "\" width=\"100%\" height=\"90\" loop=\"false\" autostart=\"true\"/>" +
  621. "</audio>", {"class":"whisper received_whisper"}, {non_user: true});
  622. }
  623. else {
  624. l.activeDialogue().displayUnsanitizedMessage("MP3 Container", "Invalid mp3 url", {"class":"whisper received_whisper"}, {non_user: true});
  625. }
  626. return false;
  627. });
  628. holodeck.addChatCommand("time", function(l,n){
  629. var today = new Date();
  630. var format = today.getDate() + "/" + (today.getMonth()+1) + "/" + today.getFullYear() + ", " + today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
  631. l.activeDialogue().displayUnsanitizedMessage("Date/Time", format, {"class":"whisper received_whisper"}, {non_user: true});
  632. return false;
  633. });
  634. holodeck.addChatCommand("reload", function(l,n){
  635. location.reload();
  636. return false;
  637. });
  638. holodeck.addChatCommand("clear", function(l,n){
  639. holodeck._active_dialogue.clear();
  640. return false;
  641. });
  642. holodeck._chat_commands.lol = holodeck._chat_commands.hi = holodeck._chat_commands.hmm = holodeck._chat_commands.test;
  643. holodeck._chat_commands.userlist = holodeck._chat_commands.username = holodeck._chat_commands.list;
  644. holodeck._chat_commands.date = holodeck._chat_commands.datetime = holodeck._chat_commands.now = holodeck._chat_commands.time;
  645. holodeck._chat_commands.math = holodeck._chat_commands.calc = holodeck._chat_commands.calculator;
  646. holodeck._chat_commands.goto = holodeck._chat_commands.http = holodeck._chat_commands.www = holodeck._chat_commands.url;
  647. holodeck._chat_commands.lvl = holodeck._chat_commands.level;
  648. holodeck._chat_commands.konghelp = holodeck._chat_commands.kongregatehelp = holodeck._chat_commands.khelp;
  649. holodeck._chat_commands.kongregate = holodeck._chat_commands.kong;
  650. holodeck._chat_commands.avglvl = holodeck._chat_commands.alvl = holodeck._chat_commands.avg;
  651. holodeck._chat_commands.close = holodeck._chat_commands.exit;
  652. holodeck._chat_commands.roominfo = holodeck._chat_commands.info;
  653. holodeck._chat_commands.friendsonline = holodeck._chat_commands.online;
  654. holodeck._chat_commands.u = holodeck._chat_commands.me = holodeck._chat_commands.user;
  655. holodeck._chat_commands.admins = holodeck._chat_commands.administrator = holodeck._chat_commands.administrators = holodeck._chat_commands.admin;
  656. holodeck._chat_commands.dev = holodeck._chat_commands.devs = holodeck._chat_commands.developers = holodeck._chat_commands.developer;
  657. holodeck._chat_commands.mod = holodeck._chat_commands.mods = holodeck._chat_commands.moderators = holodeck._chat_commands.moderator;
  658. holodeck._chat_commands.hlvl = holodeck._chat_commands.highlevel = holodeck._chat_commands.hlevel = holodeck._chat_commands.highlvl;
  659. holodeck._chat_commands.llvl = holodeck._chat_commands.lowlevel = holodeck._chat_commands.llevel = holodeck._chat_commands.lowlvl;
  660. holodeck._chat_commands.mp = holodeck._chat_commands.getmp = holodeck._chat_commands.mostplayed;
  661. }
  662.  
  663. function check(){
  664. var injectScript = dom.injectScript||(document.getElementById("injectScriptDiv")?document.getElementById("injectScriptDiv").onclick():0);
  665. if(injectScript){
  666. injectScript(init_kongquer, 0);
  667. }
  668. else if(!dom._promptedFramework && !/Chrome/i.test(navigator.appVersion)){
  669. if(confirm("You don't have the latest version of the framework-script!\n" +
  670. "Please install it, otherwise the King Kongregate script won't work.\n" +
  671. "Clicking ok will open a new tab where you can install the script"))
  672. window.open("http://userscripts-mirror.org/scripts/show/54245", "_blank");
  673. dom._promptedFramework = true;
  674. }
  675. }
  676.  
  677. setTimeout(check, 0);