Advertisement
Foxscotch

Show/Hide N/SFW

Mar 8th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Show/Hide N/SFW
  3. // @namespace    http://foxscotch.us/
  4. // @version      1.0
  5. // @description  Show or hide NSFW or SFW results on WXT index
  6. // @author       Foxscotch
  7. // @match        http://swololol.com/wxt
  8. // @grant        none
  9. // ==/UserScript==
  10. /* jshint -W097 */
  11. 'use strict';
  12.  
  13.  
  14. var mainBox = document.getElementsByClassName('box')[3];
  15.  
  16. function showOrHide(doWhat, toWhat) {
  17.     var posts = document.getElementsByClassName('post');
  18.     for (var i = 0; i < posts.length; i++) {
  19.         if (doWhat == 'hide') {
  20.             if (toWhat == 'sfw') {
  21.                 if (!posts[i].textContent.startsWith('!')) {
  22.                     posts[i].parentElement.parentElement.hidden = true;
  23.                 }
  24.             } else if (toWhat == 'nsfw') {
  25.                 if (posts[i].textContent.startsWith('!')) {
  26.                     posts[i].parentElement.parentElement.hidden = true;
  27.                 }
  28.             }
  29.         } else if (doWhat == 'show') {
  30.             if (toWhat == 'sfw') {
  31.                 if (!posts[i].textContent.startsWith('!')) {
  32.                     posts[i].parentElement.parentElement.hidden = false;
  33.                 }
  34.             } else if (toWhat == 'nsfw') {
  35.                 if (posts[i].textContent.startsWith('!')) {
  36.                     posts[i].parentElement.parentElement.hidden = false;
  37.                 }
  38.             }
  39.         }
  40.     }
  41. }
  42.  
  43. var btnContainer = document.createElement('div');
  44. btnContainer.style.textAlign = 'center';
  45.  
  46. var ssfwBtn = document.createElement('input');
  47. ssfwBtn.type = 'button';
  48. ssfwBtn.id = 'show-sfw';
  49. ssfwBtn.value = 'Show SFW';
  50. ssfwBtn.style.marginRight = '2px';
  51. ssfwBtn.addEventListener('click', showOrHide.bind(null, 'show', 'sfw'));
  52. btnContainer.appendChild(ssfwBtn);
  53.  
  54. var snsfwBtn = document.createElement('input');
  55. snsfwBtn.type = 'button';
  56. snsfwBtn.id = 'show-nsfw';
  57. snsfwBtn.value = 'Show NSFW';
  58. snsfwBtn.style.marginRight = '2px';
  59. snsfwBtn.addEventListener('click', showOrHide.bind(null, 'show', 'nsfw'));
  60. btnContainer.appendChild(snsfwBtn);
  61.  
  62. var hsfwBtn = document.createElement('input');
  63. hsfwBtn.type = 'button';
  64. hsfwBtn.id = 'hide-sfw';
  65. hsfwBtn.value = 'Hide SFW';
  66. hsfwBtn.style.marginRight = '2px';
  67. hsfwBtn.addEventListener('click', showOrHide.bind(null, 'hide', 'sfw'));
  68. btnContainer.appendChild(hsfwBtn);
  69.  
  70. var hnsfwBtn = document.createElement('input');
  71. hnsfwBtn.type = 'button';
  72. hnsfwBtn.id = 'hide-nsfw';
  73. hnsfwBtn.value = 'Hide NSFW';
  74. hnsfwBtn.addEventListener('click', showOrHide.bind(null, 'hide', 'nsfw'));
  75. btnContainer.appendChild(hnsfwBtn);
  76.  
  77. mainBox.insertBefore(btnContainer, mainBox.children[0]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement