// ==UserScript== // @name The Goatscript // @namespace http://0chan.cf/ // @version 0.2.3 // @version 0.2.2 // @description Shows hidden posts on 0-chan.ru // @icon https://raw.github.com/Juribiyan/goat-script/master/icon.png // @updateURL https://raw.github.com/Juribiyan/goat-script/master/goatscript.meta.js // @author Snivy // @match https://4.0-chan.ru/* // @include https://4.0-chan.ru/* // @grant none // ==/UserScript== 'use strict'; const getById = id => document.getElementById(id); const select = s => document.querySelector(s); const selectAll = s => document.querySelectorAll(s); const byTag = tag => document.getElementsByTagName(tag); var injector = { inject: function (alias, css) { var head = document.head || byTag("head")[0], style = document.createElement('style'); style.type = 'text/css'; style.id = 'injector:' + alias; if (style.styleSheet) { style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } head.appendChild(style); }, remove: function (alias) { var style = getById('injector:' + alias); if (style) { var head = document.head || byTag('head')[0]; if (head) { head.removeChild(getById('injector:' + alias)); } } } }; var logo = ` ` injector.inject('GS_UI', `#gs-container { position:relative; margin-left: 4px; padding-left: 8px; } #gs-head { font-size: 24px; } #gs-indicator { height: 6px; width: 6px; border-radius: 2px; position: absolute; top: 2px; left: 2px; background: #FF0039; } .gs-on #gs-indicator { background: #1ED000; }`); var gs = { init: function (on) { var hiddenReplies = selectAll('article[id^=p].deleted').length, hiddenThreads = selectAll('.index-thread.deleted').length; getById('gs-counter').innerHTML = '[' + hiddenThreads + ' / ' + hiddenReplies + ']'; if (on) this.show(); else this.hide(); }, show: function () { injector.inject('gs-unshade', ` .deleted {display: table !important; opacity: 1 !important;} .deleted > .deleted-toggle ~ :not(hr) {display:block !important;} .deleted-toggle {display:none} `); getById('gs-container').classList.add('gs-on'); this.on = true; localStorage['GS_showHiddenPosts'] = 1; }, hide: function () { injector.remove('gs-unshade'); getById('gs-container').classList.remove("gs-on") this.on = false; localStorage['GS_showHiddenPosts'] = 0; }, toggle: function () { this.on ? this.hide() : this.show(); } } document.addEventListener("DOMContentLoaded", function () { if (!localStorage.hasOwnProperty('GS_showHiddenPosts')) localStorage['GS_showHiddenPosts'] = true; var on = +(localStorage['GS_showHiddenPosts'] || 1); select('#banner span').insertAdjacentHTML( 'beforeend', ` `); gs.init(on); getById('gs-container').onclick = gs.toggle.bind(gs); });