Doublelist Filter Options

Add filter options to Doublelist listing pages

2019-03-09 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name     Doublelist Filter Options
// @description Add filter options to Doublelist listing pages
// @version  1
// @grant       GM.getValue
// @grant       GM.setValue
// @include http://doublelist.com/city/*/*
// @include https://doublelist.com/city/*/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @run-at document-idle
// @namespace https://greasyfork.org/users/257342
// ==/UserScript==

(async () => {
  mainContainer = $('.container.mt-4')[0]

  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>' +
    '<div><input name="minage" type="number" value="18" id="minage" />&nbsp;<label for="minage">Min Age</label></div>' +
    '<div><input name="maxage" type="number" value="99" id="maxage" />&nbsp;<label for="minage">Max Age</label></div>' + '</div>'

  mainContainer.innerHTML = filterHTML + mainContainer.innerHTML 

  var updatematches = function(){
    $('.postlinks2').hide()

    if($('#filteroptions #pics').is(":checked")){
      $('.postlinks2:has(.post_photo)').show()
    }else{
      $('.postlinks2').show()
    }

    posts = $('.postlinks2')

    minage = $('#filteroptions #minage').val()
    maxage = $('#filteroptions #maxage').val()

    posts.each(function(index){
      age = $(this).children('span').children('span')[1].innerText

      if(age < minage || age > maxage)
        $(this).hide()
    })
    
    GM.setValue("minage", minage)
    GM.setValue("maxage", maxage)
    GM.setValue("pics", $('#filteroptions #pics').is(":checked"))
  }

  $('#filteroptions #pics').prop('checked', await GM.getValue("pics", false))
  $('#filteroptions #minage').val(await GM.getValue("minage", 18))
  $('#filteroptions #maxage').val(await GM.getValue("maxage", 99))

  $('#filteroptions #pics').change(updatematches)
  $('#filteroptions #minage').change(updatematches)
  $('#filteroptions #maxage').change(updatematches)
  
  updatematches()
  
})();