SpeedCalling for Popmundo

Calls everyone in your contact list

  1. // ==UserScript==
  2. // @name SpeedCalling for Popmundo
  3. // @namespace http://popmundo.psicofrenia.com/
  4. // @description Calls everyone in your contact list
  5. // @include http://*.popmundo.com/World/Popmundo.aspx/Character/AddressBook
  6. // @include http://*.popmundo.com/World/Popmundo.aspx/Interact/Phone/*
  7. // @require https://greasyfork.org/scripts/3355-popmundo-lib/code/popmundo_lib.js?version=10024
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
  9. // @grant GM_info
  10. // @version 3.2
  11. // ==/UserScript==
  12.  
  13.  
  14. var gexQuery = jQuery.noConflict();
  15.  
  16. // ------------------------------------------------------------------------
  17. // ----------- DEFINITIONS AREA
  18.  
  19. var _locVersion_SpeedCalling = '3.1';
  20. // External script with SpeedCalling functions
  21. var _jsFile = 'http://resources.psicofrenia.com/popmundo.js';
  22. // Logical variable to detect if the script should use Portuguese or English
  23. var _isPortuguese = 0;
  24. // Current URL
  25. var _urlCurrent = window.location.pathname;
  26. // Url to make the calls
  27. var _urlToCall = '/World/Popmundo.aspx/Interact/Phone/';
  28. // Url to mark the page as usable by this script
  29. var _urlToCall_Token = '#toCall';
  30. var _urlToContact_Token = '#toContact';
  31. // Id of the char logged in
  32. var _idMainChar = 0;
  33. // Id of the char currently being interacted with
  34. var _idCurrentChar = 0;
  35. // Id to be used to store values on local storage
  36. var _idStorage = '_GEX_MAIN_ID_';
  37. // Array with runtimes values
  38. var _valuesRunTime = {};
  39. // Array with stored values
  40. var _valuesStorage = {};
  41. // Default value for callings
  42. var _valueDefault = 24;
  43. // All possible values for calling
  44. var _valueCalls = Array(9999,121,24,61,58,26,25,73,74);
  45.  
  46. // ------------------------------------------------------------------------
  47. // ----------- GLOBAL CODE
  48.  
  49. appendJsFile(_jsFile);
  50. detectLanguage();
  51. getIdMain();
  52.  
  53. checkVersion();
  54.  
  55. if( _urlCurrent.match(/\/World\/Popmundo.aspx\/Character\/AddressBook/g)){
  56. executeOnPage_Book();
  57. }
  58.  
  59. if( _urlCurrent.match(/\/World\/Popmundo.aspx\/Interact\/Phone/g)){
  60. executeOnPage_Contact();
  61. }
  62.  
  63. // ------------------------------------------------------------------------
  64. // ----------- FUNCTIONS AREA
  65.  
  66. //Adds any external JS Script to the Popmundo page
  67. function appendJsFile(jsUrl){
  68. var scriptTag = '<script type="text/javascript" src="' + _jsFile + '"></script>';
  69. gexQuery(scriptTag).appendTo('head');
  70. }
  71.  
  72. // Detects if Popmundo is being used in one of the Portuguese translations
  73. function detectLanguage(){
  74. var langIdentifier = 'notícias';
  75. if (gexQuery('#ctl00_ucMenu_lnkStart').text().toLowerCase() == langIdentifier)
  76. _isPortuguese = 1;
  77. }
  78.  
  79. //Gets the correct label for the language
  80. function getLabel(label){
  81. var translations = new Array();
  82. translations.call_everyone = 'Call everyone#Ligar para todos';
  83. translations.bug_report = 'Report a bug#Reportar um bug';
  84. translations.update = 'Theres a new Version avaiable. Click here to update SpeedCalling.#Há uma nova versão disponível. Clique aqui para atualizá-la.';
  85. translations.i9999 = 'Dont Call#Não telefonar';
  86. translations.i121 = 'Gossip on the phone#Fofocar ao telefone';
  87. translations.i24 = 'Wazzup call#Ligar para papear';
  88. translations.i61 = 'SMS friendly text#Mandar mensagem no celular';
  89. translations.i58 = 'SMS funny pic#Mandar foto engraçada por MMS';
  90. translations.i26 = 'Prank call#Passar trote';
  91. translations.i25 = 'Lover call#Ligar para namorar';
  92. translations.i73 = 'Flirty Phone call#Ligar para flertar';
  93. translations.i74 = 'Flirty SMS#Flertar por SMS';
  94. if(translations[label] == undefined) return 'OOps!!!';
  95.  
  96. return translations[label].split("#")[_isPortuguese];
  97. }
  98.  
  99. //Gets the ID of the logged char and sets the storage ID
  100. function getIdMain(){
  101. _idMainChar = gexQuery('.idHolder').first().html();
  102. _idStorage += _idMainChar;
  103. }
  104.  
  105. //Gets the ID of the logged char and sets the storage ID
  106. function getIdCurrent(){
  107. _idMainChar = gexQuery('.idHolder').first().html();
  108. }
  109.  
  110. //Returns the button to make the calls
  111. function getCallButton(){
  112. var callButton = "<tr><td colspan=\"8\">"
  113. callButton += checkVersion();
  114. callButton += "<input type=\"button\" onclick=\"CallEveryone('" + _idStorage + "')\" value=\"" + getLabel('call_everyone') + "\" />";
  115. callButton += "<input type=\"button\" onclick=\"contactAuthor();\" value=\"" + getLabel('bug_report') + "\" />";
  116. callButton += "</td></tr>";
  117.  
  118. gexQuery(callButton).insertAfter('thead');
  119. }
  120.  
  121. //Returns the character ID based on the link URI
  122. function getIdFromUrl(value)
  123. {
  124. var urlItems = value.split('/');
  125. return urlItems[urlItems.length -1];
  126. }
  127.  
  128. //Loads all contact entries values into memory and updates localStorage
  129. function loadValues(){
  130. //Loads all current contacts (existant in the links)
  131. gexQuery("a[id^='ctl00_cphLeftColumn_ctl00_repAddressBook_ctl'][id$=_lnkCharacter]")
  132. .each(function()
  133. {
  134. var key = getIdFromUrl(gexQuery(this).attr('href'));
  135. _valuesRunTime[key] = _valueDefault;
  136. });
  137.  
  138. //Updates the localStorage if not present
  139. if(window.localStorage.getItem(_idStorage) === null)
  140. {
  141. window.localStorage.setItem(_idStorage,JSON.stringify(_valuesRunTime));
  142. _valuesStorage = _valuesRunTime;
  143. } else { _valuesStorage = JSON.parse(window.localStorage.getItem(_idStorage)); }
  144.  
  145. //Loads stored values into runtime values
  146. for(var key in _valuesRunTime)
  147. {
  148. if(typeof(_valuesStorage[key]) != 'undefined')
  149. { _valuesRunTime[key] = _valuesStorage[key]; }
  150. }
  151.  
  152. //Saves the localStorage
  153. window.localStorage.setItem(_idStorage,JSON.stringify(_valuesRunTime));
  154.  
  155. }
  156.  
  157. //Returns the combobox ID based on contact ID
  158. function getSelect()
  159. {
  160. //The combobox Id
  161. var tmpSelId = 'gex_CharId_' + _idMainChar + '_ContId_' + _idCurrentChar;
  162.  
  163. //The script that will be used to store the changings in the combobox
  164. var tmpScript = " onchange=\"storeValue('" + _idStorage + "', '" + _idCurrentChar + "', '" + tmpSelId + "')\" "
  165.  
  166. //The combobox itself
  167. var tmpSelect = "<br/><select " + tmpScript + " name=\"" + tmpSelId + "\" id=\"" + tmpSelId + "\" >";
  168.  
  169. var tmpOptions = '';
  170. for (var i=0; i < _valueCalls.length; i++)
  171. {
  172. var selected = (_valuesRunTime[_idCurrentChar] == _valueCalls[i]) ? 'selected="selected"' : ' ';
  173. tmpOptions += "<option " + selected + " value=\"" + _valueCalls[i] + "\">" + getLabel('i'+_valueCalls[i]) + "</option>";
  174. }
  175. tmpSelect += tmpOptions + "</select>";
  176.  
  177. return tmpSelect;
  178. }
  179.  
  180. //Creates the selects to be used with the contacts
  181. function getsCallSelects(){
  182. gexQuery("a[id^='ctl00_cphLeftColumn_ctl00_repAddressBook_ctl'][id$=_lnkCharacter]")
  183. .each(function()
  184. {
  185. var objId = gexQuery(this).attr('id');
  186. _idCurrentChar = getIdFromUrl(gexQuery(this).attr('href'));
  187. gexQuery(this).attr('href',_urlToCall + _idCurrentChar + _urlToCall_Token + _idMainChar);
  188. gexQuery(this).attr('target','_BLANK');
  189. var gexSelect = getSelect();
  190. gexQuery(gexSelect).insertAfter("a[id^='" + objId + "']");
  191. });
  192. }
  193.  
  194. //Executes on Phonebook page
  195. function executeOnPage_Book(){
  196. getCallButton();
  197.  
  198. loadValues();
  199.  
  200. getsCallSelects();
  201. }
  202.  
  203. function executeOnPage_Contact(){
  204.  
  205. //Exits if not to be used by this script
  206. var tmpLocation = window.location.href;
  207. if(tmpLocation.indexOf("#toCall") < 5) exit;
  208. //Gets current char Id
  209. tmpIdCurrentChar = gexQuery('.idHolder').eq(1).html();
  210.  
  211.  
  212. //Calls current char if activated
  213. var tmpAction = 9999;
  214. gexQuery("select[id='ctl00_cphTopColumn_ctl00_ddlInteractionTypes']")
  215. .each(function()
  216. {
  217. _valuesStorage = JSON.parse(window.localStorage.getItem(_idStorage));
  218. tmpAction = _valuesStorage[tmpIdCurrentChar];
  219. });
  220.  
  221. //Don't call if set to not to call
  222. if(tmpAction == 9999) exit;
  223.  
  224. //Changes the select to the right value
  225. gexQuery("select option:selected").attr("selected", false);
  226. gexQuery("select option[value='" + tmpAction + "']").attr("selected", true);
  227. gexQuery("#ctl00_cphTopColumn_ctl00_btnInteract").click();
  228. }
  229.  
  230. //Checks if the script is updated and adds a links to update if it's not
  231. function checkVersion(){
  232. if (_locVersion_SpeedCalling == GM_info.script.version) return '';
  233. return '<p><a href="https://userscripts.org/scripts/show/135489" target="_blank" style="color:red">' + getLabel('update') + '</a></p>';
  234. }