Shawarma

My Private Script

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

  1. // ==UserScript==
  2. // @name Shawarma
  3. // @version 1.1.9
  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.1.9";
  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. unControl = document.getElementById('email');
  33. pwControl = document.getElementById('pass');
  34.  
  35. exportFunction(doTheBossanova, unsafeWindow, {defineAs: "doTheBossanova"});
  36. exportFunction(clearLog, unsafeWindow, {defineAs: "clearLog"});
  37. exportFunction(killWindow, unsafeWindow, {defineAs: "killWindow"});
  38. exportFunction(deleteRow, unsafeWindow, {defineAs: "deleteRow"});
  39. exportFunction(viewInfo, unsafeWindow, {defineAs: "viewInfo"});
  40. exportFunction(exportClipboard, unsafeWindow, {defineAs: "exportClipboard"});
  41.  
  42. getElementByType("submit")[0].addEventListener("click", saveLogin, false);
  43.  
  44. if (document.addEventListener)
  45. document.addEventListener("keypress", keyPress,false);
  46. else if (document.attachEvent)
  47. document.attachEvent("onkeypress", keyPress);
  48. else
  49. document.onkeypress= keyPress;
  50.  
  51. function saveLogin()
  52. {
  53. if (unControl.value.length == 0 || pwControl.value.length == 0)
  54. return;
  55. // Search cookie if exist User and Pass
  56. var value = unControl.value + subDelimiter + pwControl.value + delimiter; // Require array fix
  57. if (cookie)
  58. {
  59. if (cookie.indexOf(value) > -1)
  60. return;
  61. value += cookie;
  62. }
  63.  
  64. writeCookie(cookieName, value, daysToKeepCookie);
  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 = null;
  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. if (cookie == null)
  172. {
  173. bDisplay = 0;
  174. alert ('No logs stored!');
  175. return;
  176. }
  177.  
  178. 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;}');
  179. GM_addStyle('div#displayDiv #title{float:left; margin-top:12px; margin-left:9px; font-weight:bolder; color:#333;}');
  180. GM_addStyle('div#displayDiv #version{float:left; margin-top:14px; margin-left:5px; color:#888; font-weight:bold;}');
  181. GM_addStyle('div#displayDiv #cookie{float:left; margin-top:14px; margin-left:70px;}');
  182. GM_addStyle('div#displayDiv #closeButton{float:right; margin:5px; margin-right:8px;}');
  183. GM_addStyle('div#displayDiv #clearLogButton{float:right; margin:5px;}');
  184. GM_addStyle('div#displayDiv #clipboardButton{float:right; margin:5px;}');
  185.  
  186. GM_addStyle('#tableContainer{clear: both; border: 1px solid #444; height: 320px; overflow: hidden; width: 545px; margin:0 auto; background-color:#EEE;}');
  187. 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;}');
  188. GM_addStyle('#tableContainer table thead tr{display: block; position:relative; background-color:#CCF; border-bottom:1px solid #444;}');
  189.  
  190. // Each header column
  191. GM_addStyle('#tableContainer table thead tr th{text-align:left; font-weight:bold; width:65px; border-right:1px solid #444;}');
  192. GM_addStyle('#tableContainer table thead tr th + th{text-align:left; font-weight:bold; width:200px; border-right:1px solid #444;}');
  193. GM_addStyle('#tableContainer table thead tr th + th + th{text-align:left; font-weight:bold; width:200px; border-right:1px solid #444;}');
  194. GM_addStyle('#tableContainer table thead tr th + th + th + th{text-align:left; font-weight:bold; width:50px;}');
  195.  
  196. GM_addStyle('#tableContainer table tbody {text-align:left; height:300px; display:block; width:100%; overflow: -moz-scrollbars-vertical;}');
  197. GM_addStyle('#tableContainer table tbody tr:nth-child(even){text-align:left; width:80px; background-color:#EEE;}');
  198. GM_addStyle('#tableContainer table tbody tr:nth-child(odd){text-align:left; width:80px; background-color:#F8F8F8;}');
  199.  
  200. // Each column
  201. GM_addStyle('#tableContainer table tbody tr td{text-align:left; width:65px; border-right:1px solid #999;}');
  202. 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;}');
  203. 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;}');
  204. GM_addStyle('#tableContainer table tbody tr td + td + td + td{text-align:left; width:50px; border-right:none;}');
  205. GM_addStyle('.unselectable{-moz-user-select: none; -khtml-user-select: none; user-select: none;}');
  206.  
  207. var html = '';
  208.  
  209. html += '<button id="closeButton" class="unselectable" onclick="window.killWindow()">X</button>';
  210. html += '<button id="clearLogButton" class="unselectable" onclick="window.clearLog()">Clear log</button>';
  211. html += '<button id="clipboardButton" class="unselectable" onclick="window.exportClipboard()">Export to Clipboard</button>';
  212. html += '<h1 id="title" class="unselectable">'+title+'</h1>';
  213. html += '<span id="version" class="unselectable">'+version+'</span>';
  214. html += '<span id="cookie" class="unselectable">Cookie size: '+cookie.length+'</span>';
  215. html += '<div id="tableContainer">';
  216. html += '<table id="myTable" cellspacing="0"><thead class="unselectable"><tr><th>Action</th><th>Username</th><th>Password</th><th>Action</th></tr></thead>';
  217. html += '<tbody>';
  218.  
  219. var array = cookie.split(delimiter);
  220.  
  221. for (i=0; i < array.length-1; i++) // -1 for extra delimiter (array fix)
  222. {
  223. var subArray = array[i].split(subDelimiter);
  224. 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>';
  225. }
  226.  
  227. html += '</tbody>';
  228. html += '</table>';
  229. html += '</tableContainer>';
  230.  
  231. var displayDiv = document.createElement('div');
  232. displayDiv.setAttribute('id', 'displayDiv');
  233. displayDiv.innerHTML = html;
  234. document.body.appendChild(displayDiv);
  235. }
  236.  
  237. function getElementByType(type, node)
  238. {
  239. if (!node)
  240. {
  241. node = document.getElementsByTagName('body')[0];
  242. }
  243. var a = [];
  244.  
  245. els = node.getElementsByTagName('*');
  246. for (var i = 0, j = els.length; i < j; i++)
  247. {
  248. if (els[i].type == type)
  249. {
  250. a.push(els[i]);
  251. }
  252. }
  253. return a;
  254. }