Greasy Fork tweaks

this code opens scripts pages in new tab from lists and compacts user interface

当前为 2020-02-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Greasy Fork tweaks
  3. // @namespace almaceleste
  4. // @version 0.2.1
  5. // @description this code opens scripts pages in new tab from lists and compacts user interface
  6. // @description:ru этот код открывает страницы скриптов в новой вкладке из списков и делает интерфейс более компактным
  7. // @author (ɔ) Paola Captanovska
  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. // @run-at document-end
  18. // @require https://code.jquery.com/jquery-3.3.1.js
  19. // @require https://code.jquery.com/ui/1.12.1/jquery-ui.js
  20. // @require https://openuserjs.org/src/libs/sizzle/GM_config.js
  21. // @grant GM_getValue
  22. // @grant GM_setValue
  23. // @grant GM_registerMenuCommand
  24. // @grant GM_openInTab
  25.  
  26. // @match https://greasyfork.org/*/users/*
  27. // @match https://greasyfork.org/*/scripts*
  28. // ==/UserScript==
  29.  
  30. // ==OpenUserJS==
  31. // @author almaceleste
  32. // ==/OpenUserJS==
  33.  
  34. const windowcss = '#greasyforktweaksCfg {background-color: lightblue;} #greasyforktweaksCfg .reset_holder {float: left; position: relative; bottom: -1em;} #greasyforktweaksCfg .saveclose_buttons {margin: .7em;}';
  35. const iframecss = 'height: 30.1em; width: 30em; border: 1px solid; border-radius: 3px; position: fixed; z-index: 999;';
  36.  
  37. const listitem = '.script-list li';
  38. const separator = '.name-description-separator';
  39. const scriptversion = 'data-script-version';
  40. const scriptstats = '.inline-script-stats';
  41. const dailyinstalls = '.script-list-daily-installs';
  42. const totalinstalls = '.script-list-total-installs';
  43. const createddate = '.script-list-created-date';
  44. const updateddate = '.script-list-updated-date';
  45. const userprofile = '#user-profile';
  46. const controlpanel = '#control-panel';
  47. const discussions = '#user-discussions-on-scripts-written';
  48. const scriptsets = 'h3:contains("Script Sets")';
  49.  
  50.  
  51. GM_registerMenuCommand('Greasy Fork tweaks Settings', opencfg);
  52.  
  53. function opencfg()
  54. {
  55. GM_config.open();
  56. greasyforktweaksCfg.style = iframecss;
  57. }
  58.  
  59. GM_config.init(
  60. {
  61. id: 'greasyforktweaksCfg',
  62. title: 'Greasy Fork tweaks',
  63. fields:
  64. {
  65. version:
  66. {
  67. section: ['Script list', 'Script list options (common and user lists)'],
  68. label: 'add script version number in the list of scripts',
  69. labelPos: 'right',
  70. type: 'checkbox',
  71. default: true,
  72. },
  73. compact:
  74. {
  75. label: 'compact script information',
  76. labelPos: 'right',
  77. type: 'checkbox',
  78. default: true,
  79. },
  80. userprofile:
  81. {
  82. section: ['User page', 'User page options (my page and other users`)'],
  83. label: 'collapse user profile info on user page',
  84. labelPos: 'right',
  85. type: 'checkbox',
  86. default: true,
  87. },
  88. controlpanel:
  89. {
  90. label: 'collapse control panel on user page',
  91. labelPos: 'right',
  92. type: 'checkbox',
  93. default: true,
  94. },
  95. discussions:
  96. {
  97. label: 'collapse discussions on user page',
  98. labelPos: 'right',
  99. type: 'checkbox',
  100. default: true,
  101. },
  102. scriptsets:
  103. {
  104. label: 'collapse script sets on user page',
  105. labelPos: 'right',
  106. type: 'checkbox',
  107. default: true,
  108. },
  109. newtab:
  110. {
  111. section: ['New tab', 'Open script page in new tab'],
  112. label: 'open script page in new tab',
  113. labelPos: 'right',
  114. type: 'checkbox',
  115. default: true,
  116. },
  117. background:
  118. {
  119. label: 'open new tab in background',
  120. labelPos: 'right',
  121. type: 'checkbox',
  122. default: false,
  123. },
  124. insert:
  125. {
  126. label: 'insert new tab next to the current instead of the right end',
  127. labelPos: 'right',
  128. type: 'checkbox',
  129. default: true,
  130. },
  131. setParent:
  132. {
  133. label: 'return to the current tab after new tab closed',
  134. labelPos: 'right',
  135. type: 'checkbox',
  136. default: true,
  137. },
  138. },
  139. css: windowcss,
  140. events:
  141. {
  142. save: function() {
  143. GM_config.close();
  144. }
  145. },
  146. });
  147.  
  148. (function() {
  149. 'use strict';
  150.  
  151. var options = {active: !GM_config.get('background'), insert: GM_config.get('insert'), setParent: GM_config.get('setParent')};
  152.  
  153. if (GM_config.get('version')){
  154. $(listitem).each(function(){
  155. $(this).find(separator).after(($(this).attr(scriptversion)));
  156. });
  157. }
  158. if (GM_config.get('compact')){
  159. $(scriptstats).children().css('width','auto');
  160. $('dt' + totalinstalls).each(function(){
  161. $(this).css('display','none');
  162. $(this).siblings('dt' + dailyinstalls).find('span').append(' (' + $(this).find('span').text() + ')');
  163. });
  164. $('dd' + totalinstalls).each(function(){
  165. $(this).css('display','none');
  166. $(this).siblings('dd' + dailyinstalls).find('span').append(' (' + $(this).find('span').text() + ')');
  167. });
  168. $('dt' + updateddate).each(function(){
  169. $(this).css('display','none');
  170. $(this).siblings('dt' + createddate).find('span').append(' (' + $(this).find('span').text() + ')');
  171. });
  172. $('dd' + updateddate).each(function(){
  173. $(this).css('display','none');
  174. $(this).siblings('dd' + createddate).find('span').append(' (' + $(this).find('span').text() + ')');
  175. });
  176. }
  177. if (GM_config.get('userprofile')){
  178. $(userprofile).parent().children('h2')
  179. .append('<span>&#9660</span>')
  180. .click(function(){
  181. $(userprofile).slideToggle();
  182. })
  183. $(userprofile).slideUp();
  184. }
  185. if (GM_config.get('controlpanel')){
  186. $(controlpanel)
  187. .accordion({
  188. collapsible: true,
  189. active: false
  190. })
  191. .find('header h3').append('<span>&#9660</span>')
  192. }
  193. if (GM_config.get('discussions')){
  194. $(discussions)
  195. .accordion({
  196. collapsible: true,
  197. active: false
  198. })
  199. .find('header h3').append('<span>&#9660</span>')
  200. }
  201. if (GM_config.get('scriptsets')){
  202. $(scriptsets).parents('section')
  203. .accordion({
  204. collapsible: true,
  205. active: false
  206. })
  207. .find('header h3').append('<span>&#9660</span>')
  208. }
  209. if (GM_config.get('newtab')){
  210. $(listitem).each(function(){
  211. $(this).find(separator).prev('a').click(newtaber);
  212. });
  213. }
  214.  
  215. function newtaber(e){
  216. e.preventDefault();
  217. e.stopPropagation();
  218. GM_openInTab(this.href, options);
  219. }
  220. })();