Guest User

Untitled

a guest
Aug 31st, 2025
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Hoyolab
  3. // @namespace    http://tampermonkey.net/
  4. // @version      2025-04-28
  5. // @description  whatever
  6. // @author       You
  7. // @match        https://act.hoyolab.com/app/community-game-records-sea/*
  8. // @icon         https://www.google.com/s2/favicons?sz=64&domain=hoyolab.com
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. const additionalCSS = `
  13.     .pc-root-layout__container {
  14.         max-width: calc(100% - var(--gpx));
  15.         .layout {
  16.               padding: 0;
  17.         }
  18.     }
  19.     .role-medium.tw-cursor-pointer {
  20.         display: inline-block;
  21.         position: relative;
  22.     }
  23.     .main-container {
  24.         display: block;
  25.         position: relative;
  26.         height: 2000px;
  27.     }
  28.     .dragging {
  29.         position: absolute;
  30.         pointer-events: none;
  31.     }
  32. `;
  33.  
  34. const addGlobalStyle = (css = '') => {
  35.     try {
  36.         const target = document.getElementsByTagName('head')[0] || document.body || document.documentElement;
  37.         const style = document.createElement('style');
  38.  
  39.         style.type = 'text/css';
  40.         style.id = 'cccccc';
  41.         style.innerHTML = css.replaceAll(';', ' !important;');
  42.         target.appendChild(style);
  43.     } catch (e) {
  44.         console.error('Error while add global styles:', e);
  45.     }
  46. }
  47.  
  48.  
  49. const addDragToElements = () => {
  50.     const elements = document.getElementsByClassName('tw-cursor-pointer');
  51.     if (elements.length > 0) {
  52.         const l = elements.length;
  53.         for (let i = 0; i < l; i++) {
  54.             elements.item(i).replaceWith(elements.item(i).cloneNode(true));
  55.             dragElement(elements.item(i));
  56.         }
  57.     }
  58.     console.log('add draggable completed!');
  59. };
  60.  
  61. const clamp = (value, min, max) => {
  62.     return Math.min(max, Math.max(min, value))
  63. }
  64.  
  65. const dragElement = (elmnt) => {
  66.     elmnt.onclick = (e) => {
  67.         e.stopImmediatePropagation();
  68.         return false;
  69.     };
  70.     elmnt.onmousedown = dragStart;
  71.  
  72.     let dragTarget;
  73.     let diffX;
  74.     let diffY;
  75.  
  76.     const px = v => `${v}px`;
  77.  
  78.     const unpx = v => parseInt(v.slice(0, -2));
  79.  
  80.     function dragStart(e) {
  81.         dragTarget = this;
  82.         dragTarget.classList.add("dragging");
  83.         let container = document.getElementsByClassName('main-container')[0];
  84.         const { left, top } = container.getBoundingClientRect()
  85.         diffX = e.pageX - unpx(dragTarget.style.left || '0px');
  86.         diffY = e.pageY - unpx(dragTarget.style.top || '0px');
  87.         window.addEventListener('mousemove', dragMove, {passive: false});
  88.         window.addEventListener('mouseup', dragStop, {passive: false});
  89.         return false;
  90.     }
  91.  
  92.     function dragMove(e) {
  93.         if (dragTarget) {
  94.             e.preventDefault();
  95.             e.stopPropagation();
  96.             const x = e.pageX - diffX;
  97.             const y = e.pageY - diffY;
  98.             dragTarget.style.left = px(x);
  99.             dragTarget.style.top = px(y);
  100.         }
  101.     }
  102.  
  103.     function dragStop(e) {
  104.         dragTarget.classList.remove("dragging");
  105.         dragTarget = undefined;
  106.         window.removeEventListener('mousemove', dragMove);
  107.         window.removeEventListener('mouseup', dragStop);
  108.     }
  109. }
  110.  
  111. const addSetDragElementBtn = () => {
  112.     const target = document.querySelector('.tw-justify-between.tw-px-3.tw-py-6.tw-flex-items-center');
  113.     if (target) {
  114.         const dragBtn = document.createElement('div');
  115.         dragBtn.classList.add('tw-cursor-pointer');
  116.         dragBtn.classList.add('tw-space-x-1');
  117.         dragBtn.classList.add('tw-flex-items-center');
  118.         dragBtn.onclick = () => addDragToElements();
  119.         const dragBtnChild = document.createElement('span');
  120.         dragBtnChild.classList.add('tw-text-sm-pc');
  121.         dragBtnChild.classList.add('tw-text-gt-l-text-white-3');
  122.         dragBtnChild.innerHTML = 'Add Drag';
  123.         dragBtn.appendChild(dragBtnChild);
  124.         target.appendChild(dragBtn);
  125.     }
  126. }
  127.  
  128. setTimeout(() => {
  129.     addGlobalStyle(additionalCSS);
  130.     addSetDragElementBtn();
  131. }, 5000);
  132.  
Advertisement
Add Comment
Please, Sign In to add comment