-
Notifications
You must be signed in to change notification settings - Fork 0
/
kick-tools.user.js
25 lines (25 loc) · 6.41 KB
/
kick-tools.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// ==UserScript==
// @name Kick Tools
// @description Enhance Kick.com
// @license AGPL-3.0
// @author İsmail Karslı <cszn@pm.me> (https://ismail.karsli.net)
// @namespace https://github.com/ismailkarsli
// @homepageURL https://github.com/ismailkarsli/kick-tools
// @supportURL https://github.com/ismailkarsli/kick-tools/issues
// @updateURL https://raw.githubusercontent.com/ismailkarsli/kick-tools/main/kick-tools.user.js
// @version 2.2.2
// @match https://*.kick.com/*
// ==/UserScript==
"use strict";(()=>{var h={live:"live",LIVE:"LIVE",BEHIND:"BEHIND",Speed:"Speed","Kick Tools Settings":"Kick Tools Settings","Auto theater mode":"Auto theater mode","Auto speed up if behind live (1.1x)":"Auto speed up if behind live (1.1x)","Show removed chat entries":"Show removed chat entries"},g={live:"canl\u0131",LIVE:"CANLI",BEHIND:"GER\u0130DE",Speed:"H\u0131z","Kick Tools Settings":"Kick Tools Ayarlar\u0131","Auto theater mode":"Otomatik tiyatro modu","Auto speed up if behind live (1.1x)":"Canl\u0131dan gerideyse oto h\u0131zland\u0131r (1.1x)","Show removed chat entries":"Silinen mesajlar\u0131 g\xF6ster"},p=navigator.language.split("-")[0],c=l=>p==="tr"?g[l]:h[l];var a=(l,o,e)=>{let t=document.querySelectorAll(".chat-actions-item"),n=Array.from(t).find(r=>r.querySelector(".base-toggle"))?.cloneNode(!0);if(!n)throw new Error("Switch item not found");let i=n.firstElementChild,s=n.querySelector(".base-toggle");if(!i||!s)throw new Error("Switch text or input not found");return i.textContent=l,o?s.classList.add("toggled-on"):s.classList.remove("toggled-on"),s.addEventListener("click",()=>{let r=s.classList.toggle("toggled-on");e(r)}),n},u=l=>{let o=l.firstElementChild?.cloneNode(!0);if(!o)throw new Error("Settings title not found");let e=document.createElement("div");e.classList.add("chat-actions-menu-list"),e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.width="100%",e.style.height="100%",e.style.padding="10px",e.style.backgroundColor="#171c1e";let t=o.querySelector("div div");t&&(t.textContent=c("Kick Tools Settings"));let n=o.querySelector("button");return n&&n.addEventListener("click",()=>{e.remove()}),e.appendChild(o),e};var d=class{constructor(){this.lastUrl=window.location.href;this.intervals=[];this.settings={autoTheaterMode:!0,showRemovedChat:!0};let o=localStorage.getItem("KickToolsSettings");o&&(this.settings=JSON.parse(o)),this.observer=new MutationObserver(this.onObserve.bind(this)),this.observer.observe(document.body,{childList:!0,subtree:!0})}set(o,e){this.settings[o]=e,localStorage.setItem("KickToolsSettings",JSON.stringify(this.settings))}async mount(){let o=await this.waitForEl("video"),e=await this.waitForEl("video + .z-controls"),t=await this.waitForEl("div:nth-child(2)",e),n=await this.waitForEl("button:nth-child(2)",t),i=t.querySelector("#speed-select");if(this.log(i),!i){let s=document.createElement("div");s.style.display="flex",s.style.alignItems="center",s.style.marginLeft="10px",s.style.color="white",s.style.fontSize="12px",s.innerHTML=`
<span style="margin-right: 4px">${c("Speed")}:</span>
<select id="speed-select" style="color: white; background: transparent; border: none; padding: 1px;">
<option style="background-color: black" value="0.25">0.25x</option>
<option style="background-color: black" value="0.5">0.5x</option>
<option style="background-color: black" value="0.75">0.75x</option>
<option style="background-color: black" value="1" selected="selected">1x</option>
<option style="background-color: black" value="1.1">1.1x</option>
<option style="background-color: black" value="1.25">1.25x</option>
<option style="background-color: black" value="1.5">1.5x</option>
<option style="background-color: black" value="2">2x</option>
</select>
`;let r=s.querySelector("select");e.appendChild(r),r.addEventListener("change",()=>{o.playbackRate=Number.parseFloat(r.value)})}}mountSettings(o){let e=o.querySelector(".chat-actions-item");if(!e)return;let t=e.cloneNode(!0);o.appendChild(t);let n=t.childNodes?.[0]||t.querySelector("div"),i=t.querySelector(".base-icon");n&&i&&(n.textContent=c("Kick Tools Settings"),i.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512" fill="currentColor" height="1em" width="1em"><path d="M125 8h70l10 48.1c13.8 5.2 26.5 12.7 37.5 22L285.6 64 320 123.4l-33.9 30.3c1.3 7.3 1.9 14.7 1.9 22.3s-.7 15.1-1.9 22.3L320 228.6 285.6 288l-43.1-14.2c-11.1 9.3-23.7 16.8-37.5 22L195 344H125l-10-48.1c-13.8-5.2-26.5-12.7-37.5-22L34.4 288 0 228.6l33.9-30.3C32.7 191.1 32 183.6 32 176s.7-15.1 1.9-22.3L0 123.4 34.4 64 77.5 78.2c11.1-9.3 23.7-16.8 37.5-22L125 8zm83 168c0-26.5-21.5-48-48-48s-48 21.5-48 48s21.5 48 48 48s48-21.5 48-48zM632 386.4l-47.8 9.8c-4.9 13.4-12 25.8-20.9 36.7l15 44.8L517.7 512l-30.9-34c-7.4 1.3-15 2-22.7 2s-15.4-.7-22.7-2l-30.9 34-60.6-34.4 15-44.8c-8.9-10.9-16-23.3-20.9-36.7L296 386.4V317.6l47.8-9.8c4.9-13.4 12-25.8 20.9-36.7l-15-44.8L410.3 192l30.9 34c7.4-1.3 15-2 22.7-2s15.4 .7 22.7 2l30.9-34 60.6 34.4-15 44.8c8.9 10.9 16 23.3 20.9 36.7l47.8 9.8v68.7zM464 400c26.5 0 48-21.5 48-48s-21.5-48-48-48s-48 21.5-48 48s21.5 48 48 48z"></path></svg>',t.addEventListener("click",()=>{this.openSettings()}))}async openSettings(){let o=await this.waitForEl(".chat-actions-popup");if(!o)return this.log("Actions menu not found");let e=u(o);e.appendChild(a(c("Auto theater mode"),this.settings.autoTheaterMode,t=>{this.set("autoTheaterMode",t)})),e.appendChild(a(c("Show removed chat entries"),this.settings.showRemovedChat,t=>{this.set("showRemovedChat",t)})),o.appendChild(e)}onObserve(o){this.reset(),this.mount();for(let e of o){for(let t of e.addedNodes){if(!t||!(t instanceof Element))continue;let n=t.querySelector(".chat-actions-menu-list");n&&this.mountSettings(n)}if(this.settings.showRemovedChat)for(let t of e.removedNodes){if(!t||!(t instanceof HTMLElement)||!(e.target instanceof HTMLElement))continue;let n=e.target.querySelector(".chat-entry-content-deleted");if(t.dataset.chatEntry){let s=e.previousSibling;t.style.opacity="0.6",s&&e.target.insertBefore(t,s.nextSibling)}else n&&(t.style.opacity="0.6",n.replaceWith(t))}}}log(...o){console.log("%c[KickTools]","color: #53fc18;",...o)}waitForEl(o,e=document.body){return new Promise(t=>{let n=0,i=setInterval(()=>{this.log(`Waiting for ${o}`);let s=e.querySelector(o);s?(clearInterval(i),t(s)):(n++,n>100&&(clearInterval(i),this.log(`Element not found: ${o}`)))},200);this.intervals.push(i)})}reset(){for(let o of this.intervals)clearInterval(o)}};new d().mount();})();