Doublelist Filter Options

Add filter options to Doublelist listing pages

  1. // ==UserScript==
  2. // @name Doublelist Filter Options
  3. // @description Add filter options to Doublelist listing pages
  4. // @version 3
  5. // @grant GM.getValue
  6. // @grant GM.setValue
  7. // @include http://doublelist.com/city/*/*
  8. // @include https://doublelist.com/city/*/*
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
  10. // @run-at document-idle
  11. // @namespace https://greasyfork.org/users/257342
  12. // ==/UserScript==
  13.  
  14. (async () => {
  15. mainContainer = $('.container')[0]
  16.  
  17. filterHTML = '<div class="container" id="filteroptions"><h2>Filters:</h2><br/><div><input name="pics" type="checkbox" id="pics" />&nbsp;<label for="pics">Require Picture</label></div>' +
  18. '<div><input name="minage" type="number" value="18" id="minage" />&nbsp;<label for="minage">Min Age</label></div>' +
  19. '<div><input name="maxage" type="number" value="99" id="maxage" />&nbsp;<label for="minage">Max Age</label></div>' +
  20. '<div><input name="blocklist" type="text" value="" id="blocklist" />&nbsp;<label for="blocklist">Blocked terms (in title)</label></div>' +
  21. '<div><input name="blocklist2" type="text" value="" id="blocklist2" />&nbsp;<label for="blocklist2">Blocked terms (in location)</label></div>' + '</div>'
  22.  
  23. mainContainer.innerHTML = filterHTML + mainContainer.innerHTML
  24.  
  25. var updatematches = function(){
  26. $('.list').hide()
  27.  
  28. if($('#filteroptions #pics').is(":checked")){
  29. $('.list:has(.orn)').show()
  30. }else{
  31. $('.list').show()
  32. }
  33.  
  34. posts = $('.list')
  35.  
  36. minage = Math.max(18, $('#filteroptions #minage').val())
  37. maxage = Math.max(minage, $('#filteroptions #maxage').val())
  38.  
  39. blocklist = $('#blocklist').val().split(/[\s,;]+/)
  40. blocklist2 = $('#blocklist2').val().split(/[\s,;]+/)
  41. posts.each(function(index){
  42. if($(this).children('a').children('span').length > 2)
  43. age = $(this).children('a').children('span')[2].innerText
  44. else
  45. age = -1
  46. if(age < minage || age > maxage)
  47. $(this).hide()
  48. if(blocklist.some(block => block.length > 0 && $(this).children('a').children('span')[0].innerText.toLowerCase().includes(block.toLowerCase())))
  49. $(this).hide()
  50. if(blocklist2.some(block => block.length > 0 && $(this).children('a').children('span')[1].innerText.toLowerCase().includes(block.toLowerCase())))
  51. $(this).hide()
  52. })
  53. GM.setValue("minage", minage)
  54. GM.setValue("maxage", maxage)
  55. GM.setValue("pics", $('#filteroptions #pics').is(":checked"))
  56. GM.setValue("blocklist", $('#blocklist').val())
  57. GM.setValue("blocklist2", $('#blocklist2').val())
  58. }
  59.  
  60. $('#filteroptions #pics').prop('checked', await GM.getValue("pics", false))
  61. $('#filteroptions #minage').val(await GM.getValue("minage", 18))
  62. $('#filteroptions #maxage').val(await GM.getValue("maxage", 99))
  63. $('#filteroptions #blocklist').val(await GM.getValue("blocklist", ""))
  64. $('#filteroptions #blocklist2').val(await GM.getValue("blocklist2", ""))
  65.  
  66. $('#filteroptions #pics').change(updatematches)
  67. $('#filteroptions #minage').change(updatematches)
  68. $('#filteroptions #maxage').change(updatematches)
  69. $('#filteroptions #blocklist').change(updatematches)
  70. $('#filteroptions #blocklist2').change(updatematches)
  71. updatematches()
  72. })();