Advertisement
Guest User

m_filter.user

a guest
Jul 24th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        m_filter
  3. // @namespace   m_filter
  4. // @description Фильтр анкет для сайта don-m.ru
  5. // @include     http://don-m.ru/*
  6. // @version     1.06
  7. // @grant       none
  8. // @author      Eumenes
  9. // @license     GNU GPL v3
  10. // ==/UserScript==
  11.  
  12. // Загружаем состояние из localStorage
  13. var blacklist = [];
  14. blacklist = localStorage.blacklist ? JSON.parse(localStorage.blacklist) : [];
  15. var FBlack;
  16. FBlack = localStorage.FBlack ? JSON.parse(localStorage.FBlack) : false;
  17. var FSideBar;
  18. FSideBar = localStorage.FSideBar ? JSON.parse(localStorage.FSideBar) : false;
  19. var FAddRef;
  20. FAddRef = localStorage.FAddRef ? JSON.parse(localStorage.FAddRef) : true;
  21. var RefList;
  22. RefList = localStorage.RefList ? JSON.parse(localStorage.RefList) : {};
  23.  
  24. // #region BlackList
  25. // ##############################
  26.  
  27. // функция для очистки BlackList
  28. function clearBlackList(){
  29.     blacklist = [];
  30.     localStorage.blacklist = JSON.stringify(blacklist);
  31.     window.location.reload();
  32. }
  33.  
  34. // функция для сохранения BlackList
  35. function showBlackList(){
  36.     prompt("BlackList", JSON.stringify(blacklist));
  37. }
  38.  
  39. // функция для внесения анкет в BlackList
  40. function enterBlackList(){
  41.     var new_JSON_black_list = prompt("Enter BlackList");
  42.     var new_removelist = [];
  43.     try {
  44.         new_removelist = JSON.parse(new_JSON_black_list);
  45.         for (var i = 0; i < new_removelist.length; i++) {
  46.             if (blacklist.indexOf(new_removelist[i]) == -1) {
  47.                 blacklist[blacklist.length] = new_removelist[i];
  48.             }
  49.         }
  50.         localStorage.blacklist = JSON.stringify(blacklist);
  51.         window.location.reload();
  52.     }
  53.     catch (e) {
  54.        
  55.     }
  56. }
  57.  
  58. // переключение между режимами White/Black List
  59. function inverseFBlack(){
  60.     FBlack = !FBlack;
  61.     localStorage.FBlack = JSON.stringify(FBlack);
  62.     window.location.reload();
  63. }
  64.  
  65. // функция для работы с BlackList
  66. function removethis(el){
  67.     var girlid = this.parentNode.getAttribute('data-girlid');
  68.     if (FBlack == false) {
  69.         blacklist[blacklist.length] = girlid;
  70.     } else {
  71.         var idx = blacklist.indexOf(girlid);
  72.         if (idx != -1) {
  73.             blacklist.splice(idx, 1);
  74.         }
  75.     }
  76.     localStorage.blacklist = JSON.stringify(blacklist);
  77.     this.parentNode.remove();
  78. }
  79. // ##############################
  80. // #endregion
  81.  
  82.  
  83. // #region ref
  84. // ##############################
  85.  
  86. // переключение между режимами Add/Del Ref
  87. function inverseFAddRef(){
  88.     FAddRef = !FAddRef;
  89.     localStorage.FAddRef = JSON.stringify(FAddRef);
  90.    
  91.     var btnAddRefList = document.querySelectorAll('.addref');
  92.     [].forEach.call(btnAddRefList, function(el) {
  93.         el.textContent = FAddRef ? '+' : '-';
  94.     });
  95. }
  96.  
  97. // функция для работы с RefList
  98. function AddHref(el){
  99.     var girlid = this.parentNode.parentNode.getAttribute('data-girlid');
  100.     if (FAddRef == true) {
  101.         var ref = prompt('Enter ref URL');
  102.         if ( (ref !== null) && (ref !== '') ) {
  103.             if (typeof RefList[girlid] !== "undefined") {
  104.                 if (RefList[girlid].indexOf(ref) !== -1) {
  105.                     return;
  106.                 }
  107.             } else {
  108.                 RefList[girlid] = [];
  109.             }
  110.             RefList[girlid].push(ref);
  111.             localStorage.RefList = JSON.stringify(RefList);
  112.             var i = RefList[girlid].length;
  113.             var sref = document.createElement('div');
  114.             sref.textContent = i.toString();
  115.             var a = document.createElement('a');
  116.             a.href = RefList[girlid][i-1];
  117.             a.target = "_blank"
  118.             sref.className = "sref";
  119.             sref.style.top = parseInt(61 + 20*i) + 'px';
  120.             this.parentNode.insertBefore(a, this.parentNode.children[0]);
  121.             a.insertBefore(sref, a.children[0]);
  122.         }
  123.     } else {
  124.         var refn = prompt('Enter DEL ref #');
  125.         var n = parseInt(refn);
  126.         if ( (n > 0) && (n <= RefList[girlid].length) ) {
  127.             RefList[girlid].splice(n - 1, 1);
  128.         } else {
  129.             return;
  130.         }
  131.         localStorage.RefList = JSON.stringify(RefList);
  132.         window.location.reload();
  133.     }
  134. }
  135.  
  136. // функция для очистки RefList
  137. function clearRefList(){
  138.     RefList = {};
  139.     localStorage.RefList = JSON.stringify(RefList);
  140.     window.location.reload();
  141. }
  142.  
  143. // функция для сохранения RefList
  144. function showRefList(){
  145.     prompt("RefList", JSON.stringify(RefList));
  146. }
  147.  
  148. // функция для внесения анкет в RefList
  149. function enterRefList(){
  150.     var new_JSON_RefList = prompt("Enter RefList");
  151.     var new_RefList = {};
  152.     try {
  153.         new_RefList = JSON.parse(new_JSON_RefList);
  154.         for (girlid in new_RefList) {
  155.             alert(girlid);
  156.             if (typeof RefList[girlid] == "undefined") {
  157.                 RefList[girlid] = [];
  158.             }
  159.             for (var i = 0; i < new_RefList[girlid].length; i++) {
  160.                 if (RefList[girlid].indexOf(new_RefList[girlid][i]) == -1) {
  161.                     RefList[girlid].push(new_RefList[girlid][i]);
  162.                 }
  163.             }
  164.         }
  165.         localStorage.RefList = JSON.stringify(RefList);
  166.         window.location.reload();
  167.     }
  168.     catch (e) {
  169.        
  170.     }
  171. }
  172.  
  173. // ##############################
  174. // #endregion
  175.  
  176.  
  177. // #region btn
  178. // ##############################
  179.  
  180. // скрыть/показать боковую панель
  181. function displaybar()
  182. {
  183.     var myprofile = document.querySelector('.myprofile');
  184.     if (myprofile.style.display == "block") {
  185.         myprofile.style.display = "none";
  186.     } else {
  187.         myprofile.style.display = "block";
  188.     }
  189.     FSideBar = !FSideBar;
  190.     localStorage.FSideBar = JSON.stringify(FSideBar);
  191. }
  192.  
  193. document.querySelector('body').insertAdjacentHTML('beforeend', '<style>.remthis{background-color:#008bec;color:#fff;cursor:pointer;font-size:10px;padding:1px 5px;z-index:999999999;}.remthis{margin-top:0px;}.remthis:hover{background-color:#cb4437}</style>');
  194. document.querySelector('body').insertAdjacentHTML('beforeend', '<style>.addref{background-color:#008bec;color:#fff;cursor:pointer;font-size:10px;padding:3px 5px;z-index:999999999;}.addref{margin:0px;top:61px;position:absolute;}.addref:hover{background-color:#cb4437}</style>');
  195. document.querySelector('body').insertAdjacentHTML('beforeend', '<style>.sref{background-color:#008bec;color:#fff;cursor:pointer;font-size:10px;padding:3px 5px;z-index:999999999;}.sref{margin:0px;top:61px;position:absolute;}.sref:hover{background-color:#cb4437}</style>');
  196. document.querySelector('body').insertAdjacentHTML('beforeend', '<style>.myprofile {width: 1px;height: 1px;background: #eee;display: none;position:fixed;left:0;top:115px;}mybar {display: block;padding: 4px 8px;background: #666;color: #fff;position:fixed;left:0;top:115px;text-align: center;}</style>');
  197. document.querySelector('body').insertAdjacentHTML('beforeend', '<div class="myprofile"></div><mybar>></mybar>');
  198. // Добавляем сбоку выдвижную панель с кнопками
  199. var title = document.querySelector('mybar');
  200. title.onclick = displaybar;
  201. var myprof = document.querySelector('.myprofile');
  202. var btnCSS = 'margin:5px 32px; text-align:  center; width: 160px; font-size:14px;';
  203. var btnText = ["black/white list", "clear blacklist", "save blacklist", "load blacklist", "add/del ref", "clear reflist", "save reflist", "load reflist"]; //, "on/off ref"];
  204. var btnFunc = {
  205.     Functions: [inverseFBlack, clearBlackList, showBlackList, enterBlackList, inverseFAddRef, clearRefList, showRefList, enterRefList]  
  206. }
  207. for (var i = 0; i < btnText.length; i++) {
  208.     var btn = document.createElement("BUTTON");
  209.     var t = document.createTextNode(btnText[i]);
  210.     btn.appendChild(t);
  211.     btn.style.cssText = btnCSS;
  212.     btn.onclick = btnFunc.Functions[i];
  213.     myprof.appendChild(btn);
  214. }
  215. if (FSideBar == true) {
  216.     myprof.style.display = "block";
  217. }
  218.  
  219. // ##############################
  220. // #endregion
  221.  
  222.  
  223. // #region main
  224. // ##############################
  225.  
  226. // Пробегаем по всем анкетам
  227. var titlelist = document.querySelectorAll('.list-girls-item');
  228. [].forEach.call(titlelist, function(el) {
  229.     var girlid = el.getAttribute('data-girlid');
  230.    
  231.     /*
  232.     if (typeof RefList[girlid] == "undefined") {
  233.         RefList[girlid] = [];
  234.     }
  235.     localStorage.RefList = JSON.stringify(RefList);
  236.     */
  237.    
  238.     // Если анкета находится в BlackList, то удаляем её
  239.     // Иначе добавляем в правый верхний угол кнопку 'Удалить'
  240.     // В режиме просмотра BlackList добавляем кнопку 'Исключить из BlackList'
  241.     if ( (blacklist.indexOf(girlid) !== -1) ? !FBlack : FBlack) {
  242.         el.remove();
  243.     } else {
  244.         var remthis = document.createElement('div');
  245.         if (FBlack == false) {
  246.             remthis.textContent = 'Удалить';
  247.         } else {
  248.             remthis.textContent = 'Исключить из BlackList';
  249.         }
  250.         remthis.onclick = removethis;
  251.         remthis.className = "remthis";
  252.         el.insertBefore(remthis, el.children[0]);
  253.        
  254.         var addref = document.createElement('div');
  255.         if (FAddRef == true) {
  256.             addref.textContent = '+';
  257.         } else {
  258.             addref.textContent = '-';
  259.         }
  260.         var d = document.createElement('a');
  261.         addref.className = "addref";
  262.         addref.onclick = AddHref;
  263.         el.insertBefore(d, el.children[0]);
  264.         d.insertBefore(addref, d.children[0]);
  265.        
  266.         if (typeof RefList[girlid] !== "undefined") {
  267.             for (var i = 1; i <= RefList[girlid].length; i++) {
  268.                 var sref = document.createElement('div');
  269.                 sref.textContent = i.toString();
  270.                 var a = document.createElement('a');
  271.                 a.href = RefList[girlid][i-1];
  272.                 a.target = "_blank"
  273.                 sref.className = "sref";
  274.                 sref.style.top = parseInt(61 + 20*i) + 'px';
  275.                 d.insertBefore(a, d.children[0]);
  276.                 a.insertBefore(sref, a.children[0]);
  277.             }
  278.         }
  279.     }
  280. });
  281.  
  282. // Пробегаем по всем миниатюрам анкетам на вкладке салоны
  283. var salonlist = document.querySelectorAll('.salon-girl');
  284. [].forEach.call(salonlist, function(el) {
  285.     // Если анкета находится в BlackList, то удаляем её
  286.     if (blacklist.indexOf(el.getAttribute('data-girlid')) !== -1) {
  287.         el.remove();
  288.     }
  289. });
  290.  
  291. // ##############################
  292. // #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement