SHARE
TWEET

Wizchan Features.slex.js

a guest Apr 23rd, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.     // ==UserScript==
  4.     // @name Wizchan Features
  5.     // @namespace http://wizchan.org
  6.     // @description [Go to bottom], floating up-down arrows, mobile post hover fix, user CSS.
  7.     // @include http://wizchan.org/*
  8.     // @include https://wizchan.org/*
  9.     // @author Anonymage
  10.     // @version 1.3.0
  11.     // ==/UserScript==
  12.      
  13.     (function () {
  14.     'use strict';
  15.      
  16.     function BannerDown() {
  17.       var bannerElem = document.querySelector('.banner');
  18.      
  19.       if (!bannerElem) {
  20.         return;
  21.       }
  22.      
  23.       var elem = document.createElement('a');
  24.       elem.className = 'unimportant banner__down';
  25.       elem.href = '#';
  26.       elem.innerHTML = '[Go to bottom]';
  27.       elem.addEventListener('click', BannerDown.handleClick);
  28.      
  29.       bannerElem.appendChild(document.createTextNode(' '));
  30.       bannerElem.appendChild(elem);
  31.     }
  32.      
  33.     BannerDown.handleClick = function (ev) {
  34.       ev.preventDefault();
  35.       window.scrollTo(0, document.documentElement.offsetHeight - window.innerHeight);
  36.     };
  37.      
  38.     function DocNav() {
  39.       var elem = document.createElement('div');
  40.       elem.className = 'doc-nav';
  41.       document.body.appendChild(elem);
  42.      
  43.       var upElem = document.createElement('button');
  44.       upElem.className = 'doc-nav__btn doc-nav__btn--up';
  45.       upElem.addEventListener('click', DocNav.handleUpClick);
  46.       upElem.innerHTML = '↑';
  47.       elem.appendChild(upElem);
  48.      
  49.       var brElem = document.createElement('br');
  50.       elem.appendChild(brElem);
  51.      
  52.       var downElem = document.createElement('button');
  53.       downElem.className = 'doc-nav__btn doc-nav__btn--down';
  54.       downElem.addEventListener('click', DocNav.handleDownClick);
  55.       downElem.innerHTML = '↓';
  56.       elem.appendChild(downElem);
  57.     }
  58.      
  59.     DocNav.handleUpClick = function () {
  60.       window.scrollTo(0, 0);
  61.     };
  62.      
  63.     DocNav.handleDownClick = function () {
  64.       window.scrollTo(0, document.documentElement.offsetHeight - window.innerHeight);
  65.     };
  66.      
  67.     function PreviewAnchor(elem) {
  68.       elem.removeAttribute('onclick');
  69.       elem.addEventListener('click', PreviewAnchor.handleClick);
  70.       elem.addEventListener('mouseenter', PreviewAnchor.handleMouseEnter);
  71.       elem.addEventListener('mouseleave', PreviewAnchor.handleMouseLeave);
  72.     };
  73.      
  74.     PreviewAnchor.activate = function () {
  75.       PreviewAnchor.doContext(document);
  76.      
  77.       var i = 0;
  78.       var interval = setInterval(function () {
  79.         if (i > 10 || window.$) {
  80.           clearInterval(interval);
  81.         }
  82.      
  83.         if (window.$) {
  84.           $(document).on('new_post', PreviewAnchor.handleNewPost);
  85.         }
  86.       }, 1000);
  87.     };
  88.      
  89.     PreviewAnchor.doContext = function (contextElem) {
  90.       var elems = contextElem.querySelectorAll('div.body a:not([rel="nofollow"])');
  91.      
  92.       for (var i = 0, len = elems.length; i < len; i++) {
  93.         new PreviewAnchor(elems[i]);
  94.       }
  95.     };
  96.      
  97.     PreviewAnchor.handleClick = function (ev) {
  98.       if (ev.target.classList.contains('preview-anchor--noclick')) {
  99.         ev.preventDefault();
  100.         ev.target.classList.remove('preview-anchor--noclick');
  101.       }
  102.     };
  103.      
  104.     PreviewAnchor.handleNewPost = function (ev, postElem) {
  105.       PreviewAnchor.doContext(postElem);
  106.     };
  107.      
  108.     PreviewAnchor.handleMouseEnter = function (ev) {
  109.       ev.target.classList.add('preview-anchor--noclick');
  110.     };
  111.      
  112.     PreviewAnchor.handleMouseLeave = function (ev) {
  113.       ev.target.classList.remove('preview-anchor--noclick');
  114.     };
  115.      
  116.     function UserCss() {
  117.       this.handleChange = this.handleChange.bind(this);
  118.       this.handleResetClick = this.handleResetClick.bind(this);
  119.       this.handleToggleClick = this.handleToggleClick.bind(this);
  120.       this.setValue = this.setValue.bind(this);
  121.      
  122.       var refs = this.refs = {
  123.         elem: null,
  124.         inputElem: null,
  125.         modalElem: null,
  126.         toggleElem: null,
  127.       };
  128.      
  129.       var value = localStorage.getItem(':userCssValue') || UserCss.FALLBACK;
  130.      
  131.       var modalElem = refs.modalElem = document.createElement('div');
  132.       modalElem.className = 'user-css user-css--hidden';
  133.       document.body.appendChild(modalElem);
  134.      
  135.       var inputElem = refs.inputElem = document.createElement('textarea');
  136.       inputElem.className = 'user-css__input';
  137.       inputElem.value = value;
  138.       inputElem.addEventListener('input', this.handleChange);
  139.       modalElem.appendChild(inputElem);
  140.      
  141.       var resetElem = document.createElement('button');
  142.       resetElem.className = 'user-css__reset';
  143.       resetElem.innerHTML = 'Reset';
  144.       resetElem.addEventListener('click', this.handleResetClick);
  145.       modalElem.appendChild(resetElem);
  146.      
  147.       var toggleElem = refs.toggleElem = document.createElement('button');
  148.       toggleElem.className = 'user-css__toggle';
  149.       toggleElem.innerHTML = 'User CSS';
  150.       toggleElem.addEventListener('click', this.handleToggleClick);
  151.       document.body.appendChild(toggleElem);
  152.      
  153.       var elem = refs.elem = document.createElement('style');
  154.       elem.innerHTML = value;
  155.       document.body.appendChild(elem);
  156.     }
  157.      
  158.     UserCss.prototype.handleChange = function (ev) {
  159.       this.setValue(ev.target.value);
  160.     };
  161.      
  162.     UserCss.prototype.handleResetClick = function () {
  163.       if (window.confirm('Reset user CSS?')) {
  164.         this.setValue(UserCss.FALLBACK);
  165.       }
  166.     };
  167.      
  168.     UserCss.prototype.handleToggleClick = function (ev) {
  169.       ev.preventDefault();
  170.      
  171.       var refs = this.refs;
  172.       var modalElem = refs.modalElem;
  173.       var toggleElem = refs.toggleElem;
  174.      
  175.       if (modalElem.classList.contains('user-css--hidden')) {
  176.         modalElem.classList.remove('user-css--hidden');
  177.         toggleElem.classList.add('user-css__toggle--fixed');
  178.         toggleElem.innerHTML = 'Close';
  179.       } else {
  180.         modalElem.classList.add('user-css--hidden');
  181.         toggleElem.classList.remove('user-css__toggle--fixed');
  182.         toggleElem.innerHTML = 'User CSS';
  183.       }
  184.     };
  185.      
  186.     UserCss.prototype.setValue = function (value) {
  187.       localStorage.setItem(':userCssValue', value);
  188.       this.refs.inputElem.value = value;
  189.       this.refs.elem.innerHTML = value;
  190.     };
  191.      
  192.     UserCss.FALLBACK = [
  193.       '.doc-nav { margin-top: -2.5em; position: fixed; right: 8px; top: 50%; }',
  194.       '.doc-nav__btn { font-size: inherit; height: 2.5em; }',
  195.       '.user-css--hidden { display: none; }',
  196.       '.user-css__input { height: 100%; left: 0; margin: 0; max-width: 100%; position: fixed; top: 0; width: 100%; }',
  197.       '.user-css__reset { bottom: 0; position: fixed; right: 0; }',
  198.       '.user-css__toggle { clear: right; float: right; margin-bottom: 10px; }',
  199.       '.user-css__toggle--fixed { position: fixed; right: 0; top: 0; }',
  200.     ].join('\n');
  201.      
  202.     if (localStorage.getItem(':bannerDown') !== 'false') {
  203.       new BannerDown();
  204.     }
  205.      
  206.     if (localStorage.getItem(':docNav') !== 'false') {
  207.       new DocNav();
  208.     }
  209.      
  210.     if (localStorage.getItem(':previewAnchor') !== 'false') {
  211.       PreviewAnchor.activate();
  212.     }
  213.      
  214.     if (localStorage.getItem(':userCss') !== 'false') {
  215.       new UserCss();
  216.     }
  217.     })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top