<!--/*========================================================================================
* +-+-+-+-+-+ Project    : ZeroFault
* |V|1|P|3|R| Author     : ZeroFaultツ
* +-+-+-+-+-+ Version    : V1.0
========================================================================================*/-->

<!DOCTYPE html>

<html>

<head>

  <meta charset="utf-8">

  <meta http-equiv="x-ua-compatible" content="ie=edge">

  <title>ZeroDATA</title>

  <meta name="robots" content="noindex, nofollow, noimageindex">

  <meta name="description" content="">

  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="shortcut icon nofollow" href="https://iili.io/5rMNta.png">

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css">

  <style>

    .ui.container{ padding: 20px } 

    h2{ margin-bottom: 0!important }

    table{ width: 100%!important; max-width: 100%!important }

    form{ margin-top: 14px }

    input{ height: 45px!important }

    td:nth-child(2) > div.field:nth-child(2) div.dropdown{ width: 110px!important }

    div.dropdown, div.dropdown i{ padding-top: 14px !important; padding-bottom: 14px !important }

    div.button{ padding-top: 15px !important; padding-bottom: 15px !important }

  </style>

</head>

<body>

  <section class="ui container">

    <div align="center">
      
      <h2 class="ui icon header">
      
        <i class="viacoin icon"></i>
      
        <div class="content">
      
          ZeroDATAツ
      
          <div class="sub header">Email Extractor & Filter application.</div>
      
        </div>
      
      </h2>
    
    </div>

    <form class="ui form">

      <table class="ui teal single line fixed three column table small">

        <thead>
        
          <tr>

            <th>

              Please Add Your Text In Your Input Window:
            
            </th>

            <th class="right aligned">
              
              <small>
            
                &copy; 2018-<?php echo date('Y'); ?> By <a href="https://t.me/zfault" target="_blank">ZeroFaultツ</a> - All rights reserved.
              
              </small>

            </th>

          </tr>

        </thead>

        <tbody>
          
          <tr>

            <td class="top aligned">

              <div class="field">

                <label>

                  Enter The Text/Content

                  <span id="counter"></span>

                </label>

                <textarea name="string" rows="22" autocomplete="off"></textarea>

              </div>

            </td>

            <td class="top aligned">

              <div class="field">
              
                <div class="two fields">
                
                  <div class="field">

                    <label>

                      Extract Address Containing This String

                    </label>

                    <textarea name="keywoardList" autocomplete="off"></textarea>

                  </div>

                  <div class="field">

                    <label>

                     Skip Address Containing This String

                    </label>

                    <textarea name="blockedList" autocomplete="off"></textarea>

                  </div>

                </div>

              </div>

              <div class="field">

                <div class="two fields">

                  <div class="field">

                    <label>

                      Separator

                    </label>

                    <div class="ui left action input">

                      <select class="ui fluid dropdown" name="listSeparator" autocomplete="off">

                        <option value="new">

                          New Line

                        </option>

                        <option value=", ">

                          Comma

                        </option>

                        <option value="|">

                          Pipe

                        </option>

                        <option value=" : ">

                          Colon

                        </option>

                        <option value="other">

                          Other

                        </option>

                      </select>

                      <input

                        type="text"

                        name="otherSeparator"

                        placeholder="Other"

                        autocomplete="off"

                        readonly

                      >

                    </div>

                  </div>

                  <div class="field">

                    <label>

                      Group Addresses

                    </label>

                    <input

                      type="text"

                      name="groupBy"

                      autocomplete="off"

                    >

                  </div>

                </div>

              </div>

              <div class="field">
              
                <div class="two fields">

                  <div class="field">

                    <label>

                      Sort Alphabetically

                    </label>

                    <select class="ui fluid dropdown" name="sortText" autocomplete="off">

                      <option value="Yes">
                      
                        Yes
                        
                      </option>

                      <option value="No">
                        
                        No
                        
                      </option>

                    </select>
                  
                  </div>

                  <div class="field">

                    <label>

                      To Lowercase?

                    </label>

                    <select class="ui fluid dropdown" name="toLowercase" autocomplete="off">

                      <option value="Yes">
                      
                        Yes
                        
                      </option>

                      <option value="No">
                      
                        No
                        
                      </option>

                    </select>

                  </div>

                </div>

              </div>

              <div class="field">
              
                <div class="two fields">

                  <div class="field">

                    <label>

                      Result Type

                    </label>

                    <select class="ui fluid dropdown" name="resultType" autocomplete="off">

                      <option value="show">
                                    
                        Show Result In Output Window
                        
                      </option>

                      <option value="upload">
                      
                        Download Result (For Big Numbers) 
                        
                      </option>

                    </select>
                  
                  </div>

                  <div class="field">

                    <label>

                      Run Script

                    </label>

                    <div class="ui teal fluid animated fade button" tabindex="0" id="extract">

                      <div class="visible content">Extract & Filter</div>

                      <div class="hidden content">

                        <i class="paper plane icon"></i>

                      </div>

                    </div>

                  </div>

                </div>

              </div>

            </td>

          </tr>

        </tbody>

      </table>

    </form>

  </section>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>

  <script>

    $(document).ready(function() {

      'use strict'

      $('.ui.checkbox').checkbox()

      $('select').dropdown()

      let 
        listSeparator = $('select[name="listSeparator"]'),
        otherSeparator = $('input[name="otherSeparator"]'),
        groupBy = $('input[name="groupBy"]'),
        sortText = $('select[name="sortText"]'),
        toLowercase = $('select[name="toLowercase"]'),
        extractType = $('select[name="extractType"]'),
        resultType = $('select[name="resultType"]'),
        string = $('textarea[name="string"]'),
        counter = $('span#counter'),
        extract = $('div#extract')

      const V1P3R_Download = (content, counter) => {

        let
          element = document.createElement('a'),
          blob = new Blob([content], {'type': 'application/octet-stream'})

        element.href = window.URL.createObjectURL(blob)

        element.download = counter + '-Emails.txt'

        element.click()

        element.remove()

      }

      $(listSeparator).on('change', function() {

        let value = $(this).val()

        if(value == 'other'){

          otherSeparator.prop('readonly', false)

        }else{

          otherSeparator.prop('readonly', true).val('')

        }
      
      })

      $(groupBy).blur(function(){

        let item = $(this)

  			if (isNaN(item.val())) {

          alert('Please Enter A Number Or Else \nLeave Blank For No Grouping.')

          item.val('').focus()

        }

      })

      $(extract).click(function(){

        counter.html('')

        let 
          input = (toLowercase.val() == 'Yes') ? string.val().toLowerCase() : string.val(),

          keywoardList = [...new Set(
                            $('textarea[name="keywoardList"]').val().split('\n').filter(function(e) {
                            return e
                          })
                        )],

          blockedList = [...new Set(
                            $('textarea[name="blockedList"]').val().split('\n').filter(function(e) {
                            return e
                          })
                        )],

          output =  input.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi),

          separator

        if(output){

          output = [...new Set(
                      output.filter(function(e) {
                        return e
                      })
                    )]

          if(sortText.val() == 'Yes') output.sort()

          if(keywoardList.length){

            output = output.filter(function(email) {

                return keywoardList.some(function(keywoard) {
                    
                    return ~email.toLowerCase().indexOf(keywoard.toLowerCase())

                })

            })

          }

          if(blockedList.length){

            $(blockedList).each(function(i, blocked) {
              
              output = output.filter(function(email){ return email.toLowerCase().indexOf(blocked.toLowerCase()) === -1 })

            })
            
          }

          if(listSeparator.val() == 'other'){

            separator = (otherSeparator.val()) ? otherSeparator.val() : '\n'

          }else{

            separator = (listSeparator.val() == 'new') ? '\n' : listSeparator.val() 

          }

          counter.html('(' + output.length + ')')

          if(groupBy.val()){

            let chunkOutput = []

            while(output.length){

              chunkOutput.push(output.splice(0, groupBy.val()).join(separator))

            }

            output = (chunkOutput.length) ? chunkOutput.join('\n\n') : 'No Email Address Detected.'

            if(resultType.val() == 'show'){

              string.val(output)

            }else{

              V1P3R_Download(output, counter.html())

              string.val('The Result Is Ready For Download.')

            }

          }else{

            output = (output.length) ? output.join(separator) : 'No Email Address Detected.'

            if(resultType.val() == 'show'){

              string.val(output)

            }else{

              V1P3R_Download(output, counter.html())

              string.val('The Result Is Ready For Download.')

            }

          }

        }else{

          string.val('No Email Address Detected.')

        }

      })

    })

	</script>

</body>

</html>
