Lera_Rosalene / CF Hide Answered

// ==UserScript==
// @name     CF Hide Answered
// @version  0.1.5
// @grant    none
// @match    *://*.cyberforum.ru/*
// @license  MIT
// @copyright 2020, Lera_Rosalene (https://openuserjs.org/users/Lera_Rosalene)
// @supportURL https://github.com/Eva-Rosalene/cf-hide-answered
// @homepageURL https://openuserjs.org/scripts/Lera_Rosalene/CF_Hide_Answered
// @downloadURL https://openuserjs.org/install/Lera_Rosalene/CF_Hide_Answered.user.js
// @updateURL https://openuserjs.org/meta/Lera_Rosalene/CF_Hide_Answered.meta.js
// ==/UserScript==

(()=>{let i=Object.defineProperty,o=Object.prototype.hasOwnProperty,r=(a,b)=>()=>(b||(b={exports:{}},a(b.exports,b)),b.exports),s=a=>i(a,"__esModule",{value:!0}),t=(a,b)=>{s(a);if(typeof b==="object"||typeof b==="function")for(let c in b)o.call(b,c)&&!o.call(a,c)&&c!=="default"&&i(a,c,{get:()=>b[c],enumerable:!0});return a},u=a=>a&&a.__esModule?a:t(i({},"default",{value:a,enumerable:!0}),a);var n=r((a,b)=>{b.exports=`.cf_hide_answered_hidden {
  display: none;
}
`});class k{constructor(){this.tracked=[]}init(){this.tracked=[...document.querySelectorAll('[id^=td_threadtitle] [src$="tick.png"]')].map(a=>a.parentElement.parentElement.parentElement)}hide(){for(const a of this.tracked)a.classList.add("cf_hide_answered_hidden")}reveal(){for(const a of this.tracked)a.classList.remove("cf_hide_answered_hidden")}}function f(a,b,...c){const d=document.createElement(a),g=b||{};for(let[e,j]of Object.entries(g)){if(e==="ref")continue;if(j instanceof Function&&e.startsWith("on")){d.addEventListener(e.substr(2),j,!0);continue}d.setAttribute(e,j)}for(let e of c){if(typeof e==="string"){d.appendChild(document.createTextNode(e));continue}d.appendChild(e)}return g.ref&&g.ref(d),d}class l{constructor(){this.registerLink=a=>{this.link=a};this.handleClick=a=>{a.preventDefault(),this.state=!this.state,this.handleUpdate(),this.link.innerHTML=this.text()};this.state=!1}handleUpdate(){this.onUpdate&&this.onUpdate(this.state)}text(){return this.state?`[Показать темы с лучшими ответами (${this.count})]`:`[Скрыть темы с лучшими ответами (${this.count})]`}createDOMNode(){return f("td",{class:"vbmenu_control"},f("a",{ref:this.registerLink,onclick:this.handleClick,href:"#"},this.text()))}init(a,b){this.state=a,this.count=b,this.handleUpdate();const c=document.querySelector('.vbmenu_control [href$="usercp.php"]').parentElement.parentElement,d=c.lastElementChild,g=this.createDOMNode();c.insertBefore(g,d)}}const C=u(n());function q(){const a=localStorage.getItem("cf_hide_answered");if(!a)return!1;try{return!!JSON.parse(a)}catch(b){return!1}}const h=new k();h.init();const m=new l();m.onUpdate=a=>{localStorage.setItem("cf_hide_answered",JSON.stringify(a)),a?h.hide():h.reveal()};m.init(q(),h.tracked.length);document.head.appendChild(f("style",null,C.default));})();