Advertisement
Guest User

Untitled

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