Shawarma

Security Update

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

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