// ==UserScript==
// @name AliSC
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://coupon.aliexpress.com/buyer/coupon/listView.htm*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var url = window.location.toString();
var tab = document.getElementById('nav_si');
if(url.indexOf('unused')>-1 &&
tab.classList[1]==='ui-tab-active' && tab.getElementsByTagName('a')[0].innerText.indexOf('Seller Coupon')>-1
){
if(document.getElementsByClassName('ui-pagination-active')[0].innerText==='1'){
localStorage.removeItem('list_list');
}
var pack = document.getElementsByClassName('coupon-ul')[1].innerHTML;
var old = localStorage.getItem('list_list');
if(old){
localStorage.setItem('list_list',old+pack);
}else{
localStorage.setItem('list_list',pack);
}
//след.страница
var next = document.getElementsByClassName('ui-pagination-next ui-goto-page');
for(let i=0;i<next.length;i++){
if(next[i].innerText==='Next >'){ next[i].click();break; }
}//for
var next2 = document.getElementsByClassName('ui-pagination-next ui-pagination-disabled');
for(let i=0;i<next2.length;i++){
if(next2[i].innerText==='Next >'){
var list = localStorage.getItem('list_list');
var db = [];
var temp = document.createElement('div');
temp.innerHTML = list;
for(let i=0;i<temp.children.length;i++){
var details = temp.getElementsByClassName('clearfix')[i].getElementsByClassName('use-coupons-details')[0].getElementsByClassName('coupon-ul')[0];
var valid_period = details.getElementsByClassName('valid-period-coupon-seller')[0].innerText;
//'11 нояб., 00:00 PT - 14 нояб., 23:59 PT'
if(valid_period.indexOf('11 нояб')==0){
db.push( '<li class="clearfix">'+temp.getElementsByClassName('clearfix')[i].innerHTML+'</li>'
);
}else{
//
}
}//for children enum
//cut and insert
var div = document.createElement('div');
div.innerHTML ='<div id="upz" style="position:fixed;cursor:pointer;z-index:999999;border:0px solid red;padding-left:1.5%;padding-right:1.5%;padding-bottom:0.2%;padding-top:0.3%;text-align:center;font-size:2em;right:2%;bottom:2%;background:rgba(204,204,204,0.8);backdrop:blur 3px;color:rgba(174,174,174,0.96);">↾</div>'
+'<div id="downz" style="position:fixed;cursor:pointer;z-index:999999;border:0px solid red;padding-left:1.5%;padding-right:1.5%;padding-bottom:0.2%;padding-top:0.3%;text-align:center;font-size:2em;right:6.3%;bottom:2%;background:rgba(204,204,204,0.8);backdrop:blur 3px;color:rgba(164,164,164,0.98);">⇃</div>'
;
document.body.appendChild(div);
document.getElementById('upz').addEventListener('click', function(){
window.scroll({top: 0, behavior: "smooth"});
});
document.getElementById('downz').addEventListener('click', function(){
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
});
db ='<div id="main_id" style="display:flex;flex-direction:column;">Количество:'+temp.children.length+'<br>'+db+'</div>';
document.getElementsByClassName('coupon-ul')[1].innerHTML='';
document.getElementsByClassName('coupon-ul')[1].innerHTML=db;
var div2=document.createElement('div');
div2.innerHTML=
'<div id="val_limit_div" style="position:fixed;bottom:19%;right:2%;z-index:999999;width:8%;height:5%;background:argb(240,240,240,1);"><input id="limit_id" step="0.01" style="width:100%;height:100%;font-size:2em;" type="number" value="5.01" ></div>'+
'<div id="val_off_div" style="position:fixed;bottom:13%;right:4%;z-index:999999;width:6%;height:5%;background:argb(240,240,240,1);"><input id="val_id" step="0.01" style="width:100%;height:100%;font-size:2em;" type="number" value="5" ></div>'+
'<div id="sbm_id" style="position:fixed;bottom:7%;cursor:pointer;right:6.5%;border:1px solid red;z-index:999999;padding-top:1%;padding-bottom:1%;padding-left:1%;padding-right:1%;background:argb(240,240,240,1);"> OK</div>'+
'<div id="restore_id" style="position:fixed;bottom:7%;cursor:pointer;right:2%;border:1px solid red;z-index:999999;padding-top:1%;padding-bottom:1%;padding-left:1%;padding-right:1%;background:argb(240,240,240,1);"> Вст.</div>';
document.body.appendChild(div2);
document.getElementById('sbm_id').addEventListener('click', function(){
var all = document.getElementById('main_id');
var val = document.getElementById('val_id').value;
var sel_limit = document.getElementById('limit_id').value;
for(let i=0;i<all.children.length-1;i++){
var min = all.getElementsByClassName('clearfix')[i]
.getElementsByClassName('use-coupons-info-lang-price')[0].innerText;
var limit = all.getElementsByClassName('clearfix')[i]
.getElementsByClassName('use-coupons-info-lang-limit')[0].innerText;
min = parseFloat(min.replace(/[^0-9.]/g, ""));
limit = parseFloat(limit.replace(/[^0-9.]/g, ""));
console.log(limit);
console.log(sel_limit);
if(min<val
|| limit>sel_limit
){
all.getElementsByClassName('clearfix')[i].style.display='none';
}
}
});//eventlistener submit click
document.getElementById('restore_id').addEventListener('click', function(){
for(let i=0;i<document.getElementById('main_id').children.length-1;i++){
document.getElementById('main_id').getElementsByClassName('clearfix')[i].style.display='block';
}
});
}//if last
}//for
}//if url
})();