Advertisement
Guest User

m_filter_v1_05

a guest
Jul 5th, 2017
121
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.05
  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.  
  20. // функция для очистки BlackList
  21. function removeall(){
  22.     blacklist = [];
  23.     localStorage.blacklist = JSON.stringify(blacklist);
  24.     window.location.reload();
  25. }
  26.  
  27. // функция для сохранения BlackList
  28. function show_blacklist(){
  29.     prompt("BlackList", JSON.stringify(blacklist));
  30. }
  31.  
  32. // функция для внесения анкет в BlackList
  33. function enter_blacklist(){
  34.     var new_JSON_black_list = prompt("Enter BlackList");
  35.     var new_removelist = [];
  36.     try {
  37.         new_removelist = JSON.parse(new_JSON_black_list);
  38.         for (var i = 0; i < new_removelist.length; i++) {
  39.             if (blacklist.indexOf(new_removelist[i]) == -1) {
  40.                 blacklist[blacklist.length] = new_removelist[i];
  41.             }
  42.         }
  43.         localStorage.blacklist = JSON.stringify(blacklist);
  44.         window.location.reload();
  45.     }
  46.     catch (e) {
  47.        
  48.     }
  49. }
  50.  
  51. // переключение между режимами White/Black List
  52. function inverseFBlack(){
  53.     FBlack = !FBlack;
  54.     localStorage.FBlack = JSON.stringify(FBlack);
  55.     window.location.reload();
  56. }
  57.  
  58. // скрыть/показать боковую панель
  59. function displaybar()
  60. {
  61.     var myprofile = document.querySelector('.myprofile');
  62.     if (myprofile.style.display == "block") {
  63.         myprofile.style.display = "none";
  64.     } else {
  65.         myprofile.style.display = "block";
  66.     }
  67.     FSideBar = !FSideBar;
  68.     localStorage.FSideBar = JSON.stringify(FSideBar);
  69. }
  70.  
  71. // функция для работы с BlackList
  72. function removethis(el){
  73.     var girlid = this.parentNode.getAttribute('data-girlid');
  74.     if (FBlack == false) {
  75.         blacklist[blacklist.length] = girlid;
  76.     } else {
  77.         var idx = blacklist.indexOf(girlid);
  78.         if (idx != -1) {
  79.             blacklist.splice(idx, 1);
  80.         }
  81.     }
  82.     localStorage.blacklist = JSON.stringify(blacklist);
  83.     this.parentNode.remove();
  84. }
  85.  
  86. 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:-2px;position:absolute;display: block;}.remthis:hover{background-color:#cb4437}</style>');
  87. 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>');
  88. document.querySelector('body').insertAdjacentHTML('beforeend', '<div class="myprofile"></div><mybar>></mybar>');
  89. // Добавляем сбоку выдвижную панель с кнопками
  90. var title = document.querySelector('mybar');
  91. title.onclick = displaybar;
  92. var myprof = document.querySelector('.myprofile');
  93. var btnCSS = 'margin:5px 32px; text-align:  center; width: 160px; font-size:14px;';
  94. var btnText = ["black/white list", "clear blacklist", "save blacklist", "load blacklist"]; //, "add/del ref", "on/off ref", "clear reflist", "save reflist", "load reflist"];
  95. var btnFunc = {
  96.     Functions: [inverseFBlack, removeall, show_blacklist, enter_blacklist]  
  97. }
  98. for (var i = 0; i < btnText.length; i++) {
  99.     var btn = document.createElement("BUTTON");
  100.     var t = document.createTextNode(btnText[i]);
  101.     btn.appendChild(t);
  102.     btn.style.cssText = btnCSS;
  103.     btn.onclick = btnFunc.Functions[i];
  104.     myprof.appendChild(btn);
  105. }
  106. if (FSideBar == true) {
  107.     myprof.style.display = "block";
  108. }
  109.  
  110. // Пробегаем по всем анкетам
  111. var titlelist = document.querySelectorAll('.list-girls-item');
  112. [].forEach.call(titlelist, function(el) {
  113.     // Если анкета находится в BlackList, то удаляем её
  114.     // Иначе добавляем в правый верхний угол кнопку 'Удалить'
  115.     // В режиме просмотра BlackList добавляем кнопку 'Исключить из BlackList'
  116.     if ( (blacklist.indexOf(el.getAttribute('data-girlid')) !== -1) ? !FBlack : FBlack) {
  117.         el.remove();
  118.     } else {
  119.         var remthis = document.createElement('div');
  120.         if (FBlack == false) {
  121.             remthis.textContent = 'Удалить';
  122.         } else {
  123.             remthis.textContent = 'Исключить из BlackList';
  124.         }
  125.         remthis.onclick = removethis;
  126.         remthis.className = "remthis";
  127.         el.insertBefore(remthis, el.children[0]);
  128.     }
  129. });
  130.  
  131. // Пробегаем по всем миниатюрам анкетам на вкладке салоны
  132. var salonlist = document.querySelectorAll('.salon-girl');
  133. [].forEach.call(salonlist, function(el) {
  134.     // Если анкета находится в BlackList, то удаляем её
  135.     if (blacklist.indexOf(el.getAttribute('data-girlid')) !== -1) {
  136.         el.remove();
  137.     }
  138. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement