Shawarma

My Private Script

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

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