Advertisement
x7f

Переключатель темы

x7f
May 25th, 2023
953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Переключатель темы
  3. // @version      0.1
  4. // @description  Добавляет две кнопки для переключение темы, вместо кнопки "Показать QR-код"
  5. // @author       You
  6. // @match        https://vk.com/app*
  7. // @grant        unsafeWindow
  8. // @run-at       document-idle
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.   'use strict';
  13.   const b = document.createElement("div");
  14.   b.style="all: unset; color: var(--text_link); cursor: pointer; font-size: 13px; padding-right: 4px;"
  15.  
  16.   const b1 = document.createElement("button");
  17.   b1.innerText = `Светлая`
  18.   b1.onclick=()=>{
  19.     const iframe=document.body.querySelector("#wrap3 iframe")
  20.     iframe.contentWindow.postMessage({
  21.       "type": "VKWebAppUpdateConfig",
  22.       "data": {
  23.         "appearance": "light",
  24.         "scheme": "vkcom_light"
  25.       }
  26.     },"*")
  27.   };
  28.   b1.style.all="inherit"
  29.   b1.style.paddingRight="10px"
  30.  
  31.   const b2 = document.createElement("button");
  32.   b2.innerText = `Тёмная`
  33.   b2.onclick=()=>{
  34.     const iframe=document.body.querySelector("#wrap3 iframe")
  35.     iframe.contentWindow.postMessage({
  36.       "type": "VKWebAppUpdateConfig",
  37.       "data": {
  38.         "appearance": "dark",
  39.         "scheme": "vkcom_dark"
  40.       }
  41.     },"*")
  42.   };
  43.   b2.style.all="inherit"
  44.  
  45.   b.append(b1,b2)
  46.  
  47.   const observer = new MutationObserver(()=>{
  48.     const qr = document.body.querySelector("#qr_code_btn");
  49.     if (qr) {
  50.       qr.parentNode.prepend(b)
  51.       qr.remove();
  52.     }
  53.   });
  54.   observer.observe(document.querySelector("#wrap3"), {childList: true, subtree: true});
  55. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement