Video Celebs Search And UI Tweaks

Video filters and UI manipulations

2021-03-29 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

  1. // ==UserScript==
  2. // @name Video Celebs Search And UI Tweaks
  3. // @namespace brazenvoid
  4. // @version 1.3.2
  5. // @author brazenvoid
  6. // @license GPL-3.0-only
  7. // @description Video filters and UI manipulations
  8. // @match https://videocelebs.net/*
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js
  10. // @require https://greasyfork.org/scripts/375557-base-resource/code/Base%20Resource.js?version=899286
  11. // @require https://greasyfork.org/scripts/418665-brazen-configuration-manager/code/Brazen%20Configuration%20Manager.js?version=892799
  12. // @require https://greasyfork.org/scripts/416104-brazen-ui-generator/code/Brazen%20UI%20Generator.js?version=899448
  13. // @require https://greasyfork.org/scripts/416105-brazen-base-search-enhancer/code/Brazen%20Base%20Search%20Enhancer.js?version=899428
  14. // @grant GM_addStyle
  15. // @run-at document-end
  16. // ==/UserScript==
  17.  
  18. GM_addStyle(`button.show-settings{height:75vh;top:20vh}#settings-wrapper{top:20vh;width:250px}.bg-brand{background-color:#2f74a4}.font-primary{color:white}input.form-input.check-radio-input{width:auto;margin:0 5px 1px 0}label.title{margin: 0}`)
  19.  
  20. const PAGE_PATH_NAME = window.location.pathname
  21.  
  22. const IS_VIDEO_PAGE = PAGE_PATH_NAME.endsWith('.html')
  23.  
  24. const FILTER_VIDEOS_YEAR = 'Year'
  25.  
  26. const OPTION_MOVE_VIDEO_ATTRIBUTES_SECTION = 'Reposition Attributes Section'
  27. const OPTION_REMOVE_COMMENTS_SECTION = 'Remove Comments Section'
  28. const OPTION_REMOVE_IFRAME_SECTION = 'Remove Iframe Share Section'
  29. const OPTION_REMOVE_RELATED_VIDEOS_SECTION = 'Remove Related Videos Section'
  30.  
  31. const SCRIPT_PREFIX = 'vc-sui-'
  32.  
  33. const SELECTOR_ITEM = 'div.item'
  34. const SELECTOR_ITEM_LISTS = '.midle_div,.list_videos'
  35. const SELECTOR_PAGINATION_LIST = '.midle_div'
  36.  
  37. const ITEM_YEAR = 'scriptYear'
  38.  
  39. class VideoCelebsSearchAndUITweaks extends BrazenBaseSearchEnhancer
  40. {
  41. static getLastPageUrl ()
  42. {
  43. let lastPaginationElement = $('.wp-pagenavi a:last')
  44. return lastPaginationElement.length ? lastPaginationElement.attr('href') : window.location.href
  45. }
  46.  
  47. constructor ()
  48. {
  49. super(SCRIPT_PREFIX, SELECTOR_ITEM)
  50.  
  51. this._configurationManager.
  52. addFlagField(OPTION_MOVE_VIDEO_ATTRIBUTES_SECTION, 'Move the video attributes section from below the screenshot area to under the description.').
  53. addFlagField(OPTION_REMOVE_COMMENTS_SECTION, 'Remove comments area on video pages.').
  54. addFlagField(OPTION_REMOVE_IFRAME_SECTION, 'Remove iframe share section under video player.').
  55. addFlagField(OPTION_REMOVE_RELATED_VIDEOS_SECTION, 'Remove related videos section on video pages.').
  56. addRangeField(FILTER_VIDEOS_YEAR, 0, new Date().getFullYear(), 'Filter videos by content release year.')
  57.  
  58. if (!IS_VIDEO_PAGE) {
  59. this._paginator = BrazenPaginator.create($('.wp-pagenavi'), SELECTOR_PAGINATION_LIST, SELECTOR_ITEM, VideoCelebsSearchAndUITweaks.getLastPageUrl()).
  60. onGetPageNoFromUrl((url) => url.includes('/page/') ? parseInt(url.split('/').pop()) : 1).
  61. onGetPageUrlFromPageNo((newPageNo) => {
  62. let currentUrl = window.location.href
  63. if (currentUrl.includes('/page/')) {
  64. let currentUrlFragments = currentUrl.split('/')
  65. currentUrlFragments.pop()
  66. currentUrl = currentUrlFragments.join('/')
  67. } else {
  68. currentUrl += 'page'
  69. }
  70. return currentUrl + '/' + newPageNo
  71. }).
  72. onGetPaginationElementForPageNo((pageNo, paginator) => {
  73. let elementSelector = pageNo === paginator.getCurrentPageNo() ?
  74. 'span.current' : 'a[href="' + paginator.getPageUrlFromPageNo(pageNo).replace(window.location.origin, '') + '"]'
  75. return paginator.getPaginationWrapper().find(elementSelector)
  76. })
  77. }
  78.  
  79. this._addPaginationConfiguration()
  80. this._setupUI()
  81. this._setupCompliance()
  82. this._setupComplianceFilters()
  83. }
  84.  
  85. /**
  86. * @private
  87. */
  88. _moveVideoAttributesBelowDescription ()
  89. {
  90. if (this._configurationManager.getValue(OPTION_MOVE_VIDEO_ATTRIBUTES_SECTION)) {
  91. let videoInfoBlock = $('.entry-utility')
  92. videoInfoBlock.insertBefore(videoInfoBlock.prev().prev())
  93. }
  94. }
  95.  
  96. /**
  97. * @private
  98. */
  99. _removeCommentsSection ()
  100. {
  101. if (this._configurationManager.getValue(OPTION_REMOVE_COMMENTS_SECTION)) {
  102. $('.comments-area').remove()
  103. }
  104. }
  105.  
  106. /**
  107. * @private
  108. */
  109. _removeIFrameSection ()
  110. {
  111. if (this._configurationManager.getValue(OPTION_REMOVE_IFRAME_SECTION)) {
  112. $('#tab_share').remove()
  113. }
  114. }
  115.  
  116. /**
  117. * @private
  118. */
  119. _removeRelatedVideosSection ()
  120. {
  121. if (this._configurationManager.getValue(OPTION_REMOVE_RELATED_VIDEOS_SECTION)) {
  122. $('.related').remove()
  123. }
  124. }
  125.  
  126. /**
  127. * @private
  128. */
  129. _setupCompliance()
  130. {
  131. this._onGetItemLists = () => $(SELECTOR_ITEM_LISTS)
  132. this._onGetItemName = () => ''
  133. this._onFirstHitBeforeCompliance = (item) => {
  134. let yearFragments = item.find('.title a').text().trim().split('(')
  135. item[0][ITEM_YEAR] = parseInt(yearFragments[yearFragments.length - 1].replace(')', ''))
  136. }
  137. }
  138.  
  139. /**
  140. * @private
  141. */
  142. _setupComplianceFilters()
  143. {
  144. this._addItemPercentageRatingRangeFilter('.rating')
  145. this._addItemComplianceFilter(FILTER_VIDEOS_YEAR, (item, range) => Validator.isInRange(item[0][ITEM_YEAR], range.minimum, range.maximum))
  146. }
  147.  
  148. /**
  149. * @private
  150. */
  151. _setupUI ()
  152. {
  153. this._onBeforeUIBuild = () => {
  154. if (IS_VIDEO_PAGE) {
  155. this._moveVideoAttributesBelowDescription()
  156. this._removeCommentsSection()
  157. this._removeIFrameSection()
  158. this._removeRelatedVideosSection()
  159. }
  160. }
  161.  
  162. this._onUIBuild = () =>
  163. this._uiGen.createSettingsSection().append([
  164. this._uiGen.createTabsSection(['Filters', 'UI', 'Pagination', 'Global'], [
  165. this._uiGen.createTabPanel('Filters', true).append([
  166. this._configurationManager.createElement(FILTER_PERCENTAGE_RATING_RANGE),
  167. this._configurationManager.createElement(FILTER_VIDEOS_YEAR),
  168. this._uiGen.createSeparator(),
  169. this._configurationManager.createElement(OPTION_DISABLE_COMPLIANCE_VALIDATION),
  170. ]),
  171. this._uiGen.createTabPanel('UI').append([
  172. this._configurationManager.createElement(OPTION_MOVE_VIDEO_ATTRIBUTES_SECTION),
  173. this._configurationManager.createElement(OPTION_REMOVE_COMMENTS_SECTION),
  174. this._configurationManager.createElement(OPTION_REMOVE_IFRAME_SECTION),
  175. this._configurationManager.createElement(OPTION_REMOVE_RELATED_VIDEOS_SECTION),
  176. ]),
  177. this._uiGen.createTabPanel('Pagination').append([
  178. this._configurationManager.createElement(CONFIG_PAGINATOR_THRESHOLD),
  179. this._configurationManager.createElement(CONFIG_PAGINATOR_LIMIT),
  180. ]),
  181. this._uiGen.createTabPanel('Global').append([
  182. this._configurationManager.createElement(OPTION_ALWAYS_SHOW_SETTINGS_PANE),
  183. this._uiGen.createSeparator(),
  184. this._createSettingsBackupRestoreFormActions(),
  185. ]),
  186. ]),
  187. this._createSettingsFormActions(),
  188. this._uiGen.createSeparator(),
  189. this._uiGen.createStatisticsFormGroup(FILTER_PERCENTAGE_RATING_RANGE),
  190. this._uiGen.createStatisticsFormGroup(FILTER_VIDEOS_YEAR),
  191. this._uiGen.createSeparator(),
  192. this._uiGen.createStatisticsTotalsGroup(),
  193. this._uiGen.createSeparator(),
  194. this._uiGen.createStatusSection(),
  195. ])
  196.  
  197. this._onAfterUIBuild = () => {
  198. this._uiGen.getSelectedSection()[0].userScript = this
  199. }
  200. }
  201. }
  202.  
  203. (new VideoCelebsSearchAndUITweaks).init()