MultiCuneta

Acceso fácil a multicunetas para ForoCoches

  1. // ==UserScript==
  2. // @name MultiCuneta
  3. // @version 0.1.1
  4. // @description Acceso fácil a multicunetas para ForoCoches
  5. // @author Tito Belfiore
  6. // @match https://www.forocoches.com/*
  7. // @grant none
  8. // @require http://code.jquery.com/jquery-latest.js
  9. // @namespace https://greatest.deepsurf.us/users/15080
  10. // ==/UserScript==
  11.  
  12. // BUG: Si no has cerrado la ventanita de "Info para nuevos usuarios" no enviará bien el formulario de login
  13.  
  14. $(document).ready(function(){
  15.  
  16. // TUS CUNETAS
  17. var cunetas = [
  18. {
  19. username: "Cuneta1",
  20. password: "Contra1"
  21. },
  22. {
  23. username: "Cuneta2",
  24. password: "Contra2"
  25. },
  26. {
  27. username: "Cuneta3",
  28. password: "Contra3"
  29. }
  30. // Etc
  31. ];
  32.  
  33. // Get User Index from Get parameter
  34. var CunetaIndex = getUrlVars().CunetaIndex;
  35.  
  36. var UserName = document.getElementsByTagName('strong')[1].firstElementChild.innerText;
  37.  
  38. // Check if user is logged in (Another HTML element is the UserName instead)
  39. if(UserName != "IR ARRIBA  ▲"){
  40. CunetaIndex = getMultiArrayIndex(cunetas, 'username', UserName);
  41.  
  42. var MenuNodeList = document.getElementsByClassName('vbmenu_control');
  43.  
  44. var LogoutLink = MenuNodeList[6].firstChild.attributes[0].value;
  45.  
  46. // Creation of the element to be added to the top menu
  47. var td = document.createElement("td");
  48. td.className = "vbmenu_control";
  49.  
  50. var a = document.createElement("a");
  51. a.id = "listacunetas";
  52. a.href = "/foro/index.php?nojs=1#listacunetas";
  53. a.style.cursor = "pointer";
  54. a.innerText = "Cuentas ";
  55.  
  56. td.appendChild(a);
  57.  
  58. // Add the element to the top menu
  59. MenuNodeList[0].parentNode.appendChild(td);
  60. // And register it for the click event
  61. vbmenu_register("listacunetas");
  62.  
  63. // Creation of the Accounts selection PopUp
  64. var PopUpCuentas = '';
  65. PopUpCuentas +=
  66. '<div class="vbmenu_popup" id="listacunetas_menu" style="margin-top: 3px; position: absolute; z-index: 50; clip: rect(auto auto auto auto); left: 986.5px; top: 291px; display: none;" align="left">'+
  67. '<table cellpadding="4" cellspacing="1" border="0"><tbody><tr><td class="thead">Cuentas</td></tr>';
  68. for (var i in cunetas) {
  69. if (cunetas[i].username == UserName)
  70. PopUpCuentas += '<tr><td class="vbmenu_hilite vbmenu_hilite_alink" style="cursor: pointer; background: #5590CC;"><a href="#">';
  71. else
  72. PopUpCuentas += '<tr><td class="vbmenu_option vbmenu_option_alink CunetaTd" style="cursor: default;"><a href="'+LogoutLink+
  73. '&CunetaIndex='+i+'">';
  74. PopUpCuentas += cunetas[i].username + '</a></td></tr>';
  75. }
  76. PopUpCuentas += '</tbody></table></div>';
  77.  
  78. // Get the PopUp Nodes and insert the new one after them
  79. var PopUpNodes = document.getElementsByClassName('vbmenu_popup');
  80. var LastPopUp = PopUpNodes[3];
  81. $(PopUpCuentas).insertAfter(LastPopUp);
  82. // Set style and hover behaviour
  83. $( "td.CunetaTd a" ).css("width","100%");
  84. $( "td.CunetaTd a" ).css("display","block");
  85. $( "td.CunetaTd" ).mouseenter(function() {
  86. $( this ).css("color", "#FFFFFF");
  87. $( this ).css("background", "#adadad");
  88. $( this ).css("cursor", "pointer");
  89. });
  90. $( "td.CunetaTd" ).mouseleave(function() {
  91. $( this ).css("color", "#22229C");
  92. $( this ).css("background", "#f5f5f5");
  93. $( this ).css("cursor", "default");
  94. });
  95. }
  96. else if(CunetaIndex && !isNaN(CunetaIndex)){
  97. // If user is not logged in, log in the new user
  98. UserName = cunetas[CunetaIndex].username;
  99. var Password = cunetas[CunetaIndex].password;
  100. // Get User and password Form Input
  101. var UsernameInput = document.getElementById('navbar_username');
  102. var PasswordInput = document.getElementById('navbar_password');
  103. var RememberInput = document.getElementById('cb_cookieuser_navbar');
  104. // Set the values
  105. UsernameInput.value = UserName;
  106. PasswordInput.value = Password;
  107. RememberInput.value = 1;
  108. // Send the form
  109. document.forms["log"].submit();
  110. }
  111. });
  112.  
  113. //Functions
  114.  
  115. function getUrlVars() {
  116. var vars = {};
  117. var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
  118. vars[key] = value;
  119. });
  120. return vars;
  121. }
  122.  
  123. function getMultiArrayIndex(myArray, property, value){
  124. for(var i = 0; i < myArray.length; i++) {
  125. if(myArray[i][property] === value) {
  126. return i;
  127. }
  128. }
  129. }