Greasy Fork tweaks

opens pages of scripts from lists in a new tab and makes the user interface more compact, informative and interactive

目前为 2020-05-29 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Greasy Fork tweaks
  3. // @namespace almaceleste
  4. // @version 0.3.5
  5. // @description opens pages of scripts from lists in a new tab and makes the user interface more compact, informative and interactive
  6. // @description:ru открывает страницы скриптов из списков в новой вкладке и делает пользовательский интерфейс более компактным, информативным и интерактивным
  7. // @author (ɔ) almaceleste (https://almaceleste.github.io)
  8. // @license AGPL-3.0-or-later; http://www.gnu.org/licenses/agpl.txt
  9. // @icon https://greasyfork.org/assets/blacklogo16-bc64b9f7afdc9be4cbfa58bdd5fc2e5c098ad4bca3ad513a27b15602083fd5bc.png
  10. // @icon64 https://greasyfork.org/assets/blacklogo96-e0c2c76180916332b7516ad47e1e206b42d131d36ff4afe98da3b1ba61fd5d6c.png
  11.  
  12. // @homepageURL https://greasyfork.org/en/users/174037-almaceleste
  13. // @homepageURL https://openuserjs.org/users/almaceleste
  14. // @homepageURL https://github.com/almaceleste/userscripts
  15. // @supportURL https://github.com/almaceleste/userscripts/issues
  16.  
  17. // @require https://code.jquery.com/jquery-3.3.1.js
  18. // @require https://code.jquery.com/ui/1.12.1/jquery-ui.js
  19. // @require https://openuserjs.org/src/libs/sizzle/GM_config.js
  20. // @grant GM_getValue
  21. // @grant GM_setValue
  22. // @grant GM_registerMenuCommand
  23. // @grant GM_openInTab
  24.  
  25. // @match https://greasyfork.org/*/users/*
  26. // @match https://greasyfork.org/*/scripts*
  27. // ==/UserScript==
  28.  
  29. // ==OpenUserJS==
  30. // @author almaceleste
  31. // ==/OpenUserJS==
  32.  
  33. const listitem = '.script-list li';
  34. const separator = '.name-description-separator';
  35. const scriptversion = 'data-script-version';
  36. const scriptstats = '.inline-script-stats';
  37. const dailyinstalls = '.script-list-daily-installs';
  38. const totalinstalls = '.script-list-total-installs';
  39. const createddate = '.script-list-created-date';
  40. const updateddate = '.script-list-updated-date';
  41. const userprofile = '#user-profile';
  42. const controlpanel = '#control-panel';
  43. const discussions = '#user-discussions-on-scripts-written';
  44. const scriptsets = 'h3:contains("Script Sets")';
  45.  
  46. const configId = 'greasyforktweaksCfg';
  47. const windowcss = `
  48. #${configId} {
  49. background-color: darkslategray;
  50. color: whitesmoke;
  51. }
  52. #${configId} a,
  53. #${configId} button,
  54. #${configId} input,
  55. #${configId} select,
  56. #${configId} select option,
  57. #${configId} .section_desc {
  58. color: whitesmoke !important;
  59. }
  60. #${configId} a,
  61. #${configId} button,
  62. #${configId} input,
  63. #${configId} .section_desc {
  64. font-size: .8em !important;
  65. }
  66. #${configId} button,
  67. #${configId} input,
  68. #${configId} select,
  69. #${configId} select option,
  70. #${configId} .section_desc {
  71. background-color: #333;
  72. border: 1px solid #222;
  73. }
  74. #${configId} button{
  75. height: 1.65em !important;
  76. }
  77. #${configId}_header {
  78. font-size: 1.3em !important;
  79. }
  80. #${configId}.section_header {
  81. background-color: #454545;
  82. border: 1px solid #222;
  83. font-size: 1em !important;
  84. }
  85. #${configId} .field_label {
  86. font-size: .7em !important;
  87. }
  88. #${configId}_buttons_holder {
  89. position: fixed;
  90. width: 97%;
  91. bottom: 0;
  92. }
  93. #${configId} .reset_holder {
  94. float: left;
  95. position: relative;
  96. bottom: -1em;
  97. }
  98. #${configId} .saveclose_buttons {
  99. margin: .7em;
  100. }
  101. #${configId}_field_support {
  102. background: none !important;
  103. border: none !important;
  104. cursor: pointer !important;
  105. padding: 0 !important;
  106. text-decoration: underline !important;
  107. }
  108. #${configId}_field_support:hover,
  109. #${configId}_resetLink:hover {
  110. filter: drop-shadow(0 0 1px dodgerblue);
  111. }
  112. `;
  113. const iframecss = `
  114. height: 435px;
  115. width: 435px;
  116. border: 1px solid;
  117. border-radius: 3px;
  118. position: fixed;
  119. z-index: 9999;
  120. `;
  121.  
  122. GM_registerMenuCommand(`${GM_info.script.name} Settings`, () => {
  123. GM_config.open();
  124. GM_config.frame.style = iframecss;
  125. });
  126.  
  127. GM_config.init({
  128. id: `${configId}`,
  129. title: `${GM_info.script.name} ${GM_info.script.version}`,
  130. fields: {
  131. version: {
  132. section: ['', 'Script list options (own and other pages)'],
  133. label: 'add script version number in the list of scripts',
  134. labelPos: 'right',
  135. type: 'checkbox',
  136. default: true,
  137. },
  138. compact: {
  139. label: 'compact script information',
  140. labelPos: 'right',
  141. type: 'checkbox',
  142. default: true,
  143. },
  144. userprofile: {
  145. section: ['', 'User page options (own page and other users`)'],
  146. label: 'collapse user profile info on user page',
  147. labelPos: 'right',
  148. type: 'checkbox',
  149. default: true,
  150. },
  151. controlpanel: {
  152. label: 'collapse control panel on user page',
  153. labelPos: 'right',
  154. type: 'checkbox',
  155. default: true,
  156. },
  157. discussions: {
  158. label: 'collapse discussions on user page',
  159. labelPos: 'right',
  160. type: 'checkbox',
  161. default: true,
  162. },
  163. scriptsets: {
  164. label: 'collapse script sets on user page',
  165. labelPos: 'right',
  166. type: 'checkbox',
  167. default: true,
  168. },
  169. newtab: {
  170. section: ['', 'Other options'],
  171. label: 'open script page in new tab',
  172. labelPos: 'right',
  173. type: 'checkbox',
  174. default: true,
  175. },
  176. background: {
  177. label: 'open new tab in background',
  178. labelPos: 'right',
  179. type: 'checkbox',
  180. default: false,
  181. },
  182. insert: {
  183. label: 'insert new tab next to the current instead of the right end',
  184. labelPos: 'right',
  185. type: 'checkbox',
  186. default: true,
  187. },
  188. setParent: {
  189. label: 'return to the current tab after new tab closed',
  190. labelPos: 'right',
  191. type: 'checkbox',
  192. default: true,
  193. },
  194. support: {
  195. section: ['', 'Support'],
  196. label: 'almaceleste.github.io',
  197. title: 'more info on almaceleste.github.io',
  198. type: 'button',
  199. click: () => {
  200. GM_openInTab('https://almaceleste.github.io', {
  201. active: true,
  202. insert: true,
  203. setParent: true
  204. });
  205. }
  206. },
  207. },
  208. css: windowcss,
  209. events: {
  210. save: function() {
  211. GM_config.close();
  212. }
  213. },
  214. });
  215.  
  216. function collapse(element){
  217. const arrow = $(`
  218. <svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
  219. <style>
  220. .collapsed {
  221. transform: rotate(0deg);
  222. }
  223. .expanded {
  224. transform: rotate(180deg);
  225. }
  226. </style>
  227. <text x='0' y='18'>▼</text>
  228. </svg>
  229. `).css({
  230. fill: 'whitesmoke',
  231. height: '20px',
  232. width: '30px',
  233. });
  234.  
  235. $(element).css({
  236. cursor: 'pointer',
  237. })
  238. .find('header h3').append(arrow);
  239. $(element).accordion({
  240. collapsible: true,
  241. active: false,
  242. beforeActivate: () => {
  243. if ($(arrow).hasClass('expanded')) {
  244. $(arrow).animate({
  245. transform: 'rotate(0deg)',
  246. });
  247. }
  248. else {
  249. $(arrow).animate({
  250. transform: 'rotate(180deg)',
  251. });
  252. }
  253. $(arrow).toggleClass('expanded');
  254. }
  255. });
  256. }
  257.  
  258. (function() {
  259. 'use strict';
  260.  
  261. const options = {active: !GM_config.get('background'), insert: GM_config.get('insert'), setParent: GM_config.get('setParent')};
  262.  
  263. if (GM_config.get('version')){
  264. $(listitem).each(function(){
  265. $(this).find(separator).after(($(this).attr(scriptversion)));
  266. });
  267. }
  268. if (GM_config.get('compact')){
  269. $(scriptstats).children().css('width','auto');
  270. $('dt' + totalinstalls).each(function(){
  271. $(this).css('display','none');
  272. $(this).siblings('dt' + dailyinstalls).find('span').append(' (' + $(this).find('span').text() + ')');
  273. });
  274. $('dd' + totalinstalls).each(function(){
  275. $(this).css('display','none');
  276. $(this).siblings('dd' + dailyinstalls).find('span').append(' (' + $(this).find('span').text() + ')');
  277. });
  278. $('dt' + updateddate).each(function(){
  279. $(this).css('display','none');
  280. $(this).siblings('dt' + createddate).find('span').append(' (' + $(this).find('span').text() + ')');
  281. });
  282. $('dd' + updateddate).each(function(){
  283. $(this).css('display','none');
  284. $(this).siblings('dd' + createddate).find('span').append(' (' + $(this).find('span').text() + ')');
  285. });
  286. }
  287. if (GM_config.get('userprofile')){
  288. $(userprofile).parent().children('h2')
  289. .append('<span>▼</span>')
  290. .click(function(){
  291. $(userprofile).slideToggle();
  292. })
  293. $(userprofile).slideUp();
  294. }
  295. if (GM_config.get('controlpanel')){
  296. collapse(controlpanel);
  297. }
  298. if (GM_config.get('discussions')){
  299. collapse(discussions);
  300. }
  301. if (GM_config.get('scriptsets')){
  302. collapse($(scriptsets).parents('section'));
  303. }
  304. if (GM_config.get('newtab')){
  305. $(listitem).each(function(){
  306. $(this).find(separator).prev('a').click(newtaber);
  307. });
  308. }
  309.  
  310. function newtaber(e){
  311. e.preventDefault();
  312. e.stopPropagation();
  313. GM_openInTab(this.href, options);
  314. }
  315. })();