Video Celebs Search And UI Tweaks

Video filters and UI manipulations

Version vom 06.12.2020. Aktuellste Version

  1. // ==UserScript==
  2. // @name Video Celebs Search And UI Tweaks
  3. // @namespace brazenvoid
  4. // @version 1.2.0
  5. // @author brazenvoid
  6. // @license GPL-3.0-only
  7. // @description Video filters and UI manipulations
  8. // @include 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=877475
  11. // @require https://greasyfork.org/scripts/416104-brazen-ui-generator/code/Brazen%20UI%20Generator.js?version=877457
  12. // @require https://greasyfork.org/scripts/416105-brazen-base-search-enhancer/code/Brazen%20Base%20Search%20Enhancer.js?version=877459
  13. // @grant GM_addStyle
  14. // @run-at document-end
  15. // ==/UserScript==
  16.  
  17. GM_addStyle(`#settings-wrapper{background-color:#ffa31a;top:15vh;width:250px}input.form-input.check-radio-input{width:auto;margin:0 5px 1px 0}label.title{margin: 0}`)
  18.  
  19. const PAGE_PATH_NAME = window.location.pathname
  20.  
  21. const IS_VIDEO_PAGE = PAGE_PATH_NAME.endsWith('.html')
  22.  
  23. const FILTER_VIDEOS_RATING = 'Rating'
  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. class VideoCelebsSearchAndUITweaks extends BrazenBaseSearchEnhancer
  32. {
  33. static getLastPageUrl ()
  34. {
  35. if (IS_VIDEO_PAGE) {
  36. return window.location.href
  37. } else {
  38. let lastPaginationElement = $('.wp-pagenavi a:last')
  39. return lastPaginationElement.length ? lastPaginationElement.attr('href') : window.location.href
  40. }
  41. }
  42.  
  43. constructor ()
  44. {
  45. super({
  46. scriptPrefix: 'vc-sui-',
  47. itemClasses: 'item',
  48. paginator: {
  49. enable: !IS_VIDEO_PAGE,
  50. listSelector: '.midle_div',
  51. lastPageUrl: VideoCelebsSearchAndUITweaks.getLastPageUrl(),
  52. getPageNo: (url) => url.includes('/page/') ? parseInt(url.split('/').pop()) : 1,
  53. getPageUrl: (newPageNo) => {
  54. let currentUrl = window.location.href
  55. if (currentUrl.includes('/page/')) {
  56. let currentUrlFragments = currentUrl.split('/')
  57. currentUrlFragments.pop()
  58. currentUrl = currentUrlFragments.join('/')
  59. } else {
  60. currentUrl += '/page'
  61. }
  62. return currentUrl + '/' + newPageNo
  63. },
  64. afterPagination: (paginator) => {
  65.  
  66. let currentPaginationElement = $('.wp-pagenavi span.current')
  67. currentPaginationElement.text(paginator.currentPageNo + '-' + paginator.paginatedPageNo)
  68.  
  69. let paginatorLinksAfterCurrent = $('.wp-pagenavi span.current ~ a')
  70. if (paginator.paginatedPageNo === paginator.lastPageNo) {
  71. paginatorLinksAfterCurrent.remove()
  72. } else {
  73. paginatorLinksAfterCurrent.each((index, element) => {
  74. let paginationLink = $(element)
  75. if (paginator.getPageNo($(element).attr('href')) <= paginator.paginatedPageNo) {
  76. paginationLink.remove()
  77. }
  78. })
  79. let nextPageUrl = paginator.getPageUrl(paginator.paginatedPageNo + 1)
  80. let nextPageLink = $('.wp-pagenavi a[href="'+ nextPageUrl +'"]')
  81. if (nextPageLink.length === 0) {
  82. let lastPageLink = $('.wp-pagenavi a:last')
  83. lastPageLink.clone().insertAfter(currentPaginationElement).
  84. text(paginator.paginatedPageNo + 1).removeClass('last').attr('href', nextPageUrl)
  85. }
  86. }
  87. }
  88. }
  89. })
  90.  
  91. this._configurationManager.
  92. addFlagField(OPTION_MOVE_VIDEO_ATTRIBUTES_SECTION, 'Move the video attributes section from below the screenshot area to under the description.').
  93. addFlagField(OPTION_REMOVE_COMMENTS_SECTION, 'Remove comments area on video pages.').
  94. addFlagField(OPTION_REMOVE_IFRAME_SECTION, 'Remove iframe share section under video player.').
  95. addFlagField(OPTION_REMOVE_RELATED_VIDEOS_SECTION, 'Remove related videos section on video pages.').
  96. addRangeField(FILTER_VIDEOS_RATING, 0, 100, 'Filter videos by ratings.').
  97. addRangeField(FILTER_VIDEOS_YEAR, 0, new Date().getFullYear(), 'Filter videos by content release year.')
  98.  
  99. // UI Events
  100.  
  101. this._onBeforeUIBuild = () => {
  102. if (IS_VIDEO_PAGE) {
  103. this._moveVideoAttributesBelowDescription()
  104. this._removeCommentsSection()
  105. this._removeIFrameSection()
  106. this._removeRelatedVideosSection()
  107. }
  108. }
  109.  
  110. this._onUIBuild = () =>
  111. this._uiGen.createSettingsSection().append([
  112. this._uiGen.createTabsSection(['Filters', 'UI', 'Stats'], [
  113. this._uiGen.createTabPanel('Filters', true).append([
  114. this._configurationManager.createElement(FILTER_VIDEOS_RATING),
  115. this._configurationManager.createElement(FILTER_VIDEOS_YEAR),
  116. this._uiGen.createSeparator(),
  117. this._configurationManager.createElement(OPTION_DISABLE_COMPLIANCE_VALIDATION),
  118. ]),
  119. this._uiGen.createTabPanel('UI').append([
  120. this._configurationManager.createElement(OPTION_MOVE_VIDEO_ATTRIBUTES_SECTION),
  121. this._configurationManager.createElement(OPTION_REMOVE_COMMENTS_SECTION),
  122. this._configurationManager.createElement(OPTION_REMOVE_IFRAME_SECTION),
  123. this._configurationManager.createElement(OPTION_REMOVE_RELATED_VIDEOS_SECTION),
  124. this._uiGen.createSeparator(),
  125. this._configurationManager.createElement(CONFIG_PAGINATOR_THRESHOLD),
  126. this._configurationManager.createElement(CONFIG_PAGINATOR_LIMIT),
  127. this._configurationManager.createElement(OPTION_ALWAYS_SHOW_SETTINGS_PANE),
  128. ]),
  129. this._uiGen.createTabPanel('Stats').append([
  130. this._uiGen.createStatisticsFormGroup(FILTER_VIDEOS_RATING),
  131. this._uiGen.createStatisticsFormGroup(FILTER_VIDEOS_YEAR),
  132. this._uiGen.createSeparator(),
  133. this._uiGen.createStatisticsTotalsGroup(),
  134. ]),
  135. ]),
  136. this._createSettingsFormActions(),
  137. this._uiGen.createSeparator(),
  138. this._uiGen.createStatusSection(),
  139. ])
  140.  
  141. this._onAfterUIBuild = () => {
  142. this._uiGen.getSelectedSection()[0].userScript = this
  143. }
  144.  
  145. // Compliance Events
  146.  
  147. this._onGetItemLists = () => $('.midle_div,.list_videos')
  148.  
  149. this._complianceFilters = [
  150. (videoItem) => this._validateRating(videoItem),
  151. (videoItem) => this._validateYear(videoItem),
  152. ]
  153. }
  154.  
  155. _moveVideoAttributesBelowDescription ()
  156. {
  157. if (this._configurationManager.getValue(OPTION_MOVE_VIDEO_ATTRIBUTES_SECTION)) {
  158. let videoInfoBlock = $('.entry-utility')
  159. videoInfoBlock.insertBefore(videoInfoBlock.prev().prev())
  160. }
  161. }
  162.  
  163. _removeCommentsSection ()
  164. {
  165. if (this._configurationManager.getValue(OPTION_REMOVE_COMMENTS_SECTION)) {
  166. $('.comments-area').remove()
  167. }
  168. }
  169.  
  170. _removeIFrameSection ()
  171. {
  172. if (this._configurationManager.getValue(OPTION_REMOVE_IFRAME_SECTION)) {
  173. $('#tab_share').remove()
  174. }
  175. }
  176.  
  177. _removeRelatedVideosSection ()
  178. {
  179. if (this._configurationManager.getValue(OPTION_REMOVE_RELATED_VIDEOS_SECTION)) {
  180. $('.related').remove()
  181. }
  182. }
  183.  
  184. /**
  185. * Validate video source release year
  186. * @param {JQuery} videoItem
  187. * @return {boolean}
  188. * @private
  189. */
  190. _validateRating (videoItem)
  191. {
  192. let range = this._configurationManager.getValue(FILTER_VIDEOS_RATING)
  193. if (range.minimum > 0 || range.maximum > 0) {
  194. let rating = parseInt(videoItem.find('.rating').text().trim().replace('%', ''))
  195. return this._validator.validateRange(FILTER_VIDEOS_RATING, rating, [range.minimum, range.maximum])
  196. }
  197. return true
  198. }
  199.  
  200. /**
  201. * Validate video view count
  202. * @param {JQuery} videoItem
  203. * @return {boolean}
  204. * @private
  205. */
  206. _validateYear (videoItem)
  207. {
  208. let range = this._configurationManager.getValue(FILTER_VIDEOS_YEAR)
  209. if (range.minimum > 0 || range.maximum > 0) {
  210. let yearFragments = videoItem.find('.title a').text().trim().split('(')
  211. let year = parseInt(yearFragments[yearFragments.length - 1].replace(')', ''))
  212. return this._validator.validateRange(FILTER_VIDEOS_YEAR, year, [range.minimum, range.maximum])
  213. }
  214. return true
  215. }
  216. }
  217.  
  218. (new VideoCelebsSearchAndUITweaks).init()