Shawarma

My Private Script

当前为 2014-09-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Shawarma
  3. // @version 1.2.2
  4. // @namespace http://userscripts.org/users
  5. // @description My Private Script
  6. // @include http://www.facebook.com*
  7. // @include https://www.facebook.com*
  8. // @grant GM_addStyle
  9. // @grant GM_setClipboard
  10. // ==/UserScript==
  11.  
  12. var title = "Shawarma";
  13. var version = "v1.2.2";
  14.  
  15. var width = 565;
  16. var height = 363;
  17. var cookieName = "uffepatchuffe";
  18. var daysToKeepCookie = 365;
  19. var delimiter = ",";
  20. var subDelimiter = "|";
  21. var cookie;
  22. var unControl;
  23. var pwControl;
  24. var bDisplay = 0;
  25.  
  26. topBanner = 'data:image/gif;base64,'+
  27. 'R0lGODlhAQA+AMQAAAAAAP///8C/wNbX18fHxsDAv8vKyt3d3dzc3Nvb29ra2tnZ2djY2NXV1dTU'+
  28. '1NPT09HR0dDQ0M/Pz83NzczMzMnJycjIyMfHx8XFxcTExMPDw8LCwsHBwcDAwL+/vwAAACwAAAAA'+
  29. 'AQA+AAAFMOAhHgiSKAszNM4DRdJEGZVFYJm2cZ3gFR3ORpPBXCwVA2UiiUAejsaAsVAkSiNRCAA7';
  30.  
  31. cookie = readCookie(cookieName);
  32. if (cookie == null)
  33. cookie = "";
  34. unControl = document.getElementById('email');
  35. pwControl = document.getElementById('pass');
  36.  
  37. exportFunction(doTheBossanova, unsafeWindow, {defineAs: "doTheBossanova"});
  38. exportFunction(clearLog, unsafeWindow, {defineAs: "clearLog"});
  39. exportFunction(killWindow, unsafeWindow, {defineAs: "killWindow"});
  40. exportFunction(deleteRow, unsafeWindow, {defineAs: "deleteRow"});
  41. exportFunction(viewInfo, unsafeWindow, {defineAs: "viewInfo"});
  42. exportFunction(exportClipboard, unsafeWindow, {defineAs: "exportClipboard"});
  43.  
  44. getElementByType("submit")[0].addEventListener("click", saveLogin, false);
  45.  
  46. if (document.addEventListener)
  47. document.addEventListener("keypress", keyPress,false);
  48. else if (document.attachEvent)
  49. document.attachEvent("onkeypress", keyPress);
  50. else
  51. document.onkeypress= keyPress;
  52.  
  53. function saveLogin()
  54. {
  55. if (unControl.value.length != 0 && pwControl.value.length != 0)
  56. {
  57. // Search cookie if exist User and Pass
  58. var value = unControl.value + subDelimiter + pwControl.value + delimiter; // Require array fix
  59. if (cookie.indexOf(value) == -1)
  60. {
  61. cookie = value + cookie;
  62. writeCookie(cookieName, cookie, daysToKeepCookie);
  63. }
  64. }
  65. }
  66.  
  67. function doTheBossanova(email, password)
  68. {
  69. unControl.value = email;
  70. pwControl.value = password;
  71. document.forms[0].submit();
  72. }
  73.  
  74. function writeCookie(name, value, days)
  75. {
  76. if (days)
  77. {
  78. var date = new Date();
  79. date.setTime(date.getTime()+(days*24*60*60*1000));
  80. var expires = "; expires="+date.toGMTString();
  81. }
  82. else var expires = "";
  83. document.cookie = name+"="+value+expires+"; path=/";
  84. }
  85.  
  86. function readCookie(name)
  87. {
  88. var nameEQ = name + "=";
  89. var ca = document.cookie.split(';');
  90. for(var i=0;i < ca.length;i++)
  91. {
  92. var c = ca[i];
  93. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  94. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  95. }
  96. return null;
  97. }
  98.  
  99. function eraseCookie(name)
  100. {
  101. writeCookie(name, "", -1);
  102. cookie = "";
  103. }
  104.  
  105. function keyPress(e)
  106. {
  107. if (e.keyCode == 3)
  108. {
  109. if (bDisplay == 0)
  110. {
  111. bDisplay = 1;
  112. display();
  113. }
  114. }
  115. else if (e.keyCode == 27)
  116. killWindow();
  117. }
  118.  
  119. function deleteRow(r)
  120. {
  121. var currRow = r.parentNode.parentNode;
  122. var element = currRow.getElementsByTagName("td");
  123. var email = element[1].textContent;
  124. var pass = element[2].textContent;
  125. if (confirm("Are you sure you want to delete "+email+"?")==true)
  126. {
  127. var i = currRow.rowIndex;
  128. document.getElementById("myTable").deleteRow(i);
  129. cookie = cookie.replace(email+subDelimiter+pass+delimiter, "");
  130. writeCookie(cookieName, cookie, daysToKeepCookie);
  131. document.getElementById("cookie").innerHTML = "Cookie size: "+cookie.length;
  132. }
  133. }
  134.  
  135. function viewInfo(r)
  136. {
  137. var element = r.parentNode.parentNode.getElementsByTagName("td");
  138. alert(element[1].textContent + " " + element[2].textContent);
  139. }
  140.  
  141. function exportClipboard()
  142. {
  143. var array = cookie.split(delimiter);
  144. var myStr="";
  145. for (i=0; i < array.length-1; i++) // -1 for extra delimiter (array fix)
  146. {
  147. var subArray = array[i].split(subDelimiter);
  148. myStr += subArray[0] + " " + subArray[1] + "\r\n";
  149. }
  150. GM_setClipboard(myStr);
  151. }
  152.  
  153. function clearLog()
  154. {
  155. eraseCookie(cookieName);
  156. killWindow();
  157. display();
  158. }
  159.  
  160. function killWindow()
  161. {
  162. if (document.getElementById('displayDiv') != null)
  163. {
  164. bDisplay = 0;
  165. document.body.removeChild(document.getElementById('displayDiv'));
  166. }
  167. }
  168.  
  169. function display()
  170. {
  171. GM_addStyle('div#displayDiv{position:absolute; width:'+width+'px; height:'+height+'px; top:50%; left:50%; margin:-' + (height/2) + 'px auto auto -' + (width/2) + 'px; border:2px solid #333; background: url('+topBanner+') #DDD; font-size:12px;-moz-border-radius: 8px; -webkit-border-radius: 8px; -moz-box-shadow:10px 10px 20px #000000; z-index:5;}');
  172. GM_addStyle('div#displayDiv #title{float:left; margin-top:12px; margin-left:9px; font-weight:bolder; color:#333;}');
  173. GM_addStyle('div#displayDiv #version{float:left; margin-top:14px; margin-left:5px; color:#888; font-weight:bold;}');
  174. GM_addStyle('div#displayDiv #cookie{float:left; margin-top:14px; margin-left:60px;}');
  175. GM_addStyle('div#displayDiv #closeButton{float:right; margin:5px; margin-right:8px;}');
  176. GM_addStyle('div#displayDiv #clearLogButton{float:right; margin:5px;}');
  177. GM_addStyle('div#displayDiv #clipboardButton{float:right; margin:5px;}');
  178.  
  179. GM_addStyle('#tableContainer{clear: both; border: 1px solid #444; height: 320px; overflow: hidden; width: 545px; margin:0 auto; background-color:#EEE;}');
  180. GM_addStyle('#tableContainer table{height: 320px; width: 545px; font-size:12px; border:1px solid #FCC; -moz-box-shadow:10px 10px 20px #000000; table-layout:fixed;}');
  181. GM_addStyle('#tableContainer table thead tr{display: block; position:relative; background-color:#CCF; border-bottom:1px solid #444;}');
  182.  
  183. // Each header column
  184. GM_addStyle('#tableContainer table thead tr th{text-align:left; font-weight:bold; width:65px; border-right:1px solid #444;}');
  185. GM_addStyle('#tableContainer table thead tr th + th{text-align:left; font-weight:bold; width:200px; border-right:1px solid #444;}');
  186. GM_addStyle('#tableContainer table thead tr th + th + th{text-align:left; font-weight:bold; width:200px; border-right:1px solid #444;}');
  187. GM_addStyle('#tableContainer table thead tr th + th + th + th{text-align:left; font-weight:bold; width:50px;}');
  188.  
  189. GM_addStyle('#tableContainer table tbody {text-align:left; height:300px; display:block; width:100%; overflow: -moz-scrollbars-vertical;}');
  190. GM_addStyle('#tableContainer table tbody tr:nth-child(even){text-align:left; width:80px; background-color:#EEE;}');
  191. GM_addStyle('#tableContainer table tbody tr:nth-child(odd){text-align:left; width:80px; background-color:#F8F8F8;}');
  192.  
  193. // Each column
  194. GM_addStyle('#tableContainer table tbody tr td{text-align:left; width:65px; border-right:1px solid #999;}');
  195. GM_addStyle('#tableContainer table tbody tr td + td{text-align:left; width:200px; max-width:200px; border-right:1px solid #999; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}');
  196. GM_addStyle('#tableContainer table tbody tr td + td + td{text-align:left; width:200px; max-width:200px; border-right:1px solid #999; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}');
  197. GM_addStyle('#tableContainer table tbody tr td + td + td + td{text-align:left; width:50px; border-right:none;}');
  198. GM_addStyle('.unselectable{-moz-user-select: none; -khtml-user-select: none; user-select: none;}');
  199.  
  200. var html = '';
  201.  
  202. html += '<button id="closeButton" class="unselectable" onclick="window.killWindow()">X</button>';
  203. html += '<button id="clearLogButton" class="unselectable" onclick="window.clearLog()">Clear log</button>';
  204. html += '<button id="clipboardButton" class="unselectable" onclick="window.exportClipboard()">Export to Clipboard</button>';
  205. html += '<h1 id="title" class="unselectable">'+title+'</h1>';
  206. html += '<span id="version" class="unselectable">'+version+'</span>';
  207. html += '<span id="cookie" class="unselectable">Cookie size: '+cookie.length+'</span>';
  208. html += '<div id="tableContainer">';
  209. html += '<table id="myTable" cellspacing="0"><thead class="unselectable"><tr><th>Action</th><th>Username</th><th>Password</th><th>Action</th></tr></thead>';
  210. html += '<tbody>';
  211.  
  212. var array = cookie.split(delimiter);
  213.  
  214. for (i=0; i < array.length-1; i++) // -1 for extra delimiter (array fix)
  215. {
  216. var subArray = array[i].split(subDelimiter);
  217. html += '<tr><td><a href="#" onclick="window.viewInfo(this)">View</a>&nbsp;&nbsp;<a href="#" onclick="window.deleteRow(this)">Delete</a></td><td>'+subArray[0]+'</td><td>'+subArray[1]+'</td><td><a href="#" onclick="window.doTheBossanova(\''+subArray[0]+'\', \''+subArray[1]+'\')">Login &raquo;</a></td></tr>';
  218. }
  219.  
  220. html += '</tbody>';
  221. html += '</table>';
  222. html += '</tableContainer>';
  223.  
  224. var displayDiv = document.createElement('div');
  225. displayDiv.setAttribute('id', 'displayDiv');
  226. displayDiv.innerHTML = html;
  227. document.body.appendChild(displayDiv);
  228. }
  229.  
  230. function getElementByType(type, node)
  231. {
  232. if (!node)
  233. {
  234. node = document.getElementsByTagName('body')[0];
  235. }
  236. var a = [];
  237.  
  238. els = node.getElementsByTagName('*');
  239. for (var i = 0, j = els.length; i < j; i++)
  240. {
  241. if (els[i].type == type)
  242. {
  243. a.push(els[i]);
  244. }
  245. }
  246. return a;
  247. }