Advertisement
Guest User

Remove Frames

a guest
Jan 20th, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Remove Frames
  3. // @version     14.1.20.0
  4. // @license     MIT
  5. // @description Removes frames on imageboards
  6. // @include     http://iichan.hk/*
  7. // @include     http://nowere.net/*
  8. // @include     http://410chan.org/*
  9. // @include     http://sibirchan.ru/*
  10. // ==/UserScript==
  11.  
  12. (function (window, undefined) {
  13.  
  14.     var options = {
  15.         'isRight': false,
  16.         'autohide': true,
  17.         'animate': true
  18.     };
  19.  
  20.     if (window.self != window.top) {
  21.         if (window.name === 'list' || window.name === 'menu') {
  22.             if (document.readyState === 'complete' || document.readyState === 'interactive') {
  23.                 removeRealFrame();
  24.             } else {
  25.                 document.addEventListener('DOMContentLoaded', removeRealFrame.bind(null), false);
  26.             }
  27.         }
  28.     } else if (window.frames.length === 0) {
  29.         if (document.body.childNodes.length < 2) {
  30.             return;
  31.         };
  32.         if (document.readyState === 'complete' || document.readyState === 'interactive') {
  33.             addDivFrame();
  34.         } else {
  35.             document.addEventListener('DOMContentLoaded', addDivFrame.bind(null), false);
  36.         }
  37.     }
  38.  
  39.     function removeRealFrame () {
  40.         var navFrameBody = window.localStorage.getItem('FRAME_navFrame');
  41.         if (!navFrameBody) {
  42.             navFrameBody = document.body.innerHTML;
  43.             window.localStorage.setItem('FRAME_navFrame', navFrameBody);
  44.         }
  45.         var gotoURL = window.localStorage.getItem('FRAME_lastPage');
  46.         if (gotoURL) {
  47.             window.localStorage.removeItem('FRAME_lastPage');
  48.         } else {
  49.             gotoURL = window.top.main.document.location.href;
  50.         }
  51.         window.top.open(gotoURL, '_self');
  52.     }
  53.  
  54.     function addDivFrame () {
  55.         var navFrameBody = window.localStorage.getItem('FRAME_navFrame');
  56.         if (!navFrameBody) {
  57.             window.localStorage.setItem('FRAME_lastPage', document.location.href);
  58.             window.open(document.location.origin, '_self');
  59.         }
  60.         var navDiv = document.createElement('div');
  61.         navDiv.id = 'frame-nav-div';
  62.         navDiv.innerHTML = navFrameBody;
  63.         document.body.appendChild(navDiv);
  64.         addCSS();
  65.         readSettings();
  66.     }
  67.  
  68.     function addCSS () {
  69.         var style = document.createElement('style');
  70.         style.type = 'text/css';
  71.         style.textContent = '\
  72. #frame-nav-div {\n\
  73.    position: fixed;\n\
  74.    bottom: 0;\n\
  75.    top: 0;\n\
  76.    background: inherit;\n\
  77.    overflow: auto;\n\
  78.    padding: 7px;\n\
  79.    box-shadow: 0 0 5px black;\n\
  80. }\n\
  81. #frame-nav-div.left {\n\
  82.    left: 0;\n\
  83.    border-right: 1px solid;\n\
  84. }\n\
  85. #frame-nav-div.right {\n\
  86.    right: 0;\n\
  87.    border-left: 1px solid;\n\
  88. }\n\
  89. #frame-nav-div.autohide.animate {\n\
  90.    -webkit-transition-property: -webkit-transform, opacity;\n\
  91.    transition-property: transform, opacity;\n\
  92.    -webkit-transition-duration: .2s;\n\
  93.    transition-duration: .2s;\n\
  94.    -webkit-transition-timing-function: ease-in-out;\n\
  95.    transition-timing-function: ease-in-out;\n\
  96. }\n\
  97. #frame-nav-div.autohide.left {\n\
  98.    -webkit-transform: translate(-90%, 0);\n\
  99.    transform: translate(-90%, 0);\n\
  100.    opacity: 0;\n\
  101. }\n\
  102. #frame-nav-div.autohide.right {\n\
  103.    -webkit-transform: translate(90%, 0);\n\
  104.    transform: translate(90%, 0);\n\
  105.    opacity: 0;\n\
  106. }\n\
  107. #frame-nav-div.autohide:hover {\n\
  108.    -webkit-transform: translate(0, 0);\n\
  109.    transform: translate(0, 0);\n\
  110.    opacity: 1;\n\
  111. }';
  112.         document.head.appendChild(style);
  113.     }
  114.  
  115.     function readSettings () {
  116.         var navDiv = document.querySelector('#frame-nav-div');
  117.         $toggleClass(navDiv, 'right', 'left', options.isRight);
  118.         $toggleClass(navDiv, 'autohide', '', options.autohide);
  119.         $toggleClass(navDiv, 'animate', '', options.animate);
  120.     }
  121.  
  122.     function $hasClass(el, className) {
  123.         if(!className) return false;
  124.         return (' ' + el.className + ' ').indexOf(' ' + className + ' ') !== -1;
  125.     }
  126.  
  127.     function $addClass(el, className) {
  128.         if(!$hasClass(el,className)) {
  129.             if(el.className[el.className.length - 1] != ' ') {
  130.                 el.className += ' ';
  131.             }
  132.             el.className += className;
  133.         }
  134.     }
  135.  
  136.     function $removeClass(el, className) {
  137.         if($hasClass(el, className)) {
  138.             var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
  139.             el.className = el.className.replace(reg, ' ');
  140.         }
  141.     }
  142.  
  143.     function $toggleClass(el, onClass, offClass, isOn) {
  144.         if(isOn == undefined) isOn = $hasClass(el, offClass);
  145.         $addClass(el,    isOn ? onClass  : offClass);
  146.         $removeClass(el, isOn ? offClass : onClass );
  147.     }
  148. })(window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement