steamgifts.com improved game filter

Makes hiding giveaways for specific games much quicker and easier

  1. // ==UserScript==
  2. // @name steamgifts.com improved game filter
  3. // @description Makes hiding giveaways for specific games much quicker and easier
  4. // @namespace Barefoot Monkey
  5. // @include https://www.steamgifts.com/
  6. // @include https://www.steamgifts.com/giveaways/search?*
  7. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js
  8. // @version 2.1.2
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @noframes
  12. // ==/UserScript==
  13.  
  14. var version = '2.1.2'
  15. var OLD_VERSION_KEY = 'previous version'
  16.  
  17. $('<style>')
  18. .text(
  19. '.BarefootMonkey-popup-bg {'
  20. +' background: #3C424D;'
  21. +' position: fixed;'
  22. +' top: 0;'
  23. +' bottom: 0;'
  24. +' left: 0;'
  25. +' right: 0;'
  26. +' opacity: 0.85;'
  27. +' z-index: 9988;'
  28. +' cursor: pointer;'
  29. +'}'
  30.  
  31. +'.BarefootMonkey-popup ul {'
  32. +' list-style: inside;'
  33. +'}'
  34. +'.BarefootMonkey-popup p {'
  35. +' margin: 0.7em 0;'
  36. +' text-align: justify;'
  37. +'}'
  38.  
  39. +'.BarefootMonkey-popup h1 i {'
  40. +' font-size: 0.5em;'
  41. +' font-weight: bold;'
  42. +'}'
  43.  
  44. +'.BarefootMonkey-popup a {'
  45. +' color: #4B72D4;'
  46. +' font-weight: bold;'
  47. +'}'
  48. +'.BarefootMonkey-popup em {'
  49. +' font-style: italic;'
  50. +'}'
  51. +'.BarefootMonkey-popup h1 {'
  52. +' font-size: 1.5em;'
  53. +' margin: 0px 0px 0.5em;'
  54. +' border-bottom: 1px solid #6B7A8C;'
  55. +' padding-bottom: 0.5em;'
  56. +'}'
  57. +'.BarefootMonkey-popup key, .BarefootMonkey-popup b {'
  58. +' font-weight: bold;'
  59. +'}'
  60. +'.BarefootMonkey-popup {'
  61. +' background: #F0F2F5 none repeat scroll 0% 0%;'
  62. +' z-index: 9999;'
  63. +' position: fixed;'
  64. +' left: calc(50vw - 18em);'
  65. +' top: 20vh;'
  66. +' border-radius: 4px;'
  67. +' color: #6B7A8C;'
  68. +' font: 300 17px "Open Sans",sans-serif;'
  69. +' padding: 1em;'
  70. +' width: 36em;'
  71. +' max-height: calc(80vh - 3em);'
  72. +' overflow: auto;'
  73. +'}'
  74. )
  75. .appendTo(document.head)
  76.  
  77. function cmpVersion(a, b) {
  78. var i, cmp, len, re = /(\.0)+[^\.]*$/;
  79. a = (a + '').replace(re, '').split('.');
  80. b = (b + '').replace(re, '').split('.');
  81. len = Math.min(a.length, b.length);
  82. for( i = 0; i < len; i++ ) {
  83. cmp = parseInt(a[i], 10) - parseInt(b[i], 10);
  84. if( cmp !== 0 ) {
  85. return cmp;
  86. }
  87. }
  88. return a.length - b.length;
  89. }
  90.  
  91. function close_popup() {
  92. GM_setValue(OLD_VERSION_KEY, version)
  93. $('.BarefootMonkey-popup-bg, .BarefootMonkey-popup').fadeOut(500, function() { $(this).remove() })
  94. }
  95. function open_popup() {
  96. var bg = $('<div class="BarefootMonkey-popup-bg">')
  97. .hide()
  98. .appendTo(document.body)
  99. .click(close_popup)
  100.  
  101. var popup = $('<aside class="BarefootMonkey-popup">')
  102. .hide()
  103. .html('<h1>improved game filter <i>steamgifts.com userscript, version '+version+'</i></h1>'
  104. +"<p>This script replaces steamgifts.com's default \"Hide Game\" interface with one that's a bit more practical.</p>"
  105. +"<p>Click on the <i class=\"giveaway__icon giveaway__hide fa fa-eye-slash\"></i> icon next to the name of a game you want to hide and the game will be hidden without asking you for confirmation.</p>"
  106. +"<p>Skipping the confirmation makes hiding games quicker, but increases the chance that you accidentally hide the wrong game. To solve that problem, <b>improved game filter</b> doesn't actually remove games from the page as soon as you hide them - it merely adds a visual indication that they're hidden. That way you can see what games you've just hidden and undo any accidents by clicking on the <i class=\"giveaway__icon giveaway__hide fa fa-eye-slash\"></i> icons again to undo hiding them.</p>"
  107. +"<p>If you have any comments or questions about the <b>improved game filter</b> userscript then feel free to <a href=\"http://www.steamgifts.com/discussion/c1xhr/userscript-improved-game-filter\">join this discussion</a>.</p>"
  108. +"<h1>recent changes</h1>"
  109. +"<ul>"
  110. +"<li>Fixed regression in previous update, which affected users running this script through Tampermonkey on Chrome.</li>"
  111. +"<li>General site compatiblity update. You may have noticed the noticed the regular \"hide game\" popups appearing recently despite having improved game filter installed. Version 2.1 fixes this issue.</li>"
  112. +"</ul>"
  113. )
  114. .appendTo(document.body)
  115.  
  116. $('.BarefootMonkey-popup-bg, .BarefootMonkey-popup').fadeIn(500)
  117. }
  118.  
  119. var old_version = GM_getValue(OLD_VERSION_KEY)
  120. if (old_version == null || cmpVersion(old_version, version) < 0) {
  121. open_popup()
  122. }
  123.  
  124. $('<style>')
  125. .text(
  126. '@keyframes rotate-right-60px {'
  127. +' from {'
  128. +' background-position: 0px 0;'
  129. +' }'
  130. +' to {'
  131. +' background-position: 300px 0;'
  132. +' }'
  133. +'}'
  134.  
  135. +'@keyframes rotate-left-60px {'
  136. +' from {'
  137. +' background-position: 0px 0;'
  138. +' }'
  139. +' to {'
  140. +' background-position: -300px 0;'
  141. +' }'
  142. +'}'
  143.  
  144. +'.giveaway__row-outer-wrap {'
  145. +' transition: opacity 1s linear;'
  146. +'}'
  147.  
  148. +'.BarefootMonkey-hidden {'
  149. +' opacity: 0.6;'
  150. +' background: repeating-linear-gradient(45deg, transparent 0px, transparent 10px, #ccc, 10px, #ccc 12px, transparent 12px), repeating-linear-gradient(-45deg, transparent 0px, transparent 10px, #ccc, 10px, #ccc 12px, transparent 12px);'
  151. +'}'
  152.  
  153. +'.BarefootMonkey-hiding, .BarefootMonkey-unhiding {'
  154. +' opacity: 0.6;'
  155. +' animation-duration: 12s;'
  156. +' animation-iteration-count: infinite;'
  157. +' animation-timing-function: linear;'
  158. +'}'
  159.  
  160. +'.BarefootMonkey-hiding {'
  161. +' animation-name: rotate-right-60px;'
  162. +' background: repeating-linear-gradient(45deg, transparent 0px, transparent 10px, #ccc, 10px, #ccc 12px);'
  163. +'}'
  164.  
  165. +'.BarefootMonkey-unhiding {'
  166. +' animation-name: rotate-left-60px;'
  167. +' background: repeating-linear-gradient(-45deg, transparent 0px, transparent 10px, #ccc, 10px, #ccc 12px);'
  168. +'}'
  169. )
  170. .appendTo(document.head)
  171.  
  172. function update_filter(id, token, action, url, prior_class, progress_class, complete_class) {
  173.  
  174. $('.giveaway__row-outer-wrap[data-game-id='+id+']')
  175. .addClass(progress_class)
  176. .removeClass('BarefootMonkey-error')
  177. .removeClass(prior_class)
  178.  
  179. $.ajax({
  180. url: url,
  181. method: 'POST',
  182. context: {id: id, progress_class: progress_class, complete_class: complete_class},
  183. data: {
  184. 'xsrf_token':token,
  185. 'game_id':id,
  186. 'do': action
  187. },
  188. 'error': function() {
  189. $('.giveaway__icon.giveaway__hide[data-popup="popup--hide-games"][data-game-id='+this.id+']')
  190. .closest('.giveaway__row-outer-wrap')
  191. .removeClass(this.progress_class)
  192. .addClass('BarefootMonkey-error')
  193. },
  194. 'success': function() {
  195. $('.giveaway__row-outer-wrap[data-game-id='+this.id+']')
  196. .removeClass(this.progress_class)
  197. .addClass(this.complete_class)
  198. }
  199. })
  200. }
  201.  
  202. function callback(event) {
  203. var closest = $(this).closest('.giveaway__row-outer-wrap[data-game-id]')
  204. if (closest.length > 0) {
  205.  
  206. // get id and token
  207. var id = closest.data('game-id')
  208. var token = $('.popup--hide-games form input[name="xsrf_token"]').val()
  209.  
  210. // hide or unhide the game
  211. if (id && token) {
  212. if (closest.hasClass('BarefootMonkey-hidden')) {
  213. update_filter(id, token, 'remove_filter', '/ajax.php', 'BarefootMonkey-hidden', 'BarefootMonkey-unhiding', null)
  214. } else if (!closest.hasClass('BarefootMonkey-unhiding') && !closest.hasClass('BarefootMonkey-hiding')) {
  215. update_filter(id, token, 'hide_giveaways_by_game_id', '/ajax.php', null, 'BarefootMonkey-hiding', 'BarefootMonkey-hidden')
  216. }
  217. }
  218. }
  219.  
  220. event.stopPropagation()
  221. }
  222.  
  223. setTimeout(function() {
  224. // remove existing click handlers
  225. unsafeWindow.$('.giveaway__icon.giveaway__hide').off('click')
  226. // handle clicking on hide button
  227. $('.giveaway__icon.giveaway__hide')
  228. .removeClass('trigger-popup')
  229. .click(callback)
  230.  
  231. // observe DOM tree mutations to improve compatibility with endless scrolling userscripts
  232. var container = document.querySelector('.page__outer-wrap>.page__inner-wrap>.widget-container>.sidebar+div')
  233. var observer = new MutationObserver(function(mutations) {
  234. mutations.forEach(function(mutation) {
  235. var added = mutation.addedNodes
  236. for (var i = 0; i < mutation.addedNodes.length; i += 1) {
  237. var node = $(mutation.addedNodes[i])
  238.  
  239. node.find('.giveaway__icon.giveaway__hide')
  240. .off()
  241. .click(callback)
  242. }
  243. });
  244. });
  245. observer.observe(container, {childList:true});
  246.  
  247. }, 10)

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址