Advertisement
Guest User

Greasy Fork Script - Do not need Cookies ON

a guest
Mar 14th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.80 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Greasy Fork
  3. // @version 1.0.0
  4. // @description Enhancement for greasyfork.org site
  5. // @author Sonny Razzano
  6. // @namespace srazzano.com
  7. // @license CC by-nc-sa http://creativecommons.org/licenses/by-nc-sa/3.0/
  8. // @include https://greasyfork.org*
  9. // @grant none
  10. // ==/UserScript==
  11. // ********************** CUSTOMIZE TEXT **********************
  12. var sv_1 = '#';
  13. var sv_2 = 'Name';
  14. var sv_3 = 'Description';
  15. var sv_4 = 'Author';
  16. var sv_5 = 'Daily';
  17. var sv_6 = 'Total';
  18. var sv_7 = 'Created';
  19. var sv_8 = 'Updated';
  20. // ******************** END CUSTOMIZE TEXT ********************
  21. (function () {
  22. testGM();
  23. function testGM() {
  24. constSTORAGE_PREFIX = 'ustoe-';
  25. constLOG_PREFIX = 'greasyfork.org Enhancer: ';
  26. constLOG = true;
  27. constDEBUG = false;
  28. isGM = typeof GM_getValue != 'undefined' && typeof GM_getValue('a', 'b') != 'undefined';
  29. log = isGM ? function (msg) {
  30. if (LOG) GM_log(msg)
  31. }
  32. : window.opera ? function (msg) {
  33. if (LOG) opera.postError(LOG_PREFIX + msg)
  34. }
  35. : function (msg) {
  36. try {
  37. if (LOG) console.log(LOG_PREFIX + msg)
  38. } catch (e) {}
  39. }
  40. debug = function (msg) {
  41. if (LOG && DEBUG) log('** Debug: ' + msg + ' **')
  42. }
  43. addStyle = isGM ? GM_addStyle : function (css) {
  44. var head = $('head') [0];
  45. if (!head) return ;
  46. var style = $c('style', {
  47. type: 'text/css',
  48. innerHTML: css
  49. });
  50. head.appendChild(style)
  51. }
  52. setValue = isGM ? GM_setValue : function (name, value) {
  53. switch (typeof (value)) {
  54. case 'string':
  55. localStorage.setItem(STORAGE_PREFIX + name, 'S]' + value);
  56. break;
  57. case 'number':
  58. if (value.toString() .indexOf('.') < 0) {
  59. localStorage.setItem(STORAGE_PREFIX + name, 'N]' + value)
  60. }
  61. break;
  62. case 'boolean':
  63. localStorage.setItem(STORAGE_PREFIX + name, 'B]' + value);
  64. break
  65. } }
  66. getValue = isGM ? GM_getValue : function (name, defValue) {
  67. var value = localStorage.getItem(STORAGE_PREFIX + name);
  68. if (value == null) {
  69. return defValue
  70. } else {
  71. switch (value.substr(0, 2)) {
  72. case 'S]':
  73. return value.substr(2);
  74. case 'N]':
  75. return parseInt(value.substr(2));
  76. case 'B]':
  77. return value.substr(2) == 'true';
  78. } }
  79. return value
  80. }
  81. deleteValue = isGM ? GM_deleteValue : function (name) {
  82. localStorage.removeItem(STORAGE_PREFIX + name)
  83. }
  84. xhr = isGM ? GM_xmlhttpRequest : function (obj) {
  85. var request = new XMLHttpRequest();
  86. request.onreadystatechange = function () {
  87. if (obj.onreadystatechange) {
  88. obj.onreadystatechange(request)
  89. };
  90. if (request.readyState == 4 && obj.onload) {
  91. obj.onload(request)
  92. } }
  93. request.onerror = function () {
  94. if (obj.onerror) {
  95. obj.onerror(request)
  96. } }
  97. try {
  98. request.open(obj.method, obj.url, true)
  99. } catch (e) {
  100. if (obj.onerror) {
  101. obj.onerror({
  102. readyState: 4,
  103. responseHeaders: '',
  104. responseText: '',
  105. responseXML: '',
  106. status: 403,
  107. statusText: 'Forbidden'
  108. })
  109. };
  110. return
  111. }
  112. if (obj.headers) {
  113. for (name in obj.headers) {
  114. request.setRequestHeader(name, obj.headers[name])
  115. } }
  116. request.send(obj.data);
  117. return request;
  118. } }
  119.  
  120. var scriptID = 'greasyfork';
  121. var version = '1.0.0';
  122. var url = window.location.href.toLowerCase();
  123. var onScriptPage = url.match(/^https?:\/\/greasyfork\.org\/scripts/);
  124. var onUserPage = url.match(/^https?:\/\/greasyfork\.org\/users\/\d+/);
  125. var scriptList = onScriptPage ? $('#browse-script-list') : $('#user-script-list');
  126. var scriptArray = [];
  127. var scripts = $('li', scriptList);
  128. var scriptCount = scripts.length;
  129.  
  130. addStyle('\
  131. #script-table {-moz-user-select: none; border-collapse: separate !important; border-spacing: 0 !important;}\
  132. #script-table tr > #header2,\
  133. #script-table tr > #header4 {text-align: left;}\
  134. #script-table tr > #header1,\
  135. #script-table tr > #header2,\
  136. #script-table tr > #header4,\
  137. #script-table tr > #header5,\
  138. #script-table tr > #header6,\
  139. #script-table tr > #header7,\
  140. #script-table tr > #header8 {cursor: pointer;}\
  141. #script-table tr > #header3 {cursor: default; text-align: left;}\
  142. #script-table tr > td {}\
  143. #script-table tr > td:nth-child(1),\
  144. #script-table tr > td:nth-child(5),\
  145. #script-table tr > td:nth-child(6),\
  146. #script-table tr > td:nth-child(7),\
  147. #script-table tr > td:nth-child(8) {cursor: default;}\
  148. #script-table tr > td:nth-child(1),\
  149. #script-table tr > td:nth-child(5),\
  150. #script-table tr > td:nth-child(6),\
  151. #script-table tr > td:nth-child(7),\
  152. #script-table tr > td:nth-child(8) {text-align: center;}\
  153. #script-table tr > td:nth-child(2),\
  154. #script-table tr > td:nth-child(3) {cursor: default; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}\
  155. #script-table tr > td:nth-child(1) {width: 44px;}\
  156. #script-table tr > td:nth-child(2) {width: 25%;}\
  157. #script-table tr > td:nth-child(3) {width: 50%;}\
  158. #script-table tr > td:nth-child(4) {width: 180px;}\
  159. #script-table tr > td:nth-child(5),\
  160. #script-table tr > td:nth-child(6) {width: 60px;}\
  161. #script-table tr > td:nth-child(7),\
  162. #script-table tr > td:nth-child(8) {width: 120px;}\
  163. #script-table tr > td:nth-child(2) a,\
  164. #script-table tr > td:nth-child(4) a {display: block !important;}\
  165. ');
  166.  
  167. if(onUserPage) {
  168. addStyle('\
  169. #script-table tr > #header4,\
  170. #script-table tr > td:nth-child(4) {text-align: center;}\
  171. #script-table tr > td:nth-child(4) {cursor: default;}\
  172. #script-table tr > td:nth-child(4),\
  173. #script-table tr > td:nth-child(5) {width: 60px;}\
  174. ')
  175. }
  176.  
  177. function $(q, root, single, context) {
  178. root = root || document;
  179. context = context || root;
  180. if (q[0] == '#') return root.getElementById(q.substr(1));
  181. if (q.match(/^[\/*]|^\.[\/\.]/)) {
  182. if (single) return root.evaluate(q, context, null, 9, null) .singleNodeValue;
  183. var arr = [];
  184. var xpr = root.evaluate(q, context, null, 7, null);
  185. for (var i = 0; i < xpr.snapshotLength; i++) arr.push(xpr.snapshotItem(i));
  186. return arr;
  187. }
  188. if (q[0] == '.') {
  189. if (single) return root.getElementsByClassName(q.substr(1)) [0];
  190. return root.getElementsByClassName(q.substr(1));
  191. }
  192. if (single) return root.getElementsByTagName(q) [0];
  193. return root.getElementsByTagName(q);
  194. }
  195.  
  196. function $c(type, props, evls) {
  197. var node = document.createElement(type);
  198. if (props && typeof props == 'object') {
  199. for (prop in props) {
  200. if (typeof node[prop] == 'undefined') node.setAttribute(prop, props[prop]);
  201. else node[prop] = props[prop];
  202. } }
  203. if (evls instanceof Array) {
  204. for (var i = 0; i < evls.length; i++) {
  205. var evl = evls[i];
  206. if (typeof evl.type == 'string' && typeof evl.fn == 'function') node.addEventListener(evl.type, evl.fn, false);
  207. } }
  208. return node;
  209. }
  210.  
  211. function toCustStr(num) {
  212. return num.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ',');
  213. }
  214.  
  215. String.prototype.toCustNum = function () {
  216. return parseFloat(this.replace(',', ''));
  217. }
  218.  
  219. function insertAfter(newNode, refNode) {
  220. if (refNode.nextSibling) return refNode.parentNode.insertBefore(newNode, refNode.nextSibling);
  221. else return refNode.parentNode.appendChild(newNode);
  222. }
  223.  
  224. function remove(node) {
  225. if (node) node.parentNode.removeChild(node);
  226. }
  227.  
  228. function ucFirst(str) {
  229. var firstLetter = str.slice(0, 1);
  230. return firstLetter.toUpperCase() + str.substring(1);
  231. }
  232.  
  233. function capAll(str) {
  234. var words = str.toLowerCase() .split(' ');
  235. for (var i = 0; i < words.length; i++) {
  236. var wd = words[i],
  237. first = wd.substr(0, 1),
  238. rest = wd.substr(1, wd.length - 1);
  239. words[i] = first.toUpperCase() + rest;
  240. }
  241. return words.join(' ');
  242. }
  243.  
  244. for(var i = 0; i < scriptCount; i++) {
  245. var scriptObj = {};
  246. var script = scripts[i];
  247. var link = $('a', script, 1);
  248. var desc = $('p', script, 1);
  249. var auth = $('dd', script, 1);
  250. var num = $('dd', script);
  251. scriptObj.name = link.textContent;
  252. scriptObj.nhref = link.href;
  253. scriptObj.description = desc.textContent;
  254. scriptObj.author = auth.textContent;
  255. scriptObj.ahref = auth.lastChild.href;
  256. scriptObj.daily = num[1].textContent;
  257. scriptObj.total = num[2].textContent;
  258. scriptObj.created = num[3].textContent;
  259. scriptObj.updated = num[4].textContent;
  260. scriptArray.push(scriptObj);
  261. }
  262.  
  263. var scriptTable = $c('table', {id:'script-table'});
  264. var scriptTableHeaderRow = $c('tr');
  265. if(onScriptPage) var theaders = [sv_1, sv_2, sv_3, sv_4, sv_5, sv_6, sv_7, sv_8];
  266. else var theaders = [sv_1, sv_2, sv_3, sv_5, sv_6, sv_7, sv_8];
  267. for(var i = 0; i < theaders.length; i++) scriptTableHeaderRow.appendChild($c('th', {id:'header' + (i+1), className:'header', textContent:theaders[i]}));
  268. scriptTable.appendChild(scriptTableHeaderRow);
  269.  
  270. for(var i = 0; i < scriptArray.length; i++) {
  271. var script = scriptArray[i], row = $c('tr');
  272. row.appendChild($c('td', {textContent:(i + 1)}));
  273. var cellN = $c('td');
  274. cellN.appendChild($c('a', {href:script.nhref, textContent:script.name, title:script.name}));
  275. var cellDe = $c('td', {textContent:script.description, title:script.description});
  276. if(onScriptPage) {
  277. var cellA = $c('td');
  278. cellA.appendChild($c('a', {href:script.ahref, textContent:script.author}));
  279. }
  280. var cellDa = $c('td', {textContent:script.daily});
  281. var cellT = $c('td', {textContent:script.total});
  282. var cellC = $c('td', {textContent:script.created});
  283. var cellU = $c('td', {textContent:script.updated});
  284. row.appendChild(cellN);
  285. row.appendChild(cellDe);
  286. if(onScriptPage) row.appendChild(cellA);
  287. row.appendChild(cellDa);
  288. row.appendChild(cellT);
  289. row.appendChild(cellC);
  290. row.appendChild(cellU);
  291. scriptTable.appendChild(row);
  292. }
  293.  
  294. var tableContainer = $c('div', {id:'table-container'});
  295. tableContainer.appendChild(scriptTable);
  296. scriptList.parentNode.replaceChild(tableContainer, scriptList);
  297.  
  298. var th = $('th', scriptTable);
  299. for(var i = 0; i < th.length; i++) {
  300. th[i].addEventListener('click', function(e) {
  301. if(e.target.nodeName == 'TH' && e.target.textContent != sv_3)
  302. sortTable(e.target);
  303. },false);
  304. }
  305.  
  306. var colIndex = 0;
  307.  
  308. function sortTable(source) {
  309. var table = source;
  310. while(table.nodeName.toLowerCase() != 'table') {table = table.parentNode}
  311. var newRows = [];
  312. for(var i = 0; i < table.rows.length - 1; i++) {newRows[i] = table.rows[i + 1]}
  313. if(colIndex == source.cellIndex) newRows.reverse();
  314. else {
  315. colIndex = source.cellIndex;
  316. var cell = table.rows[1].cells[colIndex].textContent;
  317. if(colIndex == 0) newRows.sort(sortF);
  318. else newRows.sort(sortT);
  319. }
  320. function sortR(a, b) {
  321. return a.localeCompare(b);
  322. }
  323. function sortF(a, b) {
  324. var res = a.cells[colIndex].textContent.toCustNum() - b.cells[colIndex].textContent.toCustNum();
  325. if(res == 0) {
  326. var index = (colIndex == 2) ? 3 : 2;
  327. res = a.cells[index].textContent.toCustNum() - b.cells[index].textContent.toCustNum();
  328. }
  329. if(res == 0) res = sortR(a, b);
  330. return res;
  331. }
  332. function sortT(a, b) {
  333. a = a.cells[colIndex].textContent.toLowerCase();
  334. b = b.cells[colIndex].textContent.toLowerCase();
  335. return a.localeCompare(b);
  336. }
  337. for(var i = 0; i < newRows.length; i++) {table.appendChild(newRows[i])}
  338. }
  339. }) ();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement