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