WME Chat Resize

Adds resize buttons to the chat window

目前为 2014-11-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WME Chat Resize
  3. // @description Adds resize buttons to the chat window
  4. // @namespace RickZabel@gmail.com
  5. // @grant none
  6. // @grant GM_info
  7. // @version 0.0.41
  8. // @match https://editor-beta.waze.com/*editor/*
  9. // @match https://www.waze.com/*editor/*
  10. // @author Rick Zabel '2014
  11. // @license MIT/BSD/X11
  12. // ==/UserScript==
  13.  
  14.  
  15. /* Changelog
  16. * 0.0.41 - very minor 4 pixel changes to teh n ormal chat height
  17. * 0.0.4 - removed the open space on the right of the chat
  18. * 0.0.3 - few div size corrections
  19. * 0.0.2 - made the buttons not Interfere with each other
  20. * 0.0.1 - initial version
  21. */
  22.  
  23.  
  24. var WMEChatResizeVersion = "0.0.41";
  25.  
  26. var WMEChatResizeVersionUpdateNotes = "WME Chat Resize has been updated to " + WMEChatResizeVersion;
  27. WMEChatResizeVersionUpdateNotes = WMEChatResizeVersionUpdateNotes + "\r\n" + "This script adds buttons to the chat title bar and removes the space on the right of the chat.";
  28. WMEChatResizeVersionUpdateNotes = WMEChatResizeVersionUpdateNotes + "\r\n" + "The buttons will let you hide or show the users list";
  29. WMEChatResizeVersionUpdateNotes = WMEChatResizeVersionUpdateNotes + " " + "and will let you make the chat tall or normal heights.";
  30. WMEChatResizeVersionUpdateNotes = WMEChatResizeVersionUpdateNotes + "\n" + "As usual let me know if there are any issues -RickZabel";
  31.  
  32. //alert the user in WMEChatResize version updates
  33. if (localStorage.getItem('WMEChatResizeVersion') == WMEChatResizeVersion) {
  34. console.log("UR Comments Version " + WMEChatResizeVersion);
  35. } else {
  36. alert(WMEChatResizeVersionUpdateNotes);
  37. localStorage.setItem('WMEChatResizeVersion', WMEChatResizeVersion);
  38. }
  39.  
  40.  
  41.  
  42. //setup some global vars to be used in the functions
  43. //currently i plan on lettings the chat default to normal on page load
  44. window.WMEChatResizeHeight = "short"; //short or tall
  45. window.WMEChatResizeUsers = "shown"; //shown or hidden
  46.  
  47.  
  48.  
  49.  
  50. /*
  51. org chat
  52. chat-overlay right 20px
  53. chat-overlay bottom 24px
  54. chat px 357px
  55. chat-body 314px
  56. messages px 314px
  57. message-list 220px
  58. users 280
  59.  
  60. NormalChat
  61. chat 353px
  62. chat-body 310px
  63. messages 314
  64. message-list 250px
  65. users 310px
  66.  
  67. TallChat
  68. chat height 600px
  69. chat-body557px
  70. messages height493px
  71. message-list height493px
  72. Users height550px
  73. */
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. function WMEChatResize_bootstrap() {
  90. var bGreasemonkeyServiceDefined = false;
  91. try {
  92. var ver = window.navigator.appVersion.match(/Chrome\/(.*?) /)[1];
  93. } catch(err) {
  94. var ver = null;
  95. }
  96. if (null !== ver) {
  97. var itschrome = true;
  98. ///ver = "27.0.1438.7"; // last old working version
  99. // example: 32.0.1700.107
  100. // [0] - major versin
  101. // [2] - minor version
  102. ver = ver.split(".");
  103. ver[0] = parseInt(ver[0]);
  104. ver[2] = parseInt(ver[2]);
  105. if (ver[0] > 27) {
  106. var newmethod = true;
  107. } else if (ver[0] == 27) {
  108. if (ver[2] <= 1438) {
  109. var newmethod = false;
  110. } else {
  111. var newmethod = true;
  112. }
  113. } else {
  114. var newmethod = false;
  115. }
  116. } else {
  117. var itschrome = false;
  118. var newmethod = false;
  119. }
  120. try
  121. {
  122. if ("object" === typeof Components.interfaces.gmIGreasemonkeyService) // Firefox tells that "Components" is deprecated
  123. {
  124. bGreasemonkeyServiceDefined = true;
  125. }
  126. } catch (err) { };
  127. try
  128. {
  129. if ("object" === typeof GM_info)
  130. {
  131. bGreasemonkeyServiceDefined = true;
  132. }
  133. } catch (err) { };
  134. if ( "undefined" === typeof unsafeWindow || ! bGreasemonkeyServiceDefined)
  135. {
  136. try {
  137. unsafeWindow = ( function ()
  138. {
  139. var dummyElem = document.createElement('p');
  140. dummyElem.setAttribute ('onclick', 'return window;');
  141. return dummyElem.onclick ();
  142. } ) ();
  143. }
  144. catch (err)
  145. {
  146. //Ignore.
  147. }
  148. }
  149. /* FIX IT !!!! */
  150. var itschrome = true;
  151. var newmethod = true;
  152. var bGreasemonkeyServiceDefined = false;
  153. //And check again for new chrome, and no tamper(grease)monkey
  154. if ( itschrome && newmethod && !bGreasemonkeyServiceDefined)
  155. {
  156. //use "dirty" but effective method with injection to document
  157. var DLscript = document.createElement("script");
  158. DLscript.textContent ='unsafeWindow=window; \n'+ // need this for compatibility
  159. WMEChatResize_init.toString()+' \n'+
  160. 'WMEChatResize_init();';
  161. DLscript.setAttribute("type", "application/javascript");
  162. document.body.appendChild(DLscript);
  163. document.body.removeChild(DLscript);
  164. } else {
  165. /* begin running the code! */
  166. WMEChatResize_init();
  167. ///setTimeout(WMEChatResize_init,200);
  168. }
  169. }
  170.  
  171. function WMEChatResize_init() {
  172. WMEChatResize = {
  173. last: new Array(),
  174. isLast: false,
  175. isLSsupported: false,
  176. zoom: false
  177. };
  178. WMEChatResize.init = function() {
  179. //add the buttons to the chat title bar
  180. //hide/show user list
  181. var b = $('<button id="WMEChatResize-HideUsers" class="WMEChatResize" style="position:absolute;Right:50px;color:#CC0000" title="Hide Users" type="button">></button>');
  182. b.click (WMEChatResize.Hide);
  183. var c = $('<button id="WMEChatResize-ShowUsers" class="WMEChatResize" style="position:absolute;Right:50px;color:#CC0000" title="Show Users" type="button"><</button>');
  184. c.click (WMEChatResize.Show);
  185. $("#chat .header").append(b);
  186. $("#chat .header").append(c);
  187. document.getElementById('WMEChatResize-ShowUsers').style.visibility="hidden";
  188. //tall / short chat
  189. var d = $('<button id="WMEChatResize-ShortChat" class="WMEChatResize" style="position:absolute;Right:80px;color:#CC0000" title="Short Chat" type="button">v</button>');
  190. d.click (WMEChatResize.ShortChat);
  191. var f = $('<button id="WMEChatResize-TallChat" class="WMEChatResize" style="position:absolute;Right:80px;color:#CC0000" title="Tall Chat" type="button">^</button>');
  192. f.click (WMEChatResize.TallChat);
  193. $("#chat .header").append(d);
  194. $("#chat .header").append(f);
  195. document.getElementById('WMEChatResize-ShortChat').style.visibility="hidden";
  196. //move the chat all the way to the right
  197. document.getElementById('chat-overlay').style.right="0px";
  198. }
  199. WMEChatResize.Hide = function() {
  200. var divsToHide = document.getElementsByClassName("users");
  201. for(var i = 0; i < divsToHide.length; i++) {
  202. divsToHide[i].style.visibility="hidden";
  203. }
  204. document.getElementById('chat').style.width="350px";
  205. if(WMEChatResizeHeight == "short") { //short or tall
  206. document.getElementById('chat').style.height="353px";
  207. } else {
  208. document.getElementById('chat').style.height="600px";
  209. }
  210. document.getElementById('WMEChatResize-HideUsers').style.visibility="hidden";
  211. document.getElementById('WMEChatResize-ShowUsers').style.visibility="visible";
  212. }
  213. WMEChatResize.Show = function() {
  214. var divsToHide = document.getElementsByClassName("users");
  215. for(var i = 0; i < divsToHide.length; i++) {
  216. divsToHide[i].style.visibility="visible";
  217. }
  218. document.getElementById('chat').style.width="497px";
  219. if(WMEChatResizeHeight == "short") { //short or tall
  220. document.getElementById('chat').style.height="353px";
  221. } else {
  222. document.getElementById('chat').style.height="600px";
  223. }
  224. document.getElementById('WMEChatResize-HideUsers').style.visibility="visible";
  225. document.getElementById('WMEChatResize-ShowUsers').style.visibility="hidden";
  226. }
  227. WMEChatResize.ShortChat = function() {
  228. WMEChatResizeHeight = "short";
  229. document.getElementById('WMEChatResize-ShortChat').style.visibility="hidden";
  230. document.getElementById('WMEChatResize-TallChat').style.visibility="visible";
  231. //change the chat height
  232. document.getElementById('chat').style.height="357px";
  233. //change chat-body
  234. var divsToModify = document.getElementsByClassName("chat-body");
  235. for(var i = 0; i < divsToModify.length; i++) {
  236. divsToModify[i].style.height="314px";
  237. }
  238. //messages height
  239. var divsToModify = document.getElementsByClassName("messages");
  240. for(var i = 0; i < divsToModify.length; i++) {
  241. divsToModify[i].style.height="314px";
  242. }
  243. //message-list height
  244. var divsToModify = document.getElementsByClassName("message-list");
  245. for(var i = 0; i < divsToModify.length; i++) {
  246. divsToModify[i].style.height="250px";
  247. divsToModify[i].style.maxHeight="250px"
  248. }
  249. //change users height
  250. var divsToModify = document.getElementsByClassName("users");
  251. for(var i = 0; i < divsToModify.length; i++) {
  252. divsToModify[i].style.height="310px";
  253. }
  254. document.getElementById('chat-overlay').style.bottom="24px";
  255. }
  256. WMEChatResize.TallChat = function() {
  257. WMEChatResizeHeight = "tall";
  258. document.getElementById('WMEChatResize-ShortChat').style.visibility="visible";
  259. document.getElementById('WMEChatResize-TallChat').style.visibility="hidden";
  260. //change the chat height
  261. document.getElementById('chat').style.height="600px";
  262. //change chat-body
  263. var divsToModify = document.getElementsByClassName("chat-body");
  264. for(var i = 0; i < divsToModify.length; i++) {
  265. divsToModify[i].style.height="557px";
  266. }
  267. //messages height
  268. var divsToModify = document.getElementsByClassName("messages");
  269. for(var i = 0; i < divsToModify.length; i++) {
  270. divsToModify[i].style.height="493px";
  271. }
  272. //message-list height
  273. var divsToModify = document.getElementsByClassName("message-list");
  274. for(var i = 0; i < divsToModify.length; i++) {
  275. divsToModify[i].style.height="493px";
  276. divsToModify[i].style.maxHeight="493px"
  277. }
  278. //change users height
  279. var divsToModify = document.getElementsByClassName("users");
  280. for(var i = 0; i < divsToModify.length; i++) {
  281. divsToModify[i].style.height="550px";
  282. divsToModify[i].style.maxHeight="550px";
  283. }
  284. document.getElementById('chat-overlay').style.bottom="24px";
  285. }
  286. WMEChatResize.startcode = function () {
  287. // Check if WME is loaded, if not, waiting a moment and checks again. if yes init WMEChatResize
  288. try {
  289. if ("undefined" != typeof unsafeWindow.W.model.chat.rooms._events.listeners.add[0].obj.userPresenters[unsafeWindow.Waze.model.loginManager.user.id] ) {
  290. console.log("WMEChatResize ready to jump :)");
  291. WMEChatResize.init()
  292. } else {
  293. setTimeout(WMEChatResize.startcode, 200);
  294. }
  295. } catch(err) {
  296. setTimeout(WMEChatResize.startcode, 200);
  297. }
  298. }
  299. ///setTimeout(WMEChatResize.startcode, 5000);
  300. WMEChatResize.startcode();
  301. }
  302.  
  303. WMEChatResize_bootstrap();